Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

docker - How do I run curl command from within a Kubernetes pod

I have the following questions:

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

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

    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?

  2. 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?

  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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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

EDIT: 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...