题干
For this question, please set this context (In exam, diff cluster name)
对于这个问题,请设置这个上下文(在考试中,diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
product pod is running. when you access logs of this pod, it displays the output Mi Tv Is Good
Please update the pod definition file to utilize an environment variable with the value Sony Tv Is Good Then, recreate this pod with the modified configuration.
product pod 正在运行。当您访问这个 pod 的日志时,它显示输出 Mi Tv Is Good 请更新 pod 定义文件,以利用一个值为 Sony Tv Is Good 的环境变量 然后,使用修改后的配置重新创建这个 pod。
解题思路
kubectl edit命令无法在线修改 Pod 资源对象的属性。
- 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 通过
kubectl get pod product -o yaml > product.yaml
导出Pod的yaml进行更新修改,添加了环境变量,并把环境变量输出到控制台中。
- command:- sh- -c- echo $Sony && sleep 3600image: busyboximagePullPolicy: Alwaysname: product-containerenv:- name: Sonyvalue: "Sony Tv Is Good"
- 把原来的Pod删除掉,重新提交更新的Pod资源清单
controlplane $ k delete pod product
pod "product" deleted
controlplane $ k apply -f product.yaml
pod/product created
controlplane $ k get pod
NAME READY STATUS RESTARTS AGE
product 1/1 Running 0 3s