K8S k8s(7)__部署功能 发表于 2022-09-02 浏览量 378 没有评论 # K8s的部署功能 K8s为了持续部署,提供了Deployment类型,可以方便我们升级、回滚、扩容等。还有很多种,可自行了解。 # 使用Deployment类型部署容器 ``` cat create.yml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx spec: replicas: 2 minReadySeconds: 15 strategy: rollingUpdate: maxSurge: 0 maxUnavailable: 1 template: metadata: name: nginx labels: app: nginx spec: containers: - name: mynginx imagePullPolicy: Always image: 192.168.237.50:5000/shijiange:nginx ``` # 配置详解 ``` minReadySeconds:15 #容器启动15s才认为该容器是正常的 maxSurge #升级的时候新增容器的数量 maxUnavailable #最多允许多少个容器不可用,也可以理解为升级并发。 ``` # Deployment查看 ``` kubectl --server=192.168.237.50:8080 get deployment kubectl --server=192.168.237.50:8080 get pods kubectl --server=192.168.237.50:8080 describe pod nginx ``` - 准备一个新镜像 ``` vim /docker/nginx2/Dockerfile FROM 192.168.237.50:5000/shijiange:nginx COPY index.html /usr/local/nginx/html/index.html vim index.html k8s version 2 docker build -t 192.168.237.50:5000/shijiange:nginx2 /docker/nginx2/ docker push 192.168.237.50:5000/shijiange:nginx2 ``` # K8S升级部署实战 kubectl set image deployment/nginx mynginx=192.168.237.50:5000/shijiange:nginx2 查看是否升级成功 # K8S回滚实 ``` kubectl rollout history deployments # 查看历史版本 kubectl rollout undo deployment/nginx --to-revision=x # 指定回滚的版本 ``` # 动态扩容和缩容 ``` kubectl scale deployment nginx --replicas=x ```