How will go inside the pod as a root?

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version:
Cloud being used: (put bare-metal if not on a public cloud)
Installation method:
Host OS:
CNI and version:
CRI and version:

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

By default when you execute the following command, you get root privileges.
kubectl exec -it [pod name] bin/bash

thanks for the reply,but this command help only go to the container after that will did any changes it wont work.

What are you trying to accomplish?

Pods are composed of one or more containers; as such, you have the ability to gain access within a container using the kubectl exec -it [pod] (-c [container]) (-n [namespace]) bin/bash

If you’re trying to gain access to the node instead, use ssh followed by the username@node_host

For me it helped like this:
k exec -it dnstest – sh
k exec -it shell-demo – /bin/bash

nc -z -v -w 2 nginx-resolver-service 80

1 Like

After i had run the proper command of course:
k run --generator=run-pod/v1 dnspod --image=busybox:1.28 --command sleep 1h

k exec -it dnstest – nc -z -v -w 2 nginx-resolver-service 80 > ourfile
or
k exec -it dnstest – nc -z -v -w 2 10-44-0-4.default.pod 80 > ourfile

Hi ,

I tried below commands still not able to login as a root user id , please suggest!!
kubectl exec -it [pod name] (-c [container name]) (-n [namespace]) bin/bash
kubectl exec -it [pod name] (-c [container name]) (-n [namespace]) bin/sh
kubectl exec -it [pod name] (-c [container name]) (-n [namespace]) – sh

HEMAN.MALVE@BLRKEC397481L MINGW64 /d/HEMAN.MALVE/Database/Projects/P&G
$ ./kubectl -n kong-postgres-new exec -it ingress-kong-5f54bf5c8-r9zgk -c proxy bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] – [COMMAND] instead.
Unable to use a TTY - input is not a terminal or the right kind of file
whoami
kong
id kong
uid=100(kong) gid=65533(nogroup) groups=65533(nogroup),65533(nogroup)
id root
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
exit

HEMAN.MALVE@BLRKEC397481L MINGW64 /d/HEMAN.MALVE/Database/Projects/P&G
$ ./kubectl -n kong-postgres-new exec -it ingress-kong-5f54bf5c8-r9zgk -c proxy bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] – [COMMAND] instead.
Unable to use a TTY - input is not a terminal or the right kind of file
whoami
kong
id root
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

The short answer is you can’t. Containers which run as non-root should not be able to escalate to root.

Hi,

just curious to know,

  1. how did you say/what basis this container not able to leverage /escalate to root id ?
  2. Can it be possible to apply sudo/su/dzdo rule in deployment kind or any other possibilities?

my requirement is , mounting one file using configmap at /tmp location with volumemounts,volumes which is creating root:root (644) permissions as login into container by default its taking kong account id
referring to this link (amazon web services - Kubernetes: how to set VolumeMount user group and file permissions - Stack Overflow), does it will be achievable with securityContext?

please share your insights here…