k8s-deployment控制器
1、yaml文件标签学习-指定pod在哪台节点上创建
强制指定pod在指定节点上创建:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web1
template:
metadata:
labels:
app: web1
spec:
nodeName: node01.local # 强制指定pod在node01.local节点上创建
containers:
- name: my-pod-dep
image: 192.168.84.11/k8s/music:v3
ports:
- protocol: TCP
containerPort: 80
给node节点打标签,选择pod在那个标签的node节点运行
查看节点标签
[root@master ~]# kubectl get nodes node01.local --show-labels
NAME STATUS ROLES AGE VERSION LABELS
node01.local Ready <none> 17h v1.17.6
beta.kubernetes.io/arch=amd64,
beta.kubernetes.io/os=linux,
kubernetes.io/arch=amd64,
kubernetes.io/hostname=node01.local,
kubernetes.io/os=linux
打标签
[root@master ~]# kubectl label nodes node01.local disktype=ssd #打标签
node/node01.local labeled
[root@master ~]# kubectl get nodes node01.local --show-labels
NAME STATUS ROLES AGE VERSION LABELS
node01.local Ready <none> 17h v1.17.6 beta.kubernetes.io/arch=amd64,
beta.kubernetes.io/os=linux,
disktype=ssd, #打的标签
kubernetes.io/arch=amd64,
kubernetes.io/hostname=node01.local,
kubernetes.io/os=linux
使用标签
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels: #选择下面的template的pod
app: web1 #选择下面的template的pod
template:
metadata:
labels:
app: web1
spec:
#nodeName: node01.local
nodeSelector: # 选择标签disktype=ssd的节点
disktype: ssd
containers:
- name: my-pod-dep
image: 192.168.84.11/k8s/music:v3
ports:
- protocol: TCP
containerPort: 80
2、集群扩容方法
replicas:使用replicas标签
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 6 # 使用replicas标签
selector:
matchLabels:
app: web1
template:
metadata:
labels:
app: web1
spec:
#nodeName: node01.local
nodeSelector:
disktype: ssd
containers:
- name: my-pod-dep
image: 192.168.84.11/k8s/music:v3
ports:
- protocol: TCP
containerPort: 80
使用命令
[root@master ~]# kubectl edit deployments.apps my-deployment
deployment.apps/my-deployment edited
2、
[root@master ~]# kubectl scale deployment my-deployment --replicas=2
deployment.apps/my-deployment scaled
3、节点调度策略
https://kubernetes.io/zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/