题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
You have an existing Nginx pod named nginx-pod . Perform the following steps:
- Expose the nginx-pod internally within the cluster using a Service named nginx-service .
- Use port forwarding to service to access the Welcome content of nginx-pod using the curl command.
你有一个名为Nginx -pod的现有Nginx pod。请执行以下步骤:
- 使用一个名为
nginx-service
的服务在集群内部公开nginx-pod。- 使用端口转发服务,使用curl命令访问
nginx-pod
的欢迎内容。
解题思路
- 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 通过kubectl export命令发布SVC
controlplane $ kubectl expose pod nginx-pod --name nginx-service
service/nginx-service exposed
- 验证结果
controlplane $ k get svc nginx-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service ClusterIP 10.103.170.66 <none> 80/TCP 2m23s