July 29, 2021
Delete the existing pod first. Run the below command:
$ kubectl delete po nginx
To list and know the names of available nodes on the cluster:
$ kubectl get nodes
Add the nodeName field under the spec section in the nginx.yaml file with node01 as the value:
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
nodeName: node01
containers:
- image: nginx
name: nginx
Then run the command kubectl create -f nginx.yaml to create a pod from the definition file.
To check the status of a nginx pod and to know the node name:
$ kubectl get pods -o wide
label์ ์ง์ ํ๊ณ selector๋ก ๋งค์นญ์ํค๊ธฐ :)
label์ด env=prod์ด๊ณ tier=frontend์ธ pod ๋ค ์กฐํํด์ฃผ์ธ์!
kubectl get po -l env=prod,tier=frontend
toleration์ ํ๋์ ์ง์ ํด์ taint๋ฅผ ๊ฑด node์ toleration ์กฐ๊ฑด์ด ๋ถํฉํ์ง ์์ผ๋ฉด ์ ๊ทผํ์ง ๋ชปํ๊ฒ ํจ. ๊ทธ๋ฌ๋๊น except์ ๊ฐ๋ ์ธ ๊ฒ ๊ฐ๋ค.
A๋ผ๋ ์กฐ๊ฑด์ ๊ฐ์ง pod๋ง taint nodes nodeAAA A
ํ nodeAAA
์ ๋ค์ด์ฌ ์ ์๋ ๊ฒ!
kubectl run bee --image=nginx --restart=Never --dry-run -o yaml > bee.yaml
kubectl explain pod --recursive | grep -A5 tolerations
ํน์ ๋ ธ๋์ pod ๋์ฐ๊ณ ์ถ์ ๋ ์ฌ์ฉ
๋ผ๋ฒจ์ ์ด๋ ๊ฒ ์ง์
kubectl label nodes node-1 size=large
kubectl label node node01 color=blue
pod์ nodeSelector
๋ spec
์๋์ ์์น!
๋ ธ๋ ์ ๋ ํฐ์ ๋น์ทํ๊ฒ ํน์ ๋ ธ๋์ pod๋ฅผ ์ง์ ํด์ ๋์ฐ๊ณ ์ถ์๋ฐ, ๊ทธ๋ฐ ์กฐ๊ฑด์ ์กฐ๊ธ ๋ ์์ ๋กญ๊ฒ ์ฌ์ฉํ ์ ์์
requiredDuringSchedulingIgnoredDuringExecution
์ preferredDuringSchedulingIgnoredDuringExecution
๋ก ๋ถ๋ฅด๋ ๋ ๊ฐ์ง ์ข
๋ฅ์ ๋
ธ๋ ์ดํผ๋ํฐ
๊ทธ๋ฆฌ๊ณ requiredDuringSchedulingRequiredDuringExecution
๊น์ง!
DuringScheduling ์ํ์ DuringExecution ์ํ์ ๋ฐ๋ผ, ๋ค๋ฅธ ๊ฒ ๊ฐ์.
๋ฐ๋ผ์ requiredDuringSchedulingIgnoredDuringExecution
์ ์๋ก๋ โ์ธํ
CPU๊ฐ ์๋ ๋
ธ๋์์๋ง ํ๋ ์คํโ์ด ๋ ์ ์๊ณ , preferredDuringSchedulingIgnoredDuringExecution
์ ์๋ก๋ โ์ฅ์ ์กฐ์น ์์ญ XYZ์ ํ๋ ์งํฉ์ ์คํํ๋ ค๊ณ ํ์ง๋ง, ๋ถ๊ฐ๋ฅํ๋ค๋ฉด ๋ค๋ฅธ ๊ณณ์์ ์ผ๋ถ๋ฅผ ์คํํ๋๋ก ํ์ฉโ์ด ์์ ๊ฒ์ด๋ค.
์ด๋ ๋ค๊ณ ํฉ๋๋ค :)
Q. Set Node Affinity to the deployment to place the pods on node01 only.
apiVersion: apps/v1
kind: Deployment
metadata:
name: blue
spec:
replicas: 3
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
Q. ์ด๋ค ๊ฐ์ ๋ฐ๊ฟ์ ํ๋๋ฅผ ๋์ฐ์ธ์ ๋ผ๋ ๋ฌธ์ ์์, ์ด๋ป๊ฒ ์ปค๋งจ๋๋ฅผ ์น๋์ง?
A. ๋๊ฐ์ ๊ฒฝ์ฐ๋ kubectl edit ํ๊ณ yaml ์ ์ฅํ ๋ค์์, applyํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋๋ฐ ๋ค๋ฅธ ์ฌ๋์ ์ด๋ป๊ฒ ํ๋์ง ๊ถ๊ธ!
๋ ธ๋๊ฐ ํด๋ฌ์คํฐ์ ์ถ๊ฐ๋๋ฉด ํ๋๋ ์ถ๊ฐ๋จ!
์ฉ๋
Q. What is the path of the directory holding the static pod definition files?
$ ps -aux | grep kubelet
$ cat /var/lib/kubelet/config.yaml
Q. static pod ์๋ณ
static pod๋ฅผ ์ธ์งํ๋ ๋ฐฉ๋ฒ์ด kubectl get pods โall-namespaces์์ -controlplane์ด ๋ถ์ ๊ฒ์ด๋ค (?)
Note
static pod๋ฅผ ๋ง๋๋ ค๋ฉด, kubelet์ด ์ฌ์ฉํ๋ config์์น๋ฅผ ๋ด์ผ ํ๊ณ
kubelet์ config.yaml์์ ์ด๋ ์์น์ธ์ง ๋๋ ํ ๋ฆฌ ํ์ธ ํ(์๋ฅผ ๋ค์ด/etc/kubernetes/manifests
)
๊ฑฐ๊ธฐ์ yamlํ์ผ์ ์์ฑํ๋ฉด, static pod๊ฐ ์๋์ผ๋ก ๋ธ!
์ด๊ฑด pod ํ๋ฒ์ command๋ก ๋์ฐ๊ณ static pod directory์ ๊ฐ์ ธ๋ค ๋ฃ๋ ๊ฒ!
kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml
Q. multiple scheduler ๋ง๋ค๊ธฐ
kubelet์ configPath๋ก ๊ฐ์ scheduler.yaml์ ๋ณต์ฌํ ๋ค์์, ์ํ๋ ๊ฐ์ผ๋ก ๋ณ๊ฒฝํ kubectl create -f custom.yaml
ํด์ฃผ๊ธฐ!
leader-elect=false์ฌ์ผ ํ๊ณ (custom์ด๋๊น), port๋ secure-port ๋ณ๊ฒฝํด์ค์ผ ํจ!
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
component: my-scheduler
tier: control-plane
name: my-scheduler
namespace: kube-system
spec:
containers:
- command:
- kube-scheduler
- --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
- --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
- --bind-address=127.0.0.1
- --kubeconfig=/etc/kubernetes/scheduler.conf
- --leader-elect=false
- --port=10282
- --scheduler-name=my-scheduler
- --secure-port=0
image: k8s.gcr.io/kube-scheduler:v1.20.0
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 8
httpGet:
host: 127.0.0.1
path: /healthz
port: 10259
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
name: kube-scheduler
resources:
requests:
cpu: 100m
startupProbe:
failureThreshold: 24
httpGet:
host: 127.0.0.1
path: /healthz
port: 10259
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
volumeMounts:
- mountPath: /etc/kubernetes/scheduler.conf
name: kubeconfig
readOnly: true
hostNetwork: true
priorityClassName: system-node-critical
volumes:
- hostPath:
path: /etc/kubernetes/scheduler.conf
type: FileOrCreate
name: kubeconfig
status: {}
custom scheduler๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ pod์ spec ์๋์ schedulerName
์ ๋ฃ์ด์ฃผ๋ฉด ๋!
apiVersion: v1
kind: Pod
metadata:
name: annotation-default-scheduler
labels:
name: multischeduler-example
spec:
schedulerName: default-scheduler
containers:
- name: pod-with-default-annotation-container
image: k8s.gcr.io/pause:2.0