Common Kubernetes Commands
Overview
kubectl is a command line tool for interacting with the Kubernetes Control Plane, which manages infrastructure deployment into Kubernetes. This document lists several common kubectl commands that can be run on the Kubernetes cluster that runs the Kinetic Data platform.
Generic kubectl Commands
The following section includes a non-comprehensive list of generic kubectl commands often used when interacting with the Kubernetes cluster. These commands aren’t specific to Kinetic Data, but we often use them.
Server (Node) Commands
Nodes can be virtual or physical machines, depending on the cluster type. Kubernetes schedules pods to run on these nodes. We’ll discuss Pods more later in this document.
- Get nodes: Gets all the nodes (servers) that comprise the Kubernetes cluster.
kubectl get nodes
- Cordon a node: This stops Kubernetes from scheduling future pods on the cordoned node. This is typically used when doing underlying server changes.
kubectl cordon <NODE>
- Uncordon a node: This allows Kubernetes to schedule future pods on the node. This is typically used after doing underlying server changes.
kubectl uncordon <NODE>
- Drain a node: This will tell Kubernetes to evict all pods not part of daemonsets from the node. Barring resource and affinity constraints, Kubernetes will attempt to put the pods onto one of the other nodes in the cluster.
kubectl drain <NODE> --ignore-daemonsets --delete-empty-dir
Deployment Commands
Deployments and their flavors manage pod collections that run workloads on Kubernetes nodes.
- Get deployments: Get all deployments deployed in a given namespace.
kubectl get deployments -n <NAMESPACE>
- Deployment details: Describe a deployment.
kubectl describe deployment <NAME> -n <NAMESPACE>
- Restart deployment: Perform a rolling restart of a deployment in a namespace.
kubectl rollout restart deployment <NAME> -n <NAMESPACE>
- Deployment restart status: Get the status of an active rolling restart of a deployment.
kubectl rollout status deployment <NAME> -n <NAMESPACE>
- Scale deployment: Scale the number of pods to COUNT in a deployment. This is not applicable for daemon sets.
kubectl scale deployment <NAME> -n <NAMESPACE> --replicas=<COUNT>
Pod Commands
Pods are the smallest deployable units that can be created in Kubernetes. They are typically not deployed directly; instead, they are usually deployed via workload resources such as Deployments.
A pod can comprise one or more containers, which are software packages built as images run within a pod.
- Get all pods: Returns all pods in a given namespace.
kubectl get pods -n <NAMESPACE>
- Pod details: Get information on a pod, such as volumes mounted on the pod.
kubectl describe pod <POD> -n <NAMESPACE>
- Delete a pod: Deletes the pod. If the pod is part of a deployment, Kubernetes will attempt to replace the pod.
kubectl delete pod <POD> -n <NAMESPACE>
- View log files: Follow the container logs within a pod.
-kubectl logs <POD> -n <NAMESPACE> -c <CONTAINER>
- Shelling into a container: Shell into a container within a pod (if the container has a shell available). The first example is for a shell; the second is for a bash.
or
kubectl exec -it <POD> -n <NAMESPACE> -c <CONTAINER> -- sh
kubectl exec -it <POD> -n <NAMESPACE> -c <CONTAINER> -- bash
- Run commands in a container: Execute a command within a container located within a pod. The example below shows running the "whoami" command.
kubectl exec -it <POD> -n <NAMESPACE> -c <CONTAINER> -- whoami
- Copy container files: Copy files from a container within a pod to local machine.
kubectl cp -n <NAMESPACE> -c <CONTAINER> <POD>:\<PATH_ON_POD> \<PATH_LOCALLY>
Additional Resources
You can find more information on the various Kubernetes components that work with the Kinetic Platform here:
Updated 4 months ago