k8s命令使用

创建一个deployment

[root@k8s-master ~]# cat nginx.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-test
  template:
    metadata:
      labels:
        app: nginx-test
    spec:
      containers:
      - name: nginx
        image: nginx:1.16.1
        ports:
        - containerPort: 80
[root@k8s-master ~]#  kubectl apply -f nginx.yaml
[root@k8s-master ~]# kubectl get deployment
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           3h41m
[root@k8s-master ~]# kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running   0          3h41m
nginx-deployment-5cdd4f799d-bxszf   1/1     Running   0          3h41m
nginx-deployment-5cdd4f799d-drktr   1/1     Running   0          3h41m
[root@k8s-master ~]# kubectl get pods --show-labels
NAME                                READY   STATUS    RESTARTS   AGE     LABELS
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running   0          3h43m   app=nginx-test,pod-template-hash=5cdd4f799d
nginx-deployment-5cdd4f799d-bxszf   1/1     Running   0          3h43m   app=nginx-test,pod-template-hash=5cdd4f799d
nginx-deployment-5cdd4f799d-drktr   1/1     Running   0          3h43m   app=nginx-test,pod-template-hash=5cdd4f799d
[root@k8s-master ~]# kubectl get pods --show-labels -o wide
NAME                                READY   STATUS    RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES   LABELS
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running   0          3h45m   10.244.1.18   k8s-node1   <none>           <none>            app=nginx-test,pod-template-hash=5cdd4f799d
nginx-deployment-5cdd4f799d-bxszf   1/1     Running   0          3h45m   10.244.1.17   k8s-node1   <none>           <none>            app=nginx-test,pod-template-hash=5cdd4f799d
nginx-deployment-5cdd4f799d-drktr   1/1     Running   0          3h45m   10.244.2.18   k8s-node2   <none>           <none>            app=nginx-test,pod-template-hash=5cdd4f799d

或者:kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service

创建service

[root@k8s-master ~]# cat service.yml 
apiVersion: v1
kind: Service
metadata:
  name: nginx-service 
  labels:
    app: nginx-test
spec:
  ports:
  - port: 88
    targetPort: 80
  selector:
    app: nginx-test
[root@k8s-master ~]# kubectl apply -f service.yml 
service/nginx-service created
[root@k8s-master ~]# kubectl get svc 
NAME            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes      ClusterIP   10.0.0.1      <none>        443/TCP   5d5h
nginx-service   ClusterIP   10.1.65.177   <none>        88/TCP    75s

访问服务

[root@k8s-master ~]# curl 10.1.65.177:88
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

暴露到外部访问
修改Service为NodePort类型
type: ClusterIP 将 ClusterIP 修改为NodePort

[root@k8s-master ~]# kubectl edit svc nginx-service
找到下面的行
spec:
  clusterIP: 10.1.65.177
  ports:
  - port: 88
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-test
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
修改为
spec:
  clusterIP: 10.1.65.177
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30002
    port: 88
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-test
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}
[root@k8s-master ~]# kubectl get svc 
NAME            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.0.0.1      <none>        443/TCP        5d5h
nginx-service   NodePort    10.1.65.177   <none>        88:30002/TCP   13m
[root@k8s-master ~]# kubectl describe svc nginx-service
Name:                     nginx-service
Namespace:                default
Labels:                   app=nginx-test
Annotations:              Selector:  app=nginx-test
Type:                     NodePort
IP:                       10.1.65.177
Port:                     <unset>  88/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30002/TCP
Endpoints:                10.244.1.21:80,10.244.2.22:80,10.244.2.23:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

主机ip+端口访问


image.png

扩容nginx应用

