About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

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: