kubectl 基本操作

#!/bin/bash

#####kubectl 管理工具

1.创建
kubectl run nginx --replicas=3 --labels="app=example" --image=nginx:1.10 --port=80

2.查看
kubectl get pods -o wide
kubectl get pods --show-labels
kubectl get pods -l app=example
kubeclt get deploy

3.发布
[root@master ~]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service
service/nginx-service exposed
[root@master ~]# kubectl describe service nginx-service


4.故障排查
kubectl describe podsxxxx ###事件
kubectl describe svc/nginx-service
kubectl describe deploy/nginx
kubectl describe po/nginx-c67fd84ff-qrgb7
kubectl get pods -o wide
kubectl logs po/nginx-c67fd84ff-qrgb7

###进入终端
kubectl exec -it nginx-c67fd84ff-qrgb7 bash

5.更新
kubectl set image deployment/nginx nginx=nginx:1.11
kubectl edit pods/nginx-c67fd84ff-qrgb7 ###也可以更新

6.回滚
kubectl rollout history deploy/nginx
kubectl rollout status deploy/nginx

kubectl rollout undo deployment/nginx
deployment.extensions/nginx

##scale

kubectl scale deploy/nginx --replicas=5
deployment.extensions/nginx scaled
kubectl scale deploy/nginx --replicas=2

7.删除
kubectl delete deploy/nginx
deployment.extensions "nginx" deleted
[root@master ~]# kubectl delete svc/nginx
Error from server (NotFound): services "nginx" not found
[root@master ~]# kubectl delete svc/nginx-service
service "nginx-service" deleted
[root@master ~]#

 

你可能感兴趣的:(Kubernetes)