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:
Post a Comment