如何从 Kubernetes pod 中运行 curl 命令 [英] How do I run curl command from within a Kubernetes pod

查看:285
本文介绍了如何从 Kubernetes pod 中运行 curl 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

  1. 我使用以下命令登录到 Kubernetes pod:

  1. I am logged into a Kubernetes pod using the following command:

 ./cluster/kubectl.sh exec my-nginx-0onux -c my-nginx -it bash

'ip addr show' 命令显示其分配的 pod 的 ip.由于 pod 是一个逻辑概念,我假设我登录的是 docker 容器而不是 pod,在这种情况下,pod IP 与 docker 容器 IP 相同.这种理解正确吗?

The 'ip addr show' command shows its assigned the ip of the pod. Since pod is a logical concept, I am assuming I am logged into a docker container and not a pod, In which case, the pod IP is same as docker container IP. Is that understanding correct?

从 Kubernetes 节点,我执行 sudo docker ps 然后执行以下操作:-

from a Kubernetes node, I do sudo docker ps and then do the following:-

 sudo docker exec  71721cb14283 -it '/bin/bash'

这不起作用.有人知道我做错了什么吗?

This doesn't work. Does someone know what I am doing wrong?

我想使用 curl 从 pod 中访问我创建的 nginx 服务.如何在此 pod 或容器中安装 curl 以从内部访问服务.我想这样做是为了了解网络连接.

I want to access the nginx service I created, from within the pod using curl. How can I install curl within this pod or container to access the service from inside. I want to do this to understand the network connectivity.

推荐答案

以下是您如何在 Kubernetes 网络中使用 curl 命令行来测试和探索您的内部 REST 端点.

Here is how you get a curl command line within a kubernetes network to test and explore your internal REST endpoints.

要获得网络内部正在运行的 busybox 的提示,请执行以下命令.(提示是为每个开发者使用一个独特的容器.)

To get a prompt of a busybox running inside the network, execute the following command. (A tip is to use one unique container per developer.)

kubectl run curl-<你的名字>--image=radial/busyboxplus:curl -i --tty --rm

您可以省略 --rm 并保持实例运行以备后用.要稍后重用,请键入:

You may omit the --rm and keep the instance running for later re-usage. To reuse it later, type:

kubectl attach -c curl-<你的名字>-i -t

使用命令 kubectl get pods 你可以看到所有正在运行的 POD.类似于 curl-yourname-944940652-fvj28.

Using the command kubectl get pods you can see all running POD's. The is something similar to curl-yourname-944940652-fvj28.

请注意,您需要先从终端登录谷歌云(一次),然后才能执行此操作!这是一个示例,请确保放入您的区域、集群和项目:gcloud container clusters get-credentials example-cluster --zone europe-west1-c --project example-148812

Note that you need to login to google cloud from your terminal (once) before you can do this! Here is an example, make sure to put in your zone, cluster and project: gcloud container clusters get-credentials example-cluster --zone europe-west1-c --project example-148812

这篇关于如何从 Kubernetes pod 中运行 curl 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