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

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

问题描述

我有以下问题:-

1:我使用以下命令登录到Kubernetes窗格:-

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地址显示"

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

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 ?

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

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

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

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

This doesnt work. Does someone know what i am doing wrong ?

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

3: 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-<YOUR NAME> --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 <POD ID> -c curl-<YOUR NAME> -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.

编辑:请注意,您需要先从终端登录Google Cloud(一次),然后才能执行此操作!这是一个示例,请确保放入您的区域,群集和项目: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容器中运行curl命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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