Check Limits and requests for a pod with kubectl - kubernetes

can anyone help me with the command to view limits and requests of a pod or containers in a pod? I have tried
Kubectl describe pod ,
kubectl get pod --output=yaml ,
kubectl describe node - shows the current limits but not the configured limits. I want to see the configured limits and requests in the yaml.
Thanks.

-Try following command :
kubectl get pods <podname> -o jsonpath='{range .spec.containers[*]}{"Container Name: "}{.name}{"\n"}{"Requests:"}{.resources.requests}{"\n"}{"Limits:"}{.resources.limits}{"\n"}{end}'
Example:
kubectl get pods frontend -o jsonpath='{range .spec.containers[*]}{"Container Name: "}{.name}{"\n"}{"Requests:"}{.resources.requests}{"\n"}{"Limits:"}{.resources.limits}{"\n"}{end}'
Container Name: app
Requests:{"cpu":"250m","memory":"64Mi"}
Limits:{"cpu":"500m","memory":"128Mi"}
Container Name: log-aggregator
Requests:{"cpu":"250m","memory":"64Mi"}
Limits:{"cpu":"500m","memory":"128Mi"}

Related

Pod is not found when trying to delete, however, can be patched

I have a pod that I can see on GKE. But if I try to delete them, I got the error:
kubectl delete pod my-pod --namespace=kube-system --context=cluster-1
Error from server (NotFound): pods "my-pod" not found
However, if I try to patch it, the operation was completed successfully:
kubectl patch deployment my-pod --namespace kube-system -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"secrets-update\":\"`date +'%s'`\"}}}}}" --context=cluster-1
deployment.apps/my-pod patched
Same namespace, same context, same pod. Why kubectl fails to delete the pod?
kubectl patch deployment my-pod --namespace kube-system -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"secrets-update\":\"`date +'%s'`\"}}}}}" --context=cluster-1
You are patching the deployment here, not the pod.
Additionally, your pod will not be called "my-pod" but would be called the name of your deployment plus a hash (random set of letters and numbers), something like "my-pod-ace3g"
To see the pods in the namespace use
kubectl get pods -n {namespace}
Since you've put the deployment in the "kube-system" namespace, you would use
kubectl get pods -n kube-system
Side note: Generally don't use the kube-system namespace unless your deployment is related to the cluster functionality. There's a namespace called default you can use to test things

What is the command to know the Kubernetes Pod running status?

I am trying to create the containers, when i am trying to build it, it is going into failed state so how can i see the kube pod status in running status and would like to know the root cause of it. Why is it not getting success
Get the logs for the pod
kubectl logs -f <pod_name> -n <namespace>
Get the list of events and other information for the pod
kubectl describe po <pod_name> -n <namespace>

How to debug why my pods are pending in GCE

I'#m trying to get a pod running on GCE. The pod has an init container, and is created by me applying a manifest with a deployment that creates 1 replica of the pod.
When I look at my workloads on the cloud console, I can see that under 'Active revisions' my deployment is in the state of 'Pods are pending', and under 'Managed pods', the status is 'PodsInitializing'.
The container logs are empty, and the audit logs contain a single entry for the creation of the deployment.
My pods seem to be stuck in the above state, and I'm not really sure why. How do I go about debugging that?
Edit:
kubectl get pods --namespace=my-namespace
Outputs:
NAME READY STATUS RESTARTS AGE
my-pod-v77jm 0/1 Init:0/1 0 55m
But when I run:
kubectl describe pod my-pod-v77jm
I get
Error from server (NotFound): pods "my-pod-v77jm" not found
If you have access to kube-api via kubectl:
Use describe see details about the pod and containers
kubectl describe myPod --namespace mynamespace
To view container logs (including init containers)
kubectl logs myPod --namespace mynamespace -c initContainerName
You can get more information about pod statuses and how to debug init containers here

kubectl create doesn't seem to do anything

I am running the command
kubectl create -f mypod.yaml --namespace=mynamespace
as I need to specify the environment variables through a configMap I created and specified in the mypod.yaml file. Kubernetes returns
pod/mypod created
but kubectl get pods doesn't show it in my list of pods and I can't access it by name as if it does not exist. However, if I try to create it again, it says that the pod is already created.
What may cause this, and how would I diagnose the problem?
By default, kubectl commands operate in the default namespace. But you created your pod in the mynamespace namespace.
Try one of the following:
kubectl get pods -n mynamespace
kubectl get pods --all-namespaces

How to find the pod name given a container ID

Is there a way to find the pod name for a given Docker container ID?
I can do it the other way round "kubectl describe pods" but then I have to run it on all the pods.
Yes, you can get the pod name given a container ID using the following kubectl request:
kubectl get pod -o jsonpath='{range .items[?(#.status.containerStatuses[].containerID=="docker://<container_id>")]}{.metadata.name}{end}' -n <namespace>
where <container_id> is the long docker container ID and <namespace> is namespace which we can skip if our pod is in default namespace.
For example:
kubectl get pod -o jsonpath='{range .items[?(#.status.containerStatuses[].containerID=="docker://686bc30be6e870023dcf611f7a7808516e041c892a236e565ba2bd3e0569ff7a")]}{.metadata.name}{end}'
nginx-deployment-569477d6d8-xtf42