kubernetes run command in container code example

Example 1: kubernetes /bin/bash

sudo kubectl -n <namespace> --context=<context-with-access> exec <pod-name> -it /bin/bash

ex:
sudo kubectl -n default --context=staging-devops exec microservice1-jd830k-880 -it /bin/bash

Example 2: kubectl exec ls -lah

kubectl exec <pod_name> -- ls -la /

Example 3: how to login to docker inside kubernetes cluster

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

Tags:

C Example