1.题目
There is pod name pod-nginx, create a service name service-nginx, use nodePort to expose the pod. Then create a pod use image busybox to nslookup the pod pod-nginx and service service-nginx.
2.解析
3.答案
创建service,service-nginx.yaml
apiVersion: v1kind: Servicemetadata:name: service-nginxspec:type: NodePortselector:# 先查看nginx pod的标签是否一致run: pod-nginxports:- port: 80targetPort: 80nodePort: 30007
kubectl apply -f service-nginx.yaml
再创建busybox pod,用来查看service以及pod的dns信息
kubectl run busybox --image=busybox --command sleep 1d
执行nslookup命令,先查看pod的dns,通过以下命令获取pod的internal ip
# 查看pod ipkubectl get po pod-nginx -owide# 查看pod dnskubectl exec -ti busybox -- nslookup <pod_ip>
查看service的dns
kubectl exec -ti busybox -- nslookup service-nginx.default