[root@k8s-master ~]# kubectl scale deployment nginx-deployment --replicas 5
deployment.apps/nginx-deployment scaled
[root@k8s-master ~]# kubectl get deployment
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   5/5     5            5           4h12m
[root@k8s-master ~]# kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running   0          4h13m   10.244.1.18   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-2qtps   1/1     Running   0          14s     10.244.2.19   k8s-node2   <none>           <none>
nginx-deployment-5cdd4f799d-bxszf   1/1     Running   0          4h13m   10.244.1.17   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-d8k2p   1/1     Running   0          14s     10.244.1.19   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-drktr   1/1     Running   0          4h13m   10.244.2.18   k8s-node2   <none>           <none>
[root@k8s-master ~]# kubectl describe pods nginx-deployment-5cdd4f799d-2qtps
Name:         nginx-deployment-5cdd4f799d-2qtps
Namespace:    default
Priority:     0
Node:         k8s-node2/192.168.2.38
Start Time:   Tue, 20 Oct 2020 15:19:44 +0800
Labels:       app=nginx-test
              pod-template-hash=5cdd4f799d
Annotations:  <none>
Status:       Running
IP:           10.244.2.19
IPs:
  IP:           10.244.2.19
Controlled By:  ReplicaSet/nginx-deployment-5cdd4f799d
Containers:
  nginx:
    Container ID:   docker://761717fb01f0bb7f0e24d5eb1ae64d4a3f666119332082ef92611e81863b5881
    Image:          nginx:1.16.1
    Image ID:       docker-pullable://nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 20 Oct 2020 15:19:45 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-cfllf (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-cfllf:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-cfllf
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From                Message
  ----    ------     ----  ----                -------
  Normal  Scheduled  104s  default-scheduler   Successfully assigned default/nginx-deployment-5cdd4f799d-2qtps to k8s-node2
  Normal  Pulled     103s  kubelet, k8s-node2  Container image "nginx:1.16.1" already present on machine
  Normal  Created    103s  kubelet, k8s-node2  Created container nginx
  Normal  Started    103s  kubelet, k8s-node2  Started container nginx
