目录
工作负载控制器
Deployment
deployment生命周期演示
1、部署镜像
2、应用升级
3、滚动升级的实现(ReplicaSet)
4、deployment应用实例扩容与缩容
5、deployment应用回滚
6、项目下线
kubectl apply -f xxx.yaml
kubectl create deployment web --image=nginx:1.15 --replicas=3
apiVersion: apps/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:app: nginxname: nginxspec:replicas: 3selector:matchLabels:app: nginxstrategy: {}template:metadata:creationTimestamp: nulllabels:app: nginxspec:containers:- image: nginx:1.16name: nginxresources: {}livenessProbe:httpGet:path: /port: 80initialDelaySeconds: 3 #启动容器后多少秒健康检查periodSeconds: 10 #以后每间隔多少秒检查一次readinessProbe:httpGet:path: /port: 80initialDelaySeconds: 3periodSeconds: 10
kubectl expose deployment nginx --port=80 --target-port=8080 --type=NodePort --dry-run=client -o yaml > service.yaml
apiVersion: v1kind: Servicemetadata:creationTimestamp: nulllabels:app: nginxname: nginxspec:ports:- port: 80protocol: TCPtargetPort: 80selector:app: nginxtype: NodePort
kubectl get svc,pods
• kubectl apply -f xxx.yaml(最常用的方式)
• kubectl set image deployment/web nginx=nginx:1.17
• kubectl edit deployment/web #使用系统编辑器打开
vi deployment.yaml
apiVersion: apps/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:app: nginxname: nginxspec:replicas: 3selector:matchLabels:app: nginxstrategy: {}template:metadata:creationTimestamp: nulllabels:app: nginxspec:containers:- image: nginx:1.17name: nginxresources: {}livenessProbe:httpGet:path: /port: 80initialDelaySeconds: 3 #启动容器后多少秒健康检查periodSeconds: 10 #以后每间隔多少秒检查一次readinessProbe:httpGet:path: /port: 80initialDelaySeconds: 3periodSeconds: 10
kubectl apply -f deployment.yaml
kubectl set image deployment/web 容器名=nginx:1.17
kubectl set image deployment nginx nginx=nginx:1.18
kubectl edit deployment nginx
第一步:创建RS(nginx-68dcf59cf5)并副本数设置为1(扩容)(1.17镜像起一个pod)第二步:将RS(nginx-686db6866d)副本数设置为2(缩容)第三步:将RS(nginx-68dcf59cf5)副本数设置为2(扩容)第四步:将RS(nginx-686db6866d)副本数设置为1(缩容)第五步:将RS(nginx-68dcf59cf5)副本数设置为3(扩容)第六步:将RS(nginx-686db6866d)副本数设置为0(缩容)
kubectl get replicaset
spec:replicas: 3revisionHistoryLimit: 10 # RS历史版本保存数量selector:matchLabels:app: webstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdate
kubectl scale deployment nginx --replicas=10
kubectl get pods
kubectl get ep
kubectl rollout history deployment/web # 查看历史发布版本kubectl rollout undo deployment/web # 回滚上一个版本kubectl rollout undo deployment/web --to-revision=2 # 回滚历史指定版本
kubectl rollout history deployment nginx
kubectl rollout undo deployment nginx
kubectl rollout history deployment nginx
kubectl rollout undo deployment/web --to-revision=2 # 回滚历史指定版本
kubectl describe rs |egrep "revision:|Name:|Image:"
kubectl delete deploy/web
kubectl delete svc/web
kubectl delete deployment nginx
kubectl delete svc nginx