Sunil Kumar
Sunil Kumar

Reputation: 1711

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"}

Upvotes: 6

Views: 12602

Answers (2)

Matt Zimmerman
Matt Zimmerman

Reputation: 558

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

Upvotes: 1

cristi
cristi

Reputation: 2199

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

Upvotes: 7

Related Questions