728x90
반응형
Practice Test - Node Affinity
alias k=kubectl
# node01의 라벨 확인
k get no node01 --show-labels=true
k label no node01 color=blue
k create deploy blue --image=nginx --replicas=3 --dry-run=client -o yaml > blue.yaml
k apply -f blue.yaml
- node01에만 배포되는 nodeaffinity 설정
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: blue
name: blue
spec:
replicas: 3
selector:
matchLabels:
app: blue
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: blue
spec:
containers:
- image: nginx
name: nginx
resources: {}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
status: {}
k replace -f blue.yaml
- node-role.kubernetes.io/control-plane label이 존재하는 node에 배치하는 affinity 설정
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: red
name: red
spec:
replicas: 2
selector:
matchLabels:
app: red
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: red
spec:
containers:
- image: nginx
name: nginx
resources: {}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
status: {}
Practice Test - Resource Limits
k get po elephant -o yaml > elephant.yaml
## cpu limit 수정 후 pod 교체
k replace -f elephant.yaml --force=true
Practice Test - DaemonSets
apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
name: elasticsearch
namespace: kube-system
spec:
selector:
matchLabels:
app: FluentD
template:
metadata:
creationTimestamp: null
labels:
app: FluentD
spec:
containers:
- name: elasticsearch
image: registry.k8s.io/fluentd-elasticsearch:1.20
Practice Test - Stateful Pod
$ ps -ef | grep kubelet
root 2766 2225 0 00:48 ? 00:00:45 kube-apiserver --advertise-address=192.223.93.9 --allow-privileged=true --authorization-mode=Node,RBAC --client-ca-file=/etc/kubernetes/pki/ca.crt --enable-admission-plugins=NodeRestriction --enable-bootstrap-token-auth=true --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key --etcd-servers=https://127.0.0.1:2379 --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key --requestheader-allowed-names=front-proxy-client --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --secure-port=6443 --service-account-issuer=https://kubernetes.default.svc.cluster.local --service-account-key-file=/etc/kubernetes/pki/sa.pub --service-account-signing-key-file=/etc/kubernetes/pki/sa.key --service-cluster-ip-range=10.96.0.0/12 --tls-cert-file=/etc/kubernetes/pki/apiserver.crt --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
root 3711 1 0 00:48 ? 00:00:21 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.9
root 8491 7810 0 01:02 pts/0 00:00:00 grep kubelet
$ cat /var/lib/kubelet/config.yaml | grep -i static
staticPodPath: /etc/kubernetes/manifests
$ ls /etc/kubernetes/manifests
etcd.yaml kube-apiserver.yaml kube-controller-manager.yaml kube-scheduler.yaml
$ k run static-busybox --image=busybox --dry-run=client -o yaml --command -- sleep 1000 >> /etc/kubernetes/manifests/static-busybox.yaml
$ k get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
static-busybox-controlplane 1/1 Running 0 35s 10.244.0.5 controlplane <none> <none>
static-greenbox-node01 1/1 Running 0 15s 10.244.1.3 node01 <none> <none>
$ ssh node01
root@node01 ~ ➜ ps -ef | grep kubelet
root 6249 1 0 01:08 ? 00:00:01 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.9
root 6923 6849 0 01:09 pts/0 00:00:00 grep kubelet
root@node01 ~ ➜ cat /var/lib/kubelet/config.yaml | grep -i static
staticPodPath: /etc/just-to-mess-with-you
root@node01 ~ ➜ cd /etc/just-to-mess-with-you
root@node01 /etc/just-to-mess-with-you ➜ ls
greenbox.yaml
root@node01 /etc/just-to-mess-with-you ➜ rm greenbox.yaml
Practice Test - Multiple Schedulers
- 새로운 scheduler 추가
- 참고 자료 : https://kubernetes.io/ko/docs/tasks/extend-kubernetes/configure-multiple-schedulers/
apiVersion: v1
kind: Pod
metadata:
labels:
run: my-scheduler
name: my-scheduler
namespace: kube-system
spec:
serviceAccountName: my-scheduler
containers:
- command:
- /usr/local/bin/kube-scheduler
- --config=/etc/kubernetes/my-scheduler/my-scheduler-config.yaml
image: registry.k8s.io/kube-scheduler:v1.26.0
livenessProbe:
httpGet:
path: /healthz
port: 10259
scheme: HTTPS
initialDelaySeconds: 15
name: kube-second-scheduler
readinessProbe:
httpGet:
path: /healthz
port: 10259
scheme: HTTPS
resources:
requests:
cpu: '0.1'
securityContext:
privileged: false
volumeMounts:
- name: config-volume
mountPath: /etc/kubernetes/my-scheduler
hostNetwork: false
hostPID: false
volumes:
- name: config-volume
configMap:
name: my-scheduler-config
- 새로운 scheduler로 생성할 pod
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
schedulerName: my-scheduler
containers:
- image: nginx
name: nginx
- 이벤트 확인
$ controlplane ~ ➜ k get events -o wide | grep -i nginx
81s Normal Scheduled pod/nginx my-scheduler, my-scheduler-my-scheduler Successfully assigned default/nginx to controlplane 81s 1 nginx.1742b180abdcc231
80s Normal Pulling pod/nginx spec.containers{nginx} kubelet, controlplane Pulling image "nginx" 80s 1 nginx.1742b180e1fe697c
75s Normal Pulled pod/nginx spec.containers{nginx} kubelet, controlplane Successfully pulled image "nginx" in 4.58608765s (4.586095789s including waiting) 75s 1 nginx.1742b181f3590cdb
75s Normal Created pod/nginx spec.containers{nginx} kubelet, controlplane Created container nginx 75s 1 nginx.1742b181f680a579
75s Normal Started pod/nginx spec.containers{nginx} kubelet, controlplane Started container nginx 75s 1 nginx.1742b182087216a7
728x90
'기타 > 자격증' 카테고리의 다른 글
[CKA][실습] 4. Application Lifecycle Management (0) | 2023.02.18 |
---|---|
[CKA][실습] 3. Logging & Monitoring (0) | 2023.02.11 |
[CKA][실습] 2. Scheduling (0) | 2023.02.05 |
[CKA][실습] 1. Core Concepts (2) (0) | 2023.02.05 |
[CKA][실습] 1. Core Concepts (0) | 2023.02.04 |