Questions tagged [kubectl]

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.

3648 questions
28
votes
3 answers

How do I extract multiple values from kubectl with jsonpath

I've found jsonpath examples for testing multiple values but not extracting multiple values. I want to get image and name from kubectl get pods. this gets me name kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].name}' | xargs -n…
navicore
  • 1,979
  • 4
  • 34
  • 50
28
votes
4 answers

Get the image and SHA image ID of images in pod on Kubernetes deployment

How can I get the image ID (the docker sha256 hash) of a image / container within a Kubernetes deployment?
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
27
votes
5 answers

kubectl: describe vs get -o

In kubectl, both describe and get -o can be used to get the details of a resource, I'm wondering what's the difference between the two? why does describe even exist if get can do the same thing and more?
Dagang
  • 24,586
  • 26
  • 88
  • 133
27
votes
2 answers

Need some explaination of kubectl stdin and pipe

I'm daily user of kubectl, but not expert of linux. Recently I need edit some service type after deployment, so searched and used kubectl replace and it worked well. cat yaml | kubectl replace -f - service/tracs-pool-1sv replaced But I don't…
Lei Yang
  • 3,970
  • 6
  • 38
  • 59
26
votes
3 answers

Kubectl rollout restart for statefulset

As per the kubectl docs, kubectl rollout restart is applicable for deployments, daemonsets and statefulsets. It works as expected for deployments. But for statefulsets, it restarts only one pod of the 2 pods. ✗ k rollout restart statefulset…
livinston
  • 1,218
  • 2
  • 12
  • 18
26
votes
6 answers

Kubernetes: Display Pods by age in ascending order

I use below command to sort the pods by age kubectl get pods --sort-by={metadata.creationTimestamp} It shows up pods in descending order. How can we select sorting order like ascending?
P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
26
votes
2 answers

How do I check if a Kubernetes pod was killed for OOM or DEADLINE EXCEEDED?

I have some previously run pods that I think were killed by Kubernetes for OOM or DEADLINE EXCEEDED, what's the most reliable way to confirm that? Especially if the pods weren't recent.
nickponline
  • 25,354
  • 32
  • 99
  • 167
26
votes
3 answers

How do I save kubectl logs to a file on my host machine?

I can see the logs for a particular pod by running 'kubectl logs podName'. I have also seen that logs contains an option --log-dir flag, but it doesn't seem to be working. Is there some kind of configuration I can change, logs will be saved to a…
mbhatia4336
  • 271
  • 1
  • 3
  • 6
25
votes
3 answers

kubectl run --command vs -- arguments

I was a little confused with below command: kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'echo hello;sleep 3600' YAML: apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: busybox …
Amit Thakkar
  • 687
  • 1
  • 5
  • 14
25
votes
5 answers

kubectl - list all port forwards across all services?

I'm new to kubernetes and am wondering if there's a way for me to see a list of all currently configured port forwards using kubectl ? I see there's a kubectl port-forward command, but it doesn't seem to list them, just set one up.
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
25
votes
1 answer

Kubernetes share a directory from your local system to kubernetes container

Is there any way to share the directory/files to kubernetes container from your local system? I have a deployment yaml file. I want to share the directory without using kubectl cp. I tried with configmap but I later came to know that configmap can…
Akshay Sood
  • 6,366
  • 10
  • 36
  • 59
25
votes
2 answers

How to save content of a configmap to a file with kubectl and jsonpath?

I'm trying to save the contents of a configmap to a file on my local hard drive. Kubectl supports selecting with JSONPath but I can't find the expression I need to select just the file contents. The configmap was created using the command kubectl…
PeterH
  • 801
  • 2
  • 7
  • 16
24
votes
5 answers

Kubectl : No resource found

I’ve installed ICP4Data successfully. I am pretty green in respect to ICP4Data and Kubernetes. I’m trying to use kubectl command for listing the pods in ICP4D but “kubectl get pods” returns “No resource found”. Am I missing something?
sidrah junaid
  • 437
  • 1
  • 4
  • 11
24
votes
4 answers

How to make two Kubernetes Services talk to each other?

Currently, I have working K8s API pods in a K8s service that connects to a K8s Redis service, with K8s pods of it's own. The problem is, I am using NodePort meaning BOTH are exposed to the public. I only want the API accessable to the public. The…
Will Parzybok
  • 2,764
  • 4
  • 12
  • 18
24
votes
2 answers

Kubernetes version installed by minikube

How to know the kubernetes version that is installed by minikube? I am aware of the kubectl version and the minikube version.
NSP
  • 1,193
  • 4
  • 15
  • 26