Kubernetes容器集羣kubectl管理工具命令(八)

建立一個應用

[root@master ~]# kubectl run nginx --replicas=3 --labels="app=nginx-example" --image=nginx:1.10 --port=80

replicas:副本數爲3個,默認1個
labels :標識識別屬性,
image:默認從hub上下載

查看應用

[root@master ~]# kubectl get all NAME READY STATUS RESTARTS AGE pod/nginx-f95d765f9-bxgv9 0/1 ContainerCreating 0 2m pod/nginx-f95d765f9-pdq4x 0/1 ContainerCreating 0 2m pod/nginx-f95d765f9-znxw2 0/1 ContainerCreating 0 2m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 21h NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deployment.extensions/nginx 3 3 3 0 2m NAME DESIRED CURRENT READY AGE replicaset.extensions/nginx-f95d765f9 3 3 0 2m NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deployment.apps/nginx 3 3 3 0 2m NAME DESIRED CURRENT READY AGE replicaset.apps/nginx-f95d765f9 3 3 0 2m 正在建立中nginx

查看pod詳細信息bash

[root@master ~]# kubectl describe pod/nginx-f95d765f9-bxgv9

查看pod標籤app

[root@master ~]# kubectl get pods --show-labels
NAME                    READY     STATUS    RESTARTS   AGE       LABELS
nginx-f95d765f9-bxgv9   1/1       Running   0          9m        app=nginx-example,pod-template-hash=951832195
nginx-f95d765f9-pdq4x   1/1       Running   0          9m        app=nginx-example,pod-template-hash=951832195
nginx-f95d765f9-znxw2   1/1       Running   0          9m        app=nginx-example,pod-template-hash=951832195

查看Pod分配到哪一個節點ide

[root@master ~]# kubectl get pods -o wide
NAME                       READY     STATUS    RESTARTS   AGE       IP            NODE
busybox-5d4f595646-tqfp2   1/1       Running   2          2m        172.17.45.4   192.168.1.102
nginx-f95d765f9-bxgv9      1/1       Running   0          14m       172.17.47.2   192.168.1.103
nginx-f95d765f9-pdq4x      1/1       Running   0          14m       172.17.45.2   192.168.1.102
nginx-f95d765f9-znxw2      1/1       Running   0          14m       172.17.47.3   192.168.1.103
[root@master ~]# kubectl get deploy -o wide
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES       SELECTOR
busybox   1         1         1            0           3m        busybox      busybox      run=busybox
nginx     3         3         3            3           15m       nginx        nginx:1.10   app=nginx-example
[root@master ~]# kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
busybox   1         1         1            1           5m
nginx     3         3         3            3           17m

發佈應用

發佈:spa

[root@master ~]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
busybox 1 1 1 1 5m
nginx 3 3 3 3 17m日誌


[root@master ~]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service

經過svc查看發佈的應用code

[root@master ~]# kubectl get svc
NAME            TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.10.10.1   <none>        443/TCP        23h
nginx-service   NodePort    10.10.10.9   <none>        88:36046/TCP   1m

故障排查

// 查看Events事件
kubectl describe pod名稱  

// 經過deploy查看事件
kubectl describe deploy/nginx 

//查看發佈具體信息
kubectl describe svc name名稱

//查看日誌
kubectl logs  pod名稱

//進入容器排查
kubectl exec -it pod名稱 bash

更新鏡像升級

//把當前nginx:1.10版本更新至1.11
[root@master ~]# kubectl set image deployments/nginx nginx=nginx:1.11

or

kubectl edit deploy/nginx  編輯裏面的鏡像版本號保存退出

查看發佈狀態

// 佈署資源的狀態
kubectl rollout status deploy/nginx

// 發佈的歷史版本
kubectl rollout history deploy/nginx

回滾

//回退到上一個退版
kubectl rollout undo deploy/nginx   默認回滾到上一個版本

//查看狀態
kubectl  rollout status deploy/nginx

//回到指定版本
kubectl rollout undo deploy/nginx --to-revision=4

pod副本擴容blog

// 把當前的pod擴容到5個
kubectl scale deploy/nginx --replicas=5

縮減也是上述命令

刪除

// 刪除pod
kubectl delete deployment.extensions/nginx

//刪除service
kubectl delete service/nginx-service

//查看
 kubectl get all
kubectl get deploy
相關文章
相關標籤/搜索