[root@k8s-master ~]# kubectl describe deployment nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Tue, 20 Oct 2020 11:06:56 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx-test
Replicas:               5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-test
  Containers:
   nginx:
    Image:        nginx:1.16.1
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-5cdd4f799d (5/5 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  3m40s  deployment-controller  Scaled up replica set nginx-deployment-5cdd4f799d to 5

缩容nginx应用

[root@k8s-master ~]# kubectl scale deployment nginx-deployment --replicas 3
deployment.apps/nginx-deployment scaled
[root@k8s-master ~]# kubectl get pods -o wide
NAME                                READY   STATUS        RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running       0          4h18m   10.244.1.18   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-2qtps   1/1     Running       0          5m26s   10.244.2.19   k8s-node2   <none>           <none>
nginx-deployment-5cdd4f799d-bxszf   0/1     Terminating   0          4h18m   10.244.1.17   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-d8k2p   0/1     Terminating   0          5m26s   10.244.1.19   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-drktr   1/1     Running       0          4h18m   10.244.2.18   k8s-node2   <none>           <none>
[root@k8s-master ~]# kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running   0          4h19m   10.244.1.18   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-2qtps   1/1     Running   0          6m36s   10.244.2.19   k8s-node2   <none>           <none>
nginx-deployment-5cdd4f799d-drktr   1/1     Running   0          4h19m   10.244.2.18   k8s-node2   <none>           <none>
[root@k8s-master ~]# kubectl describe deployment nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Tue, 20 Oct 2020 11:06:56 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx-test
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-test
  Containers:
   nginx:
    Image:        nginx:1.16.1
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-5cdd4f799d (3/3 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  5m57s  deployment-controller  Scaled up replica set nginx-deployment-5cdd4f799d to 5
  Normal  ScalingReplicaSet  36s    deployment-controller  Scaled down replica set nginx-deployment-5cdd4f799d to 3

更新镜像

kubectl set image deployment/nginx-deployment nginx=nginx:1.18.0
or
kubectl edit deployment/nginx-deployment

[root@k8s-master ~]# kubectl edit deployment nginx-deployment
 找到
   spec:
      containers:
      - image: nginx:1.16.1
修改为
    spec:
      containers:
      - image: nginx:1.18.0

[root@k8s-master ~]# kubectl edit deployment nginx-deployment
deployment.apps/nginx-deployment edited

[root@k8s-master ~]# kubectl rollout status deployment nginx-deployment   #查看滚动更新过程
deployment "nginx-deployment" successfully rolled out
[root@k8s-master ~]# kubectl get pods -o wide    #更新中
NAME                                READY   STATUS              RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-5cdd4f799d-2jz9c   1/1     Running             0          4h23m   10.244.1.18   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-2qtps   1/1     Running             0          11m     10.244.2.19   k8s-node2   <none>           <none>
nginx-deployment-5cdd4f799d-drktr   1/1     Running             0          4h23m   10.244.2.18   k8s-node2   <none>           <none>
nginx-deployment-ffcfbb9f5-tb8r7    0/1     ContainerCreating   0          3s      <none>        k8s-node1   <none>           <none>
[root@k8s-master ~]# kubectl get pods -o wide      #更新完成
NAME                               READY   STATUS    RESTARTS   AGE   IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-ffcfbb9f5-bbc86   1/1     Running   0          17s   10.244.2.20   k8s-node2   <none>           <none>
nginx-deployment-ffcfbb9f5-r859g   1/1     Running   0          12s   10.244.2.21   k8s-node2   <none>           <none>
nginx-deployment-ffcfbb9f5-tb8r7   1/1     Running   0          29s   10.244.1.20   k8s-node1   <none>           <none>
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Tue, 20 Oct 2020 11:06:56 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 2
Selector:               app=nginx-test
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-test
  Containers:
   nginx:
    Image:        nginx:1.18.0
    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-ffcfbb9f5 (3/3 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  16m    deployment-controller  Scaled up replica set nginx-deployment-5cdd4f799d to 5
  Normal  ScalingReplicaSet  10m    deployment-controller  Scaled down replica set nginx-deployment-5cdd4f799d to 3
  Normal  ScalingReplicaSet  5m6s   deployment-controller  Scaled up replica set nginx-deployment-ffcfbb9f5 to 1
  Normal  ScalingReplicaSet  4m54s  deployment-controller  Scaled down replica set nginx-deployment-5cdd4f799d to 2
  Normal  ScalingReplicaSet  4m54s  deployment-controller  Scaled up replica set nginx-deployment-ffcfbb9f5 to 2
  Normal  ScalingReplicaSet  4m49s  deployment-controller  Scaled down replica set nginx-deployment-5cdd4f799d to 1
  Normal  ScalingReplicaSet  4m49s  deployment-controller  Scaled up replica set nginx-deployment-ffcfbb9f5 to 3
  Normal  ScalingReplicaSet  4m48s  deployment-controller  Scaled down replica set nginx-deployment-5cdd4f799d to 0
[root@k8s-master ~]# kubectl describe pods nginx-deployment-ffcfbb9f5-bbc86  #更新完成后,查看镜像版本
Name:         nginx-deployment-ffcfbb9f5-bbc86
Namespace:    default
Priority:     0
Node:         k8s-node2/192.168.2.38
Start Time:   Tue, 20 Oct 2020 15:31:04 +0800
Labels:       app=nginx-test
              pod-template-hash=ffcfbb9f5
Annotations:  <none>
Status:       Running
IP:           10.244.2.20
IPs:
  IP:           10.244.2.20
Controlled By:  ReplicaSet/nginx-deployment-ffcfbb9f5
Containers:
  nginx:
    Container ID:   docker://79a6cc30a58a7418ad1949ee044671aff2959861d28b11a740690ca919d263b7
    Image:          nginx:1.18.0
    Image ID:       docker-pullable://nginx@sha256:6e4fc428f9f25f1914e43dc2e75ff3be574141734509111282a3a050a420d94c
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 20 Oct 2020 15:31:09 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-cfllf (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-cfllf:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-cfllf
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age    From                Message
  ----    ------     ----   ----                -------
  Normal  Scheduled  5m45s  default-scheduler   Successfully assigned default/nginx-deployment-ffcfbb9f5-bbc86 to k8s-node2
  Normal  Pulling    5m45s  kubelet, k8s-node2  Pulling image "nginx:1.18.0"
  Normal  Pulled     5m40s  kubelet, k8s-node2  Successfully pulled image "nginx:1.18.0"
  Normal  Created    5m40s  kubelet, k8s-node2  Created container nginx
  Normal  Started    5m40s  kubelet, k8s-node2  Started container nginx

回滚

[root@k8s-master ~]# kubectl rollout undo deployment/nginx-deployment
deployment.apps/nginx-deployment rolled back
[root@k8s-master ~]#  kubectl rollout status deployment nginx-deployment
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
deployment "nginx-deployment" successfully rolled out
[root@k8s-master ~]# kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP            NODE        NOMINATED NODE   READINESS GATES
nginx-deployment-5cdd4f799d-bfnrh   1/1     Running   0          24s   10.244.2.22   k8s-node2   <none>           <none>
nginx-deployment-5cdd4f799d-fj2m9   1/1     Running   0          25s   10.244.1.21   k8s-node1   <none>           <none>
nginx-deployment-5cdd4f799d-p49rq   1/1     Running   0          22s   10.244.2.23   k8s-node2   <none>           <none>
[root@k8s-master ~]# kubectl describe pods nginx-deployment-5cdd4f799d-bfnrh
Name:         nginx-deployment-5cdd4f799d-bfnrh
Namespace:    default
Priority:     0
Node:         k8s-node2/192.168.2.38
Start Time:   Tue, 20 Oct 2020 15:47:55 +0800
Labels:       app=nginx-test
              pod-template-hash=5cdd4f799d
Annotations:  <none>
Status:       Running
IP:           10.244.2.22
IPs:
  IP:           10.244.2.22
Controlled By:  ReplicaSet/nginx-deployment-5cdd4f799d
Containers:
  nginx:
    Container ID:   docker://a0f2d26b02dfd64d3ecb2d0880089a5affd655c3b87152d5c1b505a8c550314f
    Image:          nginx:1.16.1
    Image ID:       docker-pullable://nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 20 Oct 2020 15:47:56 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-cfllf (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-cfllf:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-cfllf
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age        From                Message
  ----    ------     ----       ----                -------
  Normal  Scheduled  <unknown>  default-scheduler   Successfully assigned default/nginx-deployment-5cdd4f799d-bfnrh to k8s-node2
  Normal  Pulled     113s       kubelet, k8s-node2  Container image "nginx:1.16.1" already present on machine
  Normal  Created    113s       kubelet, k8s-node2  Created container nginx
  Normal  Started    113s       kubelet, k8s-node2  Started container nginx

回滚到指定版本

[root@k8s-master ~]# kubectl rollout history deployment/nginx-deployment  #查看历史版本
deployment.apps/nginx-deployment 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
[root@k8s-master ~]# kubectl rollout undo deployment/nginx-deployment --to-revision=2   ## 可以使用 --revision参数指定
[root@k8s-master ~]# kubectl rollout pause deployment/nginx-deployment    ## 暂停 deployment 的更新

record参数

--record参数可以记录命令,我们可以很方便的查看每次 revision 的变化

[root@k8s-master ~]# kubectl apply -f nginx.yaml --record
deployment.apps/nginx-deployment created
[root@k8s-master ~]# kubectl rollout history deployment/nginx-deployment
deployment.apps/nginx-deployment 
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=nginx.yaml --record=true

[root@k8s-master ~]# kubectl set image deployment/nginx-deployment nginx=nginx:1.12.0 --record
deployment.apps/nginx-deployment image updated
[root@k8s-master ~]# kubectl rollout history deployment/nginx-deployment
deployment.apps/nginx-deployment 
REVISION  CHANGE-CAUSE
3         <none>
4         <none>
5         kubectl set image deployment/nginx-deployment nginx=nginx:1.12.0 --record=true

删除应用

[root@k8s-master ~]# kubectl delete deployment/nginx-deployment
deployment.apps "nginx-deployment" deleted
[root@k8s-master ~]# kubectl delete svc/nginx-service
service "nginx-service" deleted

故障排查

kubectl describe TYPE NAME_PREFIX   #查看描述
kubectl logs pod-name   #查看pod的日志
kubectl exec -it pod-name bash   #进入pod内部
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,163评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,301评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,089评论 0 352
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,093评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,110评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,079评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,005评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,840评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,278评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,497评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,667评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,394评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,980评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,628评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,796评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,649评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,548评论 2 352