Inspecting a container using kubectl

Viewed 7396

Is there a way to inspect a container running in pod directly from the kubernetes command line (using kubectl) to see some details such as running in priveleged mode for instance. something like:

kubectl inspect -c <containerName>

The only way I found is to ssh to the node hosting the pod and perform a docker inspect <containerID> but this is kind of tedious.

My kubernetes version

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0+coreos.0", GitCommit:"6bb2e725fc2876cd94b3900fc57a1c98ca87a08b", GitTreeState:"clean", BuildDate:"2018-04-02T16:49:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
3 Answers

Check kubectl describe pods/<pod_name>

If it is not enough for you, you can go for JSON and filter it with jq

kubectl get <pod_name> -ojson | jq '.spec.containers[] | .securityContext'

Also, check kubectl Cheat Sheet

You have below kubectl commands to know details of a pod

kubectl describe <pod_name> -n <namespacename>
kubectl get <pod_name>  -n <namespacename> -o yaml # output in yaml format  
kubectl get <pod_name> -n <namespacename> -o json # output in json format

If you want to know which containers are running in privileged mode from an audit point of view then I suggest to look at project Falco which has a mechanism to write policies and trigger alert when a container is violating a policy. The policy could be no container can run in privileged mode.

I a similar problem, that I had a pod with status Evicted and needed to inspect it (on kubectl is describe). So i used:

kubectl describe pod <pod-name>

So I could see what I was looking for:

...
Status:         Failed
Reason:         Evicted
Message:        Pod The node had condition: [DiskPressure]. 
...

So searching i found a very nice article talking about 12 Critical Kubernetes Health Conditions You Need to Monitor and Why.

Still on solving, but this log may help others.

Related