首页
技术小册
AIGC
面试刷题
技术文章
MAGENTO
云计算
视频课程
源码下载
PDF书籍
「涨薪秘籍」
登录
注册
1. Pod
1.1. Pod介绍
1.1.1. Pod简介
1.1.2. Pod生命周期
1.1.3. Pod状态
1.2. Pod模板
1.2.1. apiversion/kind
1.2.2. metadata
1.2.3. spec
1.2.4. k8s和image中的命令
1.2.5. 就绪性探测和存活性探测
1.3. 案例
1.3.1. 创建简单pod
1.3.2. 带健康检测的pod
2. Deployment
2.1. 介绍
2.1.1. 简介
2.1.2. 部署方式
2.1.3. Deployment升级方案
2.2. 模板
2.3. 案例
2.3.1. 创建deployment
2.3.2. 模拟蓝绿发布
2.3.3. 滚动发布
2.3.4. 模拟灰度(金丝雀)发布
2.3.5. 版本回滚
2.3.6. 常用命令
3. DaemonSet
3.1. DaemonSet介绍
3.2. 模板
3.3. 案例
3.3.1. 创建daemonset
3.3.2. 升级daemonset
4. Job
4.1. Job介绍
4.2. 模板
4.3. 案例
5. CronJob
5.1. cronjob介绍
5.2. 模板
5.3. 案例
6. StatefulSet
6.1. 介绍
6.1.1. Statefulset使用场景
6.1.2. Statefulset注意项
6.2. 模板
6.3. 案例
6.3.1. 创建Statefulset资源
6.3.2. 扩缩容
6.3.3. 滚动更新
6.3.4. 删除Statefulset
6.3.5. 部署有状态应用一般思路
7. 原理分析
8. 调度
8.1. 调度器
8.2. 节点选择器
8.3. 节点亲和性
8.4. Pod亲和性
8.5. 污点和污点容忍度
当前位置:
首页>>
技术小册>>
Kubernets合辑5-Pod控制器
小册名称:Kubernets合辑5-Pod控制器
特别需要注意,文档中的方式只能说是接近蓝绿部署的效果,其实并不是真正的蓝绿部署,在更新的过程中,并不是所有的 Pod 都是同时切换到新版本的,尤其是在前端应用中,可能出现页面资源显示异常。 要想达到真正的蓝绿部署需要借助工具或者脚本实现: ``` 要求: 1. 不同版本的Deployment名称不同,比如 <appname>-<version> 2. 不同版本的Service名称相同,<appname>-svc 3. Deployment的Pod 标签选择器需要带上版本 version 标签 4. Service 需要使用 version 标签选择特定版本的 Pod 流程 1. 如果不存在旧版本Deployment,就正常部署 Deloyment 和 Service 2. 如果存在旧版本的Service,则获取旧版本的 version 变量,用于后续删除旧版本的 Deployment 3. 部署新版本的Deployment,并等待 Deployment Ready 4. 当新版本的 Deployment 全部Ready,就更新 Service 的标签选择器的 version,指向新版本的 Pod,然后删除旧版本的 Deployment 5. 如果新版本 Deployment 在指定时间内未就绪,那么更新终止并通知运维更新失败 ``` base_resource/deployment/nginx-v1.13.yaml: ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy namespace: app spec: replicas: 5 selector: matchLabels: app: nginx release: stable tier: slb partition: website strategy: rollingUpdate: # 最大浪涌数量为5 maxSurge: 5 maxUnavailable: 0 template: metadata: labels: app: nginx release: stable tier: slb partition: website # 修改版本信息,用于查看当前版本 version: v1.13 spec: containers: - name: nginx-pod # 修改镜像 image: harbor.od.com/public/nginx:v1.13 lifecycle: postStart: exec: command: - /bin/bash - -c - "echo 'health check ok!' > /usr/share/nginx/html/health.html" readinessProbe: initialDelaySeconds: 5 httpGet: port: 80 path: /health.html livenessProbe: initialDelaySeconds: 10 periodSeconds: 5 httpGet: port: 80 path: /health.html ``` ``` [root@hdss7-21 ~]# kubectl apply --filename=http://k8s-yaml.od.com/base_resource/deployment/nginx-v1.13.yaml --record=true [root@hdss7-21 ~]# kubectl rollout history deployment nginx-deploy -n app REVISION CHANGE-CAUSE 1 kubectl apply --filename=http://k8s-yaml.od.com/base_resource/deployment/nginx-v1.12.yaml --record=true 2 kubectl apply --filename=http://k8s-yaml.od.com/base_resource/deployment/nginx-v1.13.yaml --record=true [root@hdss7-21 ~]# kubectl get rs -n app -l tier=slb -L version # 多个ReplicaSet对应不同版本 NAME DESIRED CURRENT READY AGE VERSION nginx-deploy-5597c8b45 0 0 0 10m v1.12 nginx-deploy-6bd88df699 5 5 5 9m31s v1.13 ``` ``` # 升级过程中的状态变化: [root@hdss7-21 ~]# kubectl rollout status deployment nginx-deploy -n app Waiting for deployment "nginx-deploy" rollout to finish: 5 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 5 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 5 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 4 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 4 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 4 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 3 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 3 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 3 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 2 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 2 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 2 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "nginx-deploy" rollout to finish: 1 old replicas are pending termination... deployment "nginx-deploy" successfully rolled out [root@hdss7-21 ~]# kubectl get pod -n app -l partition=website -L version -w NAME READY STATUS RESTARTS AGE VERSION nginx-deploy-5597c8b45-t5plt 1/1 Running 0 19s v1.12 nginx-deploy-5597c8b45-tcq69 1/1 Running 0 19s v1.12 nginx-deploy-5597c8b45-vdjxg 1/1 Running 0 19s v1.12 nginx-deploy-5597c8b45-vqn9x 1/1 Running 0 19s v1.12 nginx-deploy-5597c8b45-zl6qr 1/1 Running 0 19s v1.12 ---- 立刻创建5个新版本pod,Pending调度中 nginx-deploy-6bd88df699-242fr 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-242fr 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-8pmdg 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-4kj8z 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-n7x6n 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-8pmdg 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-4kj8z 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-8j85n 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-n7x6n 0/1 Pending 0 0s v1.13 nginx-deploy-6bd88df699-8j85n 0/1 Pending 0 0s v1.13 ---- 创建pod中 nginx-deploy-6bd88df699-242fr 0/1 ContainerCreating 0 0s v1.13 nginx-deploy-6bd88df699-8pmdg 0/1 ContainerCreating 0 0s v1.13 nginx-deploy-6bd88df699-4kj8z 0/1 ContainerCreating 0 0s v1.13 nginx-deploy-6bd88df699-n7x6n 0/1 ContainerCreating 0 0s v1.13 nginx-deploy-6bd88df699-8j85n 0/1 ContainerCreating 0 0s v1.13 ---- 启动pod nginx-deploy-6bd88df699-242fr 0/1 Running 0 1s v1.13 nginx-deploy-6bd88df699-8j85n 0/1 Running 0 1s v1.13 nginx-deploy-6bd88df699-4kj8z 0/1 Running 0 1s v1.13 nginx-deploy-6bd88df699-n7x6n 0/1 Running 0 1s v1.13 nginx-deploy-6bd88df699-8pmdg 0/1 Running 0 1s v1.13 ---- Pod逐个就绪,且替换旧版本的pod nginx-deploy-6bd88df699-242fr 1/1 Running 0 6s v1.13 nginx-deploy-5597c8b45-t5plt 1/1 Terminating 0 50s v1.12 nginx-deploy-6bd88df699-8j85n 1/1 Running 0 7s v1.13 nginx-deploy-5597c8b45-vdjxg 1/1 Terminating 0 51s v1.12 nginx-deploy-5597c8b45-t5plt 0/1 Terminating 0 51s v1.12 nginx-deploy-5597c8b45-t5plt 0/1 Terminating 0 51s v1.12 nginx-deploy-6bd88df699-4kj8z 1/1 Running 0 7s v1.13 nginx-deploy-5597c8b45-zl6qr 1/1 Terminating 0 51s v1.12 nginx-deploy-5597c8b45-vdjxg 0/1 Terminating 0 52s v1.12 nginx-deploy-5597c8b45-vdjxg 0/1 Terminating 0 52s v1.12 nginx-deploy-5597c8b45-zl6qr 0/1 Terminating 0 53s v1.12 nginx-deploy-5597c8b45-t5plt 0/1 Terminating 0 54s v1.12 nginx-deploy-5597c8b45-t5plt 0/1 Terminating 0 54s v1.12 nginx-deploy-5597c8b45-zl6qr 0/1 Terminating 0 56s v1.12 nginx-deploy-5597c8b45-zl6qr 0/1 Terminating 0 56s v1.12 nginx-deploy-6bd88df699-n7x6n 1/1 Running 0 13s v1.13 nginx-deploy-5597c8b45-tcq69 1/1 Terminating 0 57s v1.12 nginx-deploy-5597c8b45-tcq69 0/1 Terminating 0 58s v1.12 nginx-deploy-5597c8b45-tcq69 0/1 Terminating 0 59s v1.12 nginx-deploy-6bd88df699-8pmdg 1/1 Running 0 15s v1.13 nginx-deploy-5597c8b45-vqn9x 1/1 Terminating 0 59s v1.12 nginx-deploy-5597c8b45-vqn9x 0/1 Terminating 0 60s v1.12 nginx-deploy-5597c8b45-vqn9x 0/1 Terminating 0 61s v1.12 nginx-deploy-5597c8b45-vqn9x 0/1 Terminating 0 61s v1.12 nginx-deploy-5597c8b45-vdjxg 0/1 Terminating 0 64s v1.12 nginx-deploy-5597c8b45-vdjxg 0/1 Terminating 0 64s v1.12 nginx-deploy-5597c8b45-tcq69 0/1 Terminating 0 64s v1.12 nginx-deploy-5597c8b45-tcq69 0/1 Terminating 0 64s v1.12 ```
上一篇:
2.3.1. 创建deployment
下一篇:
2.3.3. 滚动发布
该分类下的相关小册推荐:
Kubernets合辑14-日志收集
Kubernets合辑15-持续部署
Kubernetes中文教程(一)
Kubernets合辑11-持续集成
Kubernets合辑3-kubernetes介绍
Kubernets合辑12-配置中心
Kubernets合辑7-存储
云原生-K8S入门实战
Kubernets合辑9-资源约束
Kubernetes中文教程(二)
Kubernets合辑8-权限控制
Kubernets合辑10-网络