调度器章节


任务:
Manually schedule the pod on node01.
答案:


任务和答案:

任务:
Create a taint on node01 with key of spray, value of mortein and effect of NoSchedule
答案:
kubectl taint nodes node01 spray=mortein:NoSchedule
概念:
总结:key 是分类标签,value 是具体内容,二者配合可以实现更细粒度的调度控制。没有固定值,主要看你的需求!

任务:
Remove the taint on controlplane, which currently has the taint effect of NoSchedule.
答案:
kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-
任务:
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
任务:
Create a new deployment named blue with the nginx image and 3 replicas.
答案:
kubectl create deployment blue --image=nginx --replicas=3
任务和答案:

The status OOMKilled indicates that it is failing because the pod ran out of memory. Identify the memory limit set on the POD.
任务:
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.
答案:

任务和答案:
默认的命名空间是default

任务和答案:

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

任务和答案:
创建static pod需要设置restart=Never


一个比较复杂的任务:
要删掉一个static pod,但不在当前节点上,要先去看这个pod在哪个节点,再根据进程去找对应的配置文件路径,删掉后再去看pod



任务:
What is the priority value assigned to system-node-critical?
答案:

概念:
preemptionPolicy
这个字段控制在调度时,优先级较低的Pod是否可以抢占(preempt)优先级更高的Pod。它的值决定了抢占策略。
在 system-node-critical 这个PriorityClass中,preemptionPolicy 的值是 PreemptLowerPriority,意味着优先级较低的Pod可以抢占优先级更高的Pod,以确保关键系统Pod的运行。
任务:
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."
然后执行kubectl get priorityclasses这样去查看
任务:
What is the name of the POD that deploys the default kubernetes scheduler in this environment?
答案:
kubectl get pods --namespace=kube-system
Kubernetes 的核心组件(如调度器、API 服务器、控制器管理器等)都运行在 kube-system 命名空间里,这是 Kubernetes 预定义的系统命名空间,用于存放集群的系统级 Pod 和资源。
所以,调度器 Pod 也在 kube-system 命名空间中运行。
任务和答案:


一些概念
admission controller

他的配置文件如下所示


任务
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):在资源被创建或修改之前,可以修改请求中的对象,比如自动添加标签或注释。
验证准入控制器(Validating Admission Controller):在资源被创建或修改之后,验证请求的合法性,确保符合策略。
NamespaceAutoProvision:作为变异(Mutating)控制器
NamespaceExists:作为验证(Validating)控制器
NamespaceAutoProvision 会在资源创建时自动为命名空间提供一些变异操作(比如自动创建命名空间或添加标签)。
NamespaceExists 会在资源提交后验证命名空间是否存在,确保请求的合法性。
一些概念
TLS secret 是用来存储 TLS(传输层安全协议)证书和私钥的 Kubernetes 资源。它们用于为服务提供加密通信,确保数据在传输过程中安全、私密,常用于 HTTPS 和 Webhook 等场景。
如何创建:
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的区别
Namespace 就像是一个虚拟的隔离空间,用来把不同的资源(如 Deployment、Service 等)分开管理,避免冲突。而Deployment 是用来定义和管理应用的副本(Pods),确保应用持续运行。
关系是:Deployment 需要在某个 Namespace 里创建,属于那个命名空间的资源。你可以在不同的 Namespace 中有相同名字的 Deployment,它们互不干扰。
一些概念

一些概念
指标服务器(Metrics Server)是一个集群级别的组件,用于收集和存储节点和Pod的资源使用数据(如CPU和内存),以便监控和自动扩展等功能。它是Kubernetes监控的基础之一。