题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Create a pod called sleep-pod using the nginx image and also sleep for give any value for seconds.
使用nginx image创建一个名为sleep pod的pod,并指定sleep的秒数。
解题思路
- 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 根据题干要求通过命令行方式或者资源清单方式创建Pod
- 命令方式创建
kubectl run sleep-pod --image nginx --command sleep 3000
- 资源清单方式创建
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: sleep-pod
name: sleep-pod
spec:
containers:
- command:
- sleep
- "3000"
image: nginx
name: sleep-pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
执行下面命令,提交资源清单
controlplane $ k apply -f sleep-pod.yaml
pod/sleep-pod created
查看Pod状态
controlplane $ k get pod
NAME READY STATUS RESTARTS AGE
sleep-pod 1/1 Running 0 3s