创建项目目录nginx-stateless

创建deployment

创建deployment-nginx.yaml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

展示deployment信息

# kubectl describe deployment nginx-deployment

Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Sat, 16 Jun 2018 11:29:57 +0800
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision=1
                        kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"apps/v1beta2","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},"spec":{"replicas":2,"se...
Selector:               app=nginx
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.7.9
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-6d8f46cfb7 (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  1m    deployment-controller  Scaled up replica set nginx-deployment-6d8f46cfb7 to 2

列出deployment创建的pods

# kubectl get pods -l app=nginx

NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-6d8f46cfb7-6kz6t   1/1       Running   0          3m
nginx-deployment-6d8f46cfb7-fvsps   1/1       Running   0          3m

显示某个pod的信息

# kubectl describe pod nginx-deployment-6d8f46cfb7-6kz6t

Name:           nginx-deployment-6d8f46cfb7-6kz6t
Namespace:      default
Node:           izuf6a3uv2157dtxw3i75gz/172.19.192.132
Start Time:     Sat, 16 Jun 2018 11:29:57 +0800
Labels:         app=nginx
                pod-template-hash=2849027963
Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-deployment-6d8f46cfb7","uid":"8b30de4f-7115-11e8-9ae5-0016...
Status:         Running
IP:             172.17.0.4
Controlled By:  ReplicaSet/nginx-deployment-6d8f46cfb7
Containers:
  nginx:
    Container ID:   docker://308bc86bb6b96a9af096f7eedcd1a2d3db5aab65a9f9410149cf1ff5a6b6c9fe
    Image:          nginx:1.7.9
    Image ID:       docker-pullable://[email protected]:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 16 Jun 2018 11:30:20 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mkmng (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          True 
  PodScheduled   True 
Volumes:
  default-token-mkmng:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mkmng
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     <none>
Events:
  Type    Reason                 Age   From                              Message
  ----    ------                 ----  ----                              -------
  Normal  Scheduled              4m    default-scheduler                 Successfully assigned nginx-deployment-6d8f46cfb7-6kz6t to izuf6a3uv2157dtxw3i75gz
  Normal  SuccessfulMountVolume  4m    kubelet, izuf6a3uv2157dtxw3i75gz  MountVolume.SetUp succeeded for volume "default-token-mkmng"
  Normal  Pulling                4m    kubelet, izuf6a3uv2157dtxw3i75gz  pulling image "nginx:1.7.9"
  Normal  Pulled                 4m    kubelet, izuf6a3uv2157dtxw3i75gz  Successfully pulled image "nginx:1.7.9"
  Normal  Created                4m    kubelet, izuf6a3uv2157dtxw3i75gz  Created container
  Normal  Started                4m    kubelet, izuf6a3uv2157dtxw3i75gz  Started container

更新deployment

修改deployment-nginx.yaml ,将nginx升级到1.8,应用deployment

kubectl apply -f deployment-nginx.yaml

列出活动的pod

# kubectl get pods -l app=nginx

NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-784794c74c-gt8sr   1/1       Running   0          1m
nginx-deployment-784794c74c-v4sz4   1/1       Running   0          1m

扩展replica

deployment-nginx.yaml 中的replicas数目由2,重新apply

查看pods数目

# kubectl get pods -l app=nginx

NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-784794c74c-gt8sr   1/1       Running   0          4m
nginx-deployment-784794c74c-mhp64   1/1       Running   0          15s
nginx-deployment-784794c74c-pm7p8   1/1       Running   0          15s
nginx-deployment-784794c74c-v4sz4   1/1       Running   0          4m

删除deployment

删除deployment

kubectl delete deployment nginx-deployment

results matching ""

    No results matching ""