About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

Create a temporary pod that uses the busybox image to execute a wget command inside of the container.

Q:-

Create a temporary pod that uses the busybox image to execute a wget command inside of the container.

The Wget command should access the endpoint exposed by the nginx container.

You should see the HTML response body rendered in the terminal.

 Ans:- 

kubectl config get-contexts

 kubectl config delete-context 

Get  a context 

az aks get-credentials --resource-group myresourcegroup --name myakscluster

C:\Users\kusha>kubectl config set-context myakscluster --namespace=chap1

Context "myakscluster" modified.


C:\Users\kusha>kubectl config get-contexts

CURRENT   NAME           CLUSTER        AUTHINFO                                   NAMESPACE

*         myakscluster   myakscluster   clusterUser_myresourcegroup_myakscluster   chap1

First Create a pod named nginx

     kubectl run nginx --image=nginx  --port=80 

      kubectl get pod -o wide # get the IP, will be something like '10.5.240.18'


create a temp busybox pod

kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- 10.5.240.18:80


Alternatively, you can also try a more advanced option:


Get IP of the nginx pod

NGINX_IP=$(kubectl get pod nginx -o jsonpath='{.status.podIP}')


create a temp busybox pod

kubectl run busybox --image=busybox --env="NGINX_IP=$NGINX_IP" --rm -it --restart=Never -- sh -c 'wget -O- $NGINX_IP:80'


Or just in one line:


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 delete ns chap2

No comments: