多标签案例
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: as
rel: stable
spec:
containers:
- name: web
image: httpd:latest
imagePullPolicy: IFNotPresent
ports:
- containerPort: 80
kubectl get pod --show-labels
kubectl get pod -l app=as
kubectl get pod -l app!=as
kubectl get pod -l 'app in (test, as)'
kubectl get pod -L app
kubectl label pod web rel=canary --overwrite
kubectl label pod web env=prod
指定pod部署到指定的节点
kubectl get nodes --show-labels
kubectl label nodes server2 disktype=ssd
案例
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-depl
spec:
selector:
matchLabels:
pod: nginx
replicas: 5
template:
metadata:
labels:
pod: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
nodeSelector:
disktype: ssd
或者通过主机名称指定pod在那个节点运行
nodeSelector:
disktype: ssd
修改为下面
nodeName:server3
kubectl label nodes server2 disktype-
kubectl label nodes server3 evn=prod
节点迁移
nodeSelector:
evn: prod