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
128
votes
7 answers

Disabling cronjob in Kubernetes

I have scheduled an application to run as a CronJob in Kubernetes. When there is a code change, I'm also changing the image of the CronJob. I'm looking for an option where I can disable the currently running CronJob and deploy a new CronJob with the…
117
votes
5 answers

Tailing few lines from huge logs of kubectl logs -f

kubectl logs -f pod shows all logs from the beginning and it becomes a problem when the log is huge and we have to wait for a few minutes to get the last log. Its become more worst when connecting remotely. Is there a way that we can tail the logs…
Tinkaal Gogoi
  • 4,344
  • 4
  • 27
  • 36
115
votes
7 answers

Tell when Job is Complete

I'm looking for a way to tell (from within a script) when a Kubernetes Job has completed. I want to then get the logs out of the containers and perform cleanup. What would be a good way to do this? Would the best way be to run kubectl describe job…
russt
  • 1,548
  • 2
  • 14
  • 16
106
votes
3 answers

What is command to find detailed information about Kubernetes master(s) using kubectl?

Let say I want to find the kubelet and apiserver version of my k8s master(s), what's the best way to do it? I am aware of the following commands: kubectl cluster-info which only shows the endpoints. kubectl get nodes; kubectl describe node…
Kenny Ho
  • 3,247
  • 5
  • 19
  • 24
100
votes
4 answers

Execute bash command in pod with kubectl?

My question is simple. How to execute a bash command in the pod? I want to do everything with a single bash command. [root@master ~]# kubectl exec -it --namespace="tools" mongo-pod --bash -c "mongo" Error: unknown flag: --bash So, the command is…
JDev
  • 2,157
  • 3
  • 31
  • 57
88
votes
11 answers

How to configure kubectl with cluster information from a .conf file?

I have an admin.conf file containing info about a cluster, so that the following command works fine: kubectl --kubeconfig ./admin.conf get nodes How can I config kubectl to use the cluster, user and authentication from this file as default in one…
Assen Kolov
  • 4,143
  • 2
  • 22
  • 32
85
votes
15 answers

kubectl unable to connect to server: x509: certificate signed by unknown authority

i'm getting an error when running kubectl one one machine (windows) the k8s cluster is running on CentOs 7 kubernetes cluster 1.7 master, worker Here's my .kube\config apiVersion: v1 clusters: - cluster: certificate-authority-data: REDACTED …
bherto39
  • 1,516
  • 3
  • 14
  • 29
81
votes
8 answers

how to check whether RBAC is enabled, using kubectl

I'm trying to install a helm package on a kubernetes cluster which allegedly has RBAC disabled. I'm getting a permission error mentioning clusterroles.rbac.authorization.k8s.io, which is what I'd expect if RBAC was enabled. Is there a way to check…
falsePockets
  • 3,826
  • 4
  • 18
  • 37
80
votes
1 answer

What's the meaning of "READY=2/2" output by command "kubectl get pod $yourpod"

kubectl get pod run-sh-1816639685-xejyk NAME READY STATUS RESTARTS AGE run-sh-1816639685-xejyk 2/2 Running 0 26m What's the meaning of "READY=2/2"? The same with "1/1"?
workhardcc
  • 1,270
  • 3
  • 12
  • 21
78
votes
15 answers

Get current image of kubernetes deployment

How can I use kubectl or the API to retrieve the current image for containers in a pod or deployment? For example, in a deployment created with the below configuration, I want to retrieve the value eu.gcr.io/test0/brain:latest. apiVersion: v1 …
Andy Hume
  • 40,474
  • 10
  • 47
  • 58
76
votes
5 answers

What kubectl command can I use to get events sorted by specific fields and print only specific details of events?

I need to print only specific fields of Kubernetes Events, sorted by a specific field. This is to help me gather telemetry and analytics about my namespace How could I do that?
suryakrupa
  • 3,852
  • 1
  • 25
  • 34
76
votes
3 answers

How to Add Users to Kubernetes (kubectl)?

I've created a Kubernetes cluster on AWS with kops and can successfully administer it via kubectl from my local machine. I can view the current config with kubectl config view as well as directly access the stored state at ~/.kube/config, such…
peterl
  • 1,881
  • 4
  • 21
  • 34
75
votes
4 answers

kubectl how to list all contexts

How do I view all the contexts I have set up with kubectl? It doesn't appear there's a resource known to kubectl as 'contexts' $ kubectl get contexts error: the server doesn't have a resource type "contexts"
arshbot
  • 12,535
  • 14
  • 48
  • 71
73
votes
18 answers

Kubernetes create deployment unexpected SchemaError

I'm following that tutorial (https://www.baeldung.com/spring-boot-minikube) I want to create Kubernetes deployment in yaml file (simple-crud-dpl.yaml): apiVersion: apps/v1 kind: Deployment metadata: name: simple-crud spec: selector: …
Arkadiusz Migała
  • 927
  • 1
  • 8
  • 14
73
votes
2 answers

Kubernetes / kubectl - "A container name must be specified" but seems like it is?

I'm debugging log output from kubectl that states: Error from server (BadRequest): a container name must be specified for pod postgres-operator-49202276-bjtf4, choose one of: [apiserver postgres-operator] OK, so that's an explanatory error message,…
IAspireToBeGladOS
  • 1,434
  • 3
  • 19
  • 34