kubernetes - Kubernetes CKAD 准备问题:暴露端口不工作

这就是我想要做的:获取在上一步中创建的 nginx pod 的 ip,使用临时的 busybox 图像来获取它的 '/'



kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- $(kubectl get pod nginx -o jsonpath='{.status.podIP}:{.spec.containers[0].ports[0].containerPort}')


kubectl get po -o wide # get the IP, will be something like ''
# create a temp busybox pod
kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O-


您必须首先创建一个 Nginx pod。这就是所谓的“上一步”。

$ kubectl run nginx --image=nginx --restart=Never --port=80

pod/nginx created

然后,您可以在 BusyBox pod 中运行 wget:

$  kubectl run BusyBox --image=busybox --rm -it --restart=Never -- wget -O- $(kubectl get pod nginx -o jsonpath='{.status.podIP}:{.spec.containers[0].ports[0].containerPort}')

Connecting to (
writing to stdout
<!DOCTYPE html>
<title>Welcome to nginx!</title>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
-                    100% |********************************|   615  0:00:00 ETA
written to stdout
pod "busybox" deleted