首页
技术小册
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控制器
节点亲和性分为强制选择(硬亲和)和优先选择(软亲和): - 强制选择requiredDuringSchedulingIgnoredDuringExecution - 满足则调度(案例一) - 不满足则Pending(案例二) - 优先选择preferredDuringSchedulingIgnoredDuringExecution - 不满足则调度到其它节点(案例三) - 满足则优先调度到该节点,并不是一定调度到该节点,而且该节点优先级较高(案例四) 案例一 ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 5 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx-demo image: linuxmaxiaoke/nginx:v1.0.0 affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: ssd operator: DoesNotExist - key: cpu operator: In values: ["high"] ``` ``` [root@maxiaoke ~]# kubectl get pod -o wide # 不存在ssd标签,并且cpu值为 high NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deploy-6f8b6d748c-4pt2x 1/1 Running 0 8s 172.16.5.20 centos-7-56 <none> <none> nginx-deploy-6f8b6d748c-m9kb4 1/1 Running 0 8s 172.16.5.19 centos-7-56 <none> <none> nginx-deploy-6f8b6d748c-st8mw 1/1 Running 0 5s 172.16.5.22 centos-7-56 <none> <none> nginx-deploy-6f8b6d748c-w4mc9 1/1 Running 0 5s 172.16.5.21 centos-7-56 <none> <none> nginx-deploy-6f8b6d748c-wjvxx 1/1 Running 0 8s 172.16.5.18 centos-7-56 <none> <none> ``` 案例二 ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 5 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx-demo image: linuxmaxiaoke/nginx:v1.0.0 affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: ssd operator: DoesNotExist # 此处改为cpu不等于high - key: cpu operator: NotIn values: ["high"] ``` ``` [root@maxiaoke ~]# kubectl describe pod nginx-deploy-746f88c86-96dbp # 注意message Name: nginx-deploy-746f88c86-96dbp Namespace: default Priority: 0 Node: <none> ...... Status: Pending ...... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 30s (x3 over 32s) default-scheduler 0/6 nodes are available: 3 node(s) didn't match node selector, 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate. ``` 案例三 ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 5 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx-demo image: linuxmaxiaoke/nginx:v1.0.0 affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - preference: matchExpressions: # 系统中并没有这个的Node - key: ssd operator: DoesNotExist - key: cpu operator: NotIn values: ["high"] weight: 5 ``` 案例四 ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 5 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx-demo image: linuxmaxiaoke/nginx:v1.0.0 affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: # 满足该条件的节点为 centos-7-56,当并不是一把梭全部压在该节点,而且该节点的优先级更高,通过weight可以增加优先级 - preference: matchExpressions: - key: ssd operator: DoesNotExist - key: cpu operator: In values: - high weight: 10 ``` ``` [root@maxiaoke local-k8s-yaml]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deploy-5996df99f8-4cmfv 1/1 Running 0 7s 172.16.4.4 centos-7-55 <none> <none> nginx-deploy-5996df99f8-77k5l 1/1 Running 0 7s 172.16.5.38 centos-7-56 <none> <none> nginx-deploy-5996df99f8-8kxvc 1/1 Running 0 7s 172.16.5.37 centos-7-56 <none> <none> nginx-deploy-5996df99f8-t55hj 1/1 Running 0 7s 172.16.3.161 centos-7-54 <none> <none> nginx-deploy-5996df99f8-zbpf2 1/1 Running 0 7s 172.16.5.39 centos-7-56 <none> <none> ```
上一篇:
8.2. 节点选择器
下一篇:
8.4. Pod亲和性
该分类下的相关小册推荐:
云原生-K8S入门实战
Kubernets合辑9-资源约束
Kubernets合辑10-网络
Kubernets合辑13-集群监控
Kubernetes中文教程(五)
Kubernetes中文教程(一)
Kubernets合辑11-持续集成
Kubernets合辑15-持续部署
Kubernetes中文教程(二)
Kubernets合辑2-部署Ingress
Kubernetes中文教程(三)
Kubernets合辑4-kubernetes入门