Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exec commands on kubernetes pods with root access

I have one pod running with name 'jenkins-app-2843651954-4zqdp'. I want to install few softwares temporarily on this pod. How can I do this?

I am trying this- kubectl exec -it jenkins-app-2843651954-4zqdp -- /bin/bash and then running apt-get install commands but since the user I am accessing with doesn't have sudo access I am not able to run commands

like image 851
biz dev Avatar asked Mar 14 '17 18:03

biz dev


People also ask

What is Kubernetes exec command?

The kubectl exec command lets you start a shell session inside containers running in your Kubernetes cluster. This command lets you inspect the container's file system, check the state of the environment, and perform advanced debugging tools when logs alone don't provide enough information.


2 Answers

  • Use kubectl describe pod ... to find the node running your Pod and the container ID (docker://...)
  • SSH into the node
  • run docker exec -it -u root ID /bin/bash
like image 99
Janos Lenart Avatar answered Sep 27 '22 18:09

Janos Lenart


There are some plugins for kubectl that may help you achieve this: https://github.com/jordanwilson230/kubectl-plugins

One of the plugins called, 'ssh', will allow you to exec as root user by running (for example) kubectl ssh -u root -p nginx-0

like image 30
jordanwilson230 Avatar answered Sep 27 '22 17:09

jordanwilson230