Task weight: 3%
Use context: kubectl config use-context k8s-c1-H
Create a single Pod of image httpd:2.4.41-alpine in Namespace default. The Pod should be named pod1 and the container should be named pod1-container. This Pod should only be scheduled on a controlplane node, do not add new labels any nodes.
译文:
在namespace default中创建一个 httpd:2.4.41-alpine 的Pod。这个Pod应该被命名为pod1,容器应该被命名为pod1-container。这个Pod应该只被安排在控制平面节点上,不要在任何节点上添加新的标签。
解答:
切换集群环境
kubectl config use-context k8s-c1-H
首先,我们找到控制平面节点和它们的污点
k get node #找到controlplane节点
k describe node cluster1-controlplane1 | grep -i taints -A1 #查看节点污点
k get node cluster1-controlplane1 --show-labels #查看节点标签
创建一个pod模板
k run pod1 --image=httpd:2.4.41-alpine $do > 2.yaml
vim 2.yaml
2.yaml
# 2.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: pod1
name: pod1
spec:
containers:
- image: httpd:2.4.41-alpine
name: pod1-container # change
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
tolerations: # add
- effect: NoSchedule # add
key: node-role.kubernetes.io/control-plane # add
nodeSelector: # add
node-role.kubernetes.io/control-plane: "" # add
status: {}
创建pod
k -f 2.yaml create