Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute command into Kubernetes pod as other user

Docker allows execution of commands as other user with docker exec -u, when USER something in used in Dockerfile. It is helpful to enter into superuser mode to debug issues, when you are running you CMD as system user in Dockerfile.

How to execute commands on Kubernetes as other user?

My kubectl version output is

Client Version: version.Info{Major:"1", Minor:"0", GitVersion:"v1.0.6", GitCommit:"388061f00f0d9e4d641f9ed4971c775e1654579d", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"0", GitVersion:"v1.0.6", GitCommit:"388061f00f0d9e4d641f9ed4971c775e1654579d", GitTreeState:"clean"}
like image 312
Sunil Kumar Avatar asked Oct 23 '15 01:10

Sunil Kumar


2 Answers

You can check the spec schema to see what you can add in a pod or replication controller or whatever: https://cloud.google.com/container-engine/docs/spec-schema

You have runAsUser for what you want:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    securityContext:
      runAsUser: 41
like image 62
cristi Avatar answered Oct 31 '22 02:10

cristi


This is not currently supported, but there is an open feature request for it: https://github.com/kubernetes/kubernetes/issues/30656

like image 23
Matt Zimmerman Avatar answered Oct 31 '22 03:10

Matt Zimmerman