k8s deployment

  Kubernetes Deployment instructs Kubernetes how to create and update instances of your application. Once you've created a Deployment, the Kubernetes master schedules mentioned application instances onto individual Nodes in the cluster. Kubernetes Deployment Controller continuously monitors those instances, if they are deleted,  a new one will be auto created. 

 

 

 1 apiVersion: extensions/v1beta1
 2 kind: Deployment
 3 metadata:
 4   name: gitea-deployment
 5 spec:
 6   replicas: 1
 7   selector:
 8     matchLabels:
 9       app: gitea
10   template:
11     metadata:
12       labels:
13         app: gitea
14     spec:
15       containers:
16       - name: gitea-container
17         image: gitea/gitea:1.4

 

There is one other new concept introduced here: labels and selectors. Labels are simply user-defined key-value stores associated with Kubernetes resources. Selectors are used retrieve the resources that match a given label query. In this example, line 13 assigns the label “app=gitea” to all pods created by this deployment. Now, if the deployment ever needs to retrieve the list of all pods that it created (to make sure they are all healthy, for example) it will use the selector defined on lines 8–9. In this way, the deployment can always keep track of which pods it manages by searching for which ones have been assigned the “app=gitea” label.

For the most part, labels are user-defined. In the example above, “app” doesn’t mean anything special to Kubernetes, it is just a way that we may find useful to organize our system. Having said that, there are certain labels that are automatically applied by Kubernetes, containing information about the system.

Via a label selector, the client/user can identify a set of objects. The label selector is the core grouping primitive in Kubernetes.

The API currently supports two types of selectors: equality-based and set-based. A label selector can be made of multiple requirements which are comma-separated. In the case of multiple requirements, all must be satisfied so the comma separator acts as a logical AND (&&) operator.



 

posted @ 2019-07-21 04:38  anyu686  阅读(188)  评论(0编辑  收藏  举报