Node Selector in Kubernetes
Делаю: 07.04.2019
По материалам из видео индуса:
https://www.youtube.com/watch?v=TFAASAfO_gg&list=PL34sAs7_26wNBRWM6BDhnonoA5FMERax0&index=10
Подготовили кластер и окружение как здесь.
$ kubectl label node node2.k8s demoserver=true
$ kubectl get node node2.k8s --show-labels
NAME STATUS ROLES AGE VERSION LABELS
node2.k8s Ready <none> 53m v1.14.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,demoserver=true,kubernetes.io/arch=amd64,kubernetes.io/hostname=node2.k8s,kubernetes.io/os=linux
$ mkdir ~/tmp/node-selector && cd ~/tmp/node-selector
$ curl -LJO https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/1-nginx-deployment.yaml
$ vi 1-nginx-deployment.yaml
Дописываем nodeSelector
И replicas: 1
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: nginx
name: nginx-deploy
spec:
replicas: 1
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
name: nginx
nodeSelector:
demoserver: "true"
$ kubectl create -f 1-nginx-deployment.yaml
$ kubectl scale deploy nginx-deploy --replicas=2
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deploy-564845db65-kqbw4 1/1 Running 0 17s 10.244.2.3 node2.k8s <none> <none>
nginx-deploy-564845db65-l9jqc 1/1 Running 0 85s 10.244.2.2 node2.k8s <none> <none>
Удаляем все это добро
$ kubectl delete -f 1-nginx-deployment.yaml
deployment.extensions "nginx-deploy" deleted