Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter a pod as root?

Currently I enter the pod as a mysql user using the command:

kubectl exec -it PODNAME -n NAMESPACE bash

I want to enter a container as root. I've tried the following command:

kubectl exec -it PODNAME -n NAMESPACE -u root ID /bin/bash

kubectl exec -it PODNAME -n NAMESPACE -u root ID bash

There must be a way. :-)

like image 250
mac Avatar asked Mar 07 '19 11:03

mac


2 Answers

I found the answer.

You cannot log into the pod directly as root via kubectl.

You can do via the following steps.

1) find out what node it is running on kubectl get po -n [NAMESPACE] -o wide

2) ssh node

3) find the docker container sudo docker ps | grep [namespace]

4) log into container as root sudo docker exec -it -u root [DOCKER ID] /bin/bash

like image 189
mac Avatar answered Sep 25 '22 23:09

mac


Actually there is already a possibility to connect via kubectl addon kubectl-plugins. Found a solution replying onto related question.

git clone https://github.com/jordanwilson230/kubectl-plugins.git
cd kubectl-plugins
./install-plugins.sh
source ~/.bash_profile
kubectl ssh -u root suse

Connecting...
Pod: suse
Namespace: NONE
User: root
Container: NONE
Command: /bin/sh

If you don't see a command prompt, try pressing enter.
sh-5.0#
like image 22
Vit Avatar answered Sep 26 '22 23:09

Vit