创建一个应用
[[email protected] ~]# kubectl run nginx --replicas=3 --labels="app=nginx-example" --image=nginx:1.10 --port=80 replicas:副本数为3个,默认1个 labels :标识识别属性, image:默认从hub上下载
查看应用
[[email protected] ~]# 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 正在创建中
查看pod详细信息
[[email protected] ~]# kubectl describe pod/nginx-f95d765f9-bxgv9
查看pod标签
[[email protected] ~]# 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分配到哪个节点
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# kubectl get deploy NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE busybox 1 1 1 1 5m nginx 3 3 3 3 17m
发布应用
发布:
[[email protected] ~]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
busybox 1 1 1 1 5m
nginx 3 3 3 3 17m
[[email protected] ~]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service
通过svc查看发布的应用
[[email protected] ~]# 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 [[email protected] ~]# 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副本扩容
// 把当前的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
原文地址:https://www.cnblogs.com/zhangzihong/p/9449119.html