섹션 3: Scheduling
53) Maunal Scheduling
Pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: nignx
labels:
name: nignx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 8000
Pod-bind-definition.yaml
piVersion: v1
kind: Binding
metadata:
name: nignx
target:
apiVersion: v1
kind: Node
name: node02
약 5개의 lab 완료 - 문제가 복잡한것은 없었으나 개념정리가 좀 더 필요하다
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
nodeName: node01 or controlplane ( 스케줄링 하고 싶은 노드에 따라 배정해줌)
containers:
- image: nginx
name: nginx
kubectl get pods -n kube-system
kubectl replace --forece -f nginx.yaml
kubectl get pods --watch
56) Labels and Selectors
수많은 서비스들을 각각의 쓰임새와 용도에 따라 관리하기 쉽도록 레이블링 해 줌
Selector 로 명령어로 직접 찾거나 yaml 파일에 미리 지정 해주기도 가능 ( ex, ReplicaSet, Service..)
metadata:
name: simple-webapp
labels:
app: App1
function: Front-end
selector 명령어 활용으로 문제들을 각각 답 할수있었는데 중복으로 골라내는 작업은 모르겠어서 하나하나씩 진행했다.
Solution /
kubectl get pods --selector env=dev --no-headers | wc -l
kubectl get all --selector env=prod,bu=finance,tier=frontend
59) Taint and Tolerations
Taint set on Node
Tolerations set on Pods
각각의 구성요소에 할당되는 권한같은 것을 부여해줌
반드시 해당 파트를 노드에 지정! 이라는 느낌보다
설정된 노드에 특정 파드만 허용 이라는 느낌
특정 파드만 거절 이라면 - 이후에 배울 Node Affinity
마스터 노드에는 스케줄링 안되더록 설정되어있음
kubectl describe node kubemaster | grep Taint
kubectl taint nodes node-name key=valie:taint-effect (NoSchedule/PerferNoSchedule/NoExecute)
kubectl taint nodes node1 app=blue:NoSchedule
Nodes 설정
apiVersion:
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: nginx-container
image: nginx
tolerations:
- key: "app"
operator: "equal"
effect: "NoSchedule"
7번에서 약간 막혔다
이번거는 전체적으로 솔루션과 함께 진행했다,,,
Solution
kubectl describe node node01
kubectl describe node node01 | grep -i taints
kubectl taint node node01 spary=mortein:NoSchedule
Untain 하기
kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-
62) Node Selectors
간단히 특정 노드에 특정 파드가 들어가게끔 도와줌
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes node-1 size=Large
apiVersion:
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: data-processor
image: data-processor
nodeSelector:
size: Large
63) Node Affinity
조금 더 복잡한 관계에서 중복으로 지정하거나 특정 파드만 제한하게끔 도와줌
apiVersion:
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: data-processor
image: data-processor
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matechExpressions:
- key: size
operator: In or NotIn or Exists .. etc
values:
- Small
- Medium
irequiredDuringSchedulingIgnoredDuringExecution:
preferredDuringSchedulingIgnoredDuringExecution:
requiredDuringSchedulingrequiredDuringExecution:
Lab
Solutions
kubectl describe node node01 | grep Taints
kubectl create deployment red --image=nginx --replicas=2 --dry-run=client -o yaml > red.yaml
vi edit red.yaml
shift+. 공백 생성
operator: Exists (Value 가 없는 경우)
66) Taint and Tolerations VS Node Affinity
Taint 와 Tolerations 설정으로 각각 할당 only 허용범위를 주지만 반드시 그 파드를 할당한다는 보장은 없음
이 한계점을
Node Affinity 가 해결함
하지만 다른 랜덤한 파드가 할당될수있다는 한계가 있음
= 이 두가지를 합쳐서 사용하면 모든 한계 극복해서 직접 할당 가능하게끔 설정
67) Resource Requirements and Limits
apiVersion: vi
kind: Pod
metadata:
name: myapp-pod
labels:
name: myapp-pod
spec:
containers:
- name: data-processor
image: data-processor
ports:
- containerPort: 8080
resources:
requests:
memory: "4Gi"
cpu: 1
limits:
memory: "2Gi"
cpu: 2
Exceed Limit - Terminate -> OOM (Out Of Memory)
Behavior - CPU
No Requests No Limits
No Requests Limits
Requests Limits
Requests No Limits ( Ideal)
Behavior - Memory
apiVersion: vi
kind: LimitRange
metadata:
name: cpu-resource-constraint
spec:
limit:
- default:
cpu: 500m
defaultRequest:
cpu: 500m
max:
cpu: "1"
min:
cpu: 100m
type: Container
apiVersion: vi
kind: LimitRange
metadata:
name: memory-resource-constraint
spec:
limit:
- default:
memory: 1Gi
defaultRequest:
memory: 1Gi
max:
memory: 1Gi
min:
memory: 500Mi
type: Container
Resource Quotas
apiVersion: vi
kind: ResourceQuota
metadata:
name: my-resource-quota
spec:
hard:
requests.cpu: 4
requests.memory: 4Gi
limits.cpu: 10
limits.memory: 10Gi
Lab and Solutions
이번 Lab 은 큰 어려움 없이 마칠수 있었다
Solution 으로 더 효율적으로 생성할 수 있는 방법을 참고해야겠다.
Another way to replace pod
kubectl edit pod elephant
카피되어 자동생성된 yaml 파일 ~~.yaml
kubectl replace --force -f ~~.yaml
71) DeamonSets
ReplicaSet 과 비슷한 방식으로 노드가 생기면 전체적으로 같은 파드를 같게끔 복제 해줌
Use Case - 모니터링 agent 심거나 로그 Viewer 가질때 유용 / kube-proxy / Networking
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: monitoring-daemon
spec:
selector:
matchLabels:
app: montiroing-agent
template:
metadata:
labels:
app: montiroing-agent
spec:
containers:
- name: montiroing-agent
image: montiroing-agent
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: monitoring-daemon
spec:
selector:
matchLabels:
app: montiroing-agent
template:
metadata:
labels:
app: montiroing-agent
spec:
containers:
- name: montiroing-agent
image: montiroing-agent
kubectl get daemonsets
kubectl describe daemonsets monitoring-daemon
Lab and Solutions
Daemonset 셋업하기
- Deployment 와 비슷하므로 설정해서 수정하기
kubectl create deployment elasticsearch -n kube-system --image=iamge --dry-run=client -o yaml > fluentd.yaml
kind -> Daemonset 변경
spec 의 replicase / strategy 제거 , status 제거
kubectl create -f fluentd.yaml
74) Static Pods
Static Pods VS DaemonSets
Created by kubelet / Created by Kube-API server(DaemonSet Controller)
Deploy Control Plan components as Static Pods / Deploy Monitoring Agents, Logging Agents on Nodes
Both ignored by the kube-Scheduler
Lab and Solutions
Static Pods 확인 방법
kubectl get pod podname -n kube-system -o yaml
owner reference 의 kind - node 와 name - controlplane 확인
cat /var/lib/kubelet/config.yaml
에서 staticpodpath 확인 가능
ls /etc/kubernetes/manifests
kubectl run static-busybox --image=busybox --restart=Never --dry-run=client -o yaml --command -- sleep 1000 > static-busybox.yaml
cp static-busybox.yaml /etc/kubernetes/manifests
kubectl get pods
kubectl get pods
static pod 지우기
kubectl delete pods 명령어는 안 통함
kubectl get nodes -o wide 로 ip 주소 확인
ssh ip주소
ls /etc/kubernets/manifests/
cat /var/lib/kubelet/config.yaml 에서 staticpath 재확인
cd /etc/just-to-mess-with-you
ls
rm greenbox.yaml
이번에도 개념정립이 더 필요할 것 같아서 바로 랩과 솔루션 동시에 진행했다
특히 마지막 문제가 복잡하다
77) Multiple Schedulers
apiVersion: v1
kind: Pod
metadata:
name: my-custom-scheduler
namespace: kube-system
spec:
containers:
- command :
- kube-scheduler
- --address=127.0.0.1
- --kubeconfig=/etc/kubernetes/scheduler.conf
- --config=/etc/kubernets/my-scheduler-config.yaml
image: k8s.ger.io/kube-scheduler-amd64:v1.11.3
name: kube-scheduler
apiVersion: kubescheduler.config.k8s.io/v1
kind: kubeschedulerConfiguration
profiles:
- schedulerName: my-scheduler
leaderElection:
leaderElect: true
resourceNamespace: kube-system
resourName: lock-object-my-scheduler
view schedulers - kubectl get pods --namespace=kube-system
view events - kubectl get events -o wide
view schedulers logs - kubectl logs my-custom-scheduler --name-space=kube-system
Lab and Solutions
현재 이미지 가져오기
kubectl get pods -A
kubectl describe pod 스케쥴러 파일 이름 -n kube-system | grep Image
kubectl create configmap my-scheduler-config --from-file=/root/my-scheduler-configmap/my-scheduler-config.yaml -n kube-system
kubectl get configmap my-scheduler-config -n kube-system
yaml spec 다음에 schedulerName: 커스텀 스케줄 이름 추가
솔루션과 동시에 진행하였다
약간 알듯 말듯.. ㅎ
80) Configuring Scheduler Profiles
Scheduling Plugins ( Extension Points)
Scheduling Queue - PrioirySort (queueSort)
Filtering - NodeResourcesFit / NodeName / NodeUnschedulable (filter)
Scoring - NodeResourcesFit / ImageLocality (score)
Binding - DefaultBinder (Binding)
apiVersion: kubescheduler.config.k8s.io/v1
kind: kubeschedulerConfiguration
profiles:
- schedulerName: my-scheduler
plugins:
score:
disabled:
- name: TainToleration
enabled:
- name: MyCustomPluginA
- name: MyCustomPluginB
섹션 2도 한주에 이어 마무리 되었다.
아직 절반도 안된 강의지만 지금까지 배운것을 마스터하려면 한참 더 복습해야할것같다
'Kubernates' 카테고리의 다른 글
쿠버네티스 따배씨 강의 (1) | 2024.01.24 |
---|---|
쿠버네티스 101 (1) | 2024.01.22 |
Kubernetes 쿠버네티스 CKA (Udemy 강의#04) (0) | 2023.07.26 |
Kubernetes 쿠버네티스 CKA (Udemy 강의#03) (0) | 2023.07.21 |
Kubernetes 쿠버네티스 CKA (Udemy 강의#01) (0) | 2023.07.07 |