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
464
votes
11 answers

kubectl apply vs kubectl create?

What I understood by the documentation is that: kubectl create Creates a new k8s resource in the cluster kubectl replace Updates a resource in the live cluster kubectl apply If I want to do create + replace (Reference) My questions are Why…
Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
282
votes
24 answers

Kubernetes pod gets recreated when deleted

I have started pods with command $ kubectl run busybox \ --image=busybox \ --restart=Never \ --tty \ -i \ --generator=run-pod/v1 Something went wrong, and now I can't delete this Pod. I tried using the methods described below but the Pod keeps…
yman
  • 2,931
  • 2
  • 11
  • 6
235
votes
6 answers

Kubernetes API - Get Pods on Specific Nodes

Reading the Kubernets documentation it looks to be possible to select a certain range of pods based on labels. I want to select all the pods on one node but I don't want to label each pod on their corresponding node. Am I missing something from the…
Fran
  • 3,693
  • 4
  • 19
  • 19
234
votes
4 answers

Kubernetes: How do I delete clusters and contexts from kubectl config?

kubectl config view shows contexts and clusters corresponding to clusters that I have deleted. How can I remove those entries? The command kubectl config unset clusters appears to delete all clusters. Is there a way to selectively delete cluster…
Jeremy Lewi
  • 6,386
  • 6
  • 22
  • 37
232
votes
14 answers

kubectl logs - continuously

kubectl logs gets latest logs from my deployment - I am working on a bug and interested to know the logs at runtime - How can I get continuous stream of logs ? edit: corrected question at the end.
npr
  • 4,325
  • 4
  • 20
  • 30
210
votes
6 answers

How kubectl port-forward works?

kubectl exposes commands that can be used to create a Service for an application and assigns an IP address to access it from internet. As far as I understand, to access any application within Kubernetes cluster there should be a Service resource…
karthikeayan
  • 4,291
  • 7
  • 37
  • 75
201
votes
15 answers

Restart container within pod

I have a pod test-1495806908-xn5jn with 2 containers. I'd like to restart one of them called container-test. Is it possible to restart a single container within a pod and how? If not, how do I restart the pod? The pod was created using a…
s5s
  • 11,159
  • 21
  • 74
  • 121
192
votes
19 answers

Checking Kubernetes pod CPU and memory utilization

I am trying to see how much memory and CPU is utilized by a kubernetes pod. I ran the following command for this: kubectl top pod podname --namespace=default I am getting the following error: W0205 15:14:47.248366 2767 top_pod.go:190] Metrics…
aniztar
  • 2,443
  • 4
  • 18
  • 24
176
votes
9 answers

How can I update a secret on Kubernetes when it is generated from a file?

I've created a secret using kubectl create secret generic production-tls \ --from-file=./tls.key \ --from-file=./tls.crt If I'd like to update the values - how can I do this?
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
165
votes
8 answers

kubectl get events only for a pod

When I run kubectl -n abc-namespace describe pod my-pod-zl6m6, I get a lot of information about the pod along with the Events in the end. Is there a way to output just the Events of the pod either using kubectl describe or kubectl get commands?
Rakesh N
  • 2,450
  • 3
  • 25
  • 32
164
votes
13 answers

Listing all resources in a namespace

I would like to see all resources in a namespace. Doing kubectl get all will, despite of the name, not list things like services and ingresses. If I know the the type I can explicitly ask for that particular type, but it seems there is also no…
michas
  • 25,361
  • 15
  • 76
  • 121
155
votes
7 answers

Kubernetes sort pods by age

I can sort my Kubernetes pods by name using: kubectl get pods --sort-by=.metadata.name How can I sort them (or other resoures) by age using kubectl?
Eugene Platonov
  • 3,145
  • 3
  • 26
  • 20
140
votes
2 answers

Get error "unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend" when switch from v1beta1 to v1 in Kubernetes Ingress

I had the below YAML for my Ingress and it worked (and continues to work): apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: test-ingress namespace: test-layer annotations: nginx.ingress.kubernetes.io/rewrite-target:…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
135
votes
30 answers

did you specify the right host or port? error on Kubernetes

I have followed the helloword tutorial on http://kubernetes.io/docs/hellonode/. When I run: kubectl run hello-node --image=gcr.io/PROJECT_ID/hello-node:v1 --port=8080 I get: The connection to the server localhost:8080 was refused - did you specify…
poiuytrez
  • 21,330
  • 35
  • 113
  • 172
132
votes
8 answers

How to pull environment variables with Helm charts

I have my deployment.yaml file within the templates directory of Helm charts with several environment variables for the container I will be running using Helm. Now I want to be able to pull the environment variables locally from whatever machine the…
uberrebu
  • 3,597
  • 9
  • 38
  • 73
1
2 3
99 100