調(diào)度器章節(jié)


任務(wù):
Manually schedule the pod on node01.
答案:


任務(wù)和答案:

任務(wù):
Create a taint on node01 with key of spray, value of mortein and effect of NoSchedule
答案:
kubectl taint nodes node01 spray=mortein:NoSchedule
概念:
總結(jié):key 是分類標簽,value 是具體內(nèi)容,二者配合可以實現(xiàn)更細粒度的調(diào)度控制。沒有固定值,主要看你的需求!

任務(wù):
Remove the taint on controlplane, which currently has the taint effect of NoSchedule.
答案:
kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-
任務(wù):
Apply a label color=blue to node node01
答案:
kubectl label node node01 color=blue
其實k8s命令還挺直接的,要加污點就是kubectl taint nodes xx,要對某個node加標簽就是kubectl label node node01 xx=xx
任務(wù):
Create a new deployment named blue with the nginx image and 3 replicas.
答案:
kubectl create deployment blue --image=nginx --replicas=3
任務(wù)和答案:

The status OOMKilled indicates that it is failing because the pod ran out of memory. Identify the memory limit set on the POD.
任務(wù):
The elephant pod runs a process that consumes 10Mi of memory. Increase the limit of the elephant pod to 20Mi.
Delete and recreate the pod if required. Do not modify anything other than the required fields.
答案:

任務(wù)和答案:
默認的命名空間是default

任務(wù)和答案:

任務(wù)和答案:
Deploy a DaemonSet for FluentD Logging.
要寫yaml文件然后apply
任務(wù):
How many static pods exist in this cluster in all namespaces?
答案:
kubectl get pods --all-namespaces |wc -l
概念

任務(wù)和答案:
創(chuàng)建static pod需要設(shè)置restart=Never


一個比較復(fù)雜的任務(wù):
要刪掉一個static pod,但不在當前節(jié)點上,要先去看這個pod在哪個節(jié)點,再根據(jù)進程去找對應(yīng)的配置文件路徑,刪掉后再去看pod



任務(wù):
What is the priority value assigned to system-node-critical?
答案:

概念:
preemptionPolicy
這個字段控制在調(diào)度時,優(yōu)先級較低的Pod是否可以搶占(preempt)優(yōu)先級更高的Pod。它的值決定了搶占策略。
在 system-node-critical 這個PriorityClass中,preemptionPolicy 的值是 PreemptLowerPriority,意味著優(yōu)先級較低的Pod可以搶占優(yōu)先級更高的Pod,以確保關(guān)鍵系統(tǒng)Pod的運行。
任務(wù):
Create another PriorityClass named low-priority with a value of 1000. Do not set this class as a global default.
答案:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: low-priority
value: 1000
globalDefault: false
description: "This priority class is used for low-priority pods."
然后執(zhí)行kubectl get priorityclasses這樣去查看
任務(wù):
What is the name of the POD that deploys the default kubernetes scheduler in this environment?
答案:
kubectl get pods --namespace=kube-system
Kubernetes 的核心組件(如調(diào)度器、API 服務(wù)器、控制器管理器等)都運行在 kube-system 命名空間里,這是 Kubernetes 預(yù)定義的系統(tǒng)命名空間,用于存放集群的系統(tǒng)級 Pod 和資源。
所以,調(diào)度器 Pod 也在 kube-system 命名空間中運行。
任務(wù)和答案:


一些概念
admission controller

他的配置文件如下所示


任務(wù)
Reconfigure the API server to enable the ImagePolicyWebhook admission plugin and ensure it can access the configuration files.
ImagePolicyWebhook admission plugin enabled on kube-apiserver?
admission-control-config-file flag set on kube-apiserver?
imgvalidation volume mounted in kube-apiserver?

一些概念
變異準入控制器(Mutating Admission Controller):在資源被創(chuàng)建或修改之前,可以修改請求中的對象,比如自動添加標簽或注釋。
驗證準入控制器(Validating Admission Controller):在資源被創(chuàng)建或修改之后,驗證請求的合法性,確保符合策略。
NamespaceAutoProvision:作為變異(Mutating)控制器
NamespaceExists:作為驗證(Validating)控制器
NamespaceAutoProvision 會在資源創(chuàng)建時自動為命名空間提供一些變異操作(比如自動創(chuàng)建命名空間或添加標簽)。
NamespaceExists 會在資源提交后驗證命名空間是否存在,確保請求的合法性。
一些概念
TLS secret 是用來存儲 TLS(傳輸層安全協(xié)議)證書和私鑰的 Kubernetes 資源。它們用于為服務(wù)提供加密通信,確保數(shù)據(jù)在傳輸過程中安全、私密,常用于 HTTPS 和 Webhook 等場景。
如何創(chuàng)建:
kubectl -n webhook-demo create secret tls webhook-server-tls \
--cert "/root/keys/webhook-server-tls.crt" \
--key "/root/keys/webhook-server-tls.key"
一些概念
namespace和deployment的區(qū)別
Namespace 就像是一個虛擬的隔離空間,用來把不同的資源(如 Deployment、Service 等)分開管理,避免沖突。而Deployment 是用來定義和管理應(yīng)用的副本(Pods),確保應(yīng)用持續(xù)運行。
關(guān)系是:Deployment 需要在某個 Namespace 里創(chuàng)建,屬于那個命名空間的資源。你可以在不同的 Namespace 中有相同名字的 Deployment,它們互不干擾。
一些概念

一些概念
指標服務(wù)器(Metrics Server)是一個集群級別的組件,用于收集和存儲節(jié)點和Pod的資源使用數(shù)據(jù)(如CPU和內(nèi)存),以便監(jiān)控和自動擴展等功能。它是Kubernetes監(jiān)控的基礎(chǔ)之一。