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

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

找到您的参考链接:https://github.com/dgkanatsios/CKAD-exercises/blob/main/a.core_concepts.md#get-nginx-pods-ip-created-in-previous-step-use-a-temp-busybox-image-to-wget-its-

现在我的问题是,当我运行这个命令时它可以工作:

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 '10.1.1.131'
# create a temp busybox pod
kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- 10.1.1.131:80

回答1

您必须首先创建一个 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 10.42.0.52:80 (10.42.0.52:80)
writing to stdout
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<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>
</body>
</html>
-                    100% |********************************|   615  0:00:00 ETA
written to stdout
pod "busybox" deleted

相似文章

随机推荐

最新文章