What is it?
kubectl is the command-line interface (CLI) tool used to interact with Kubernetes clusters. It allows users to deploy applications, inspect and manage cluster resources, and view logs.
If you have a cluster deployed (locally with Minikube, or remotely with a cloud provider), you can use kubectl to manage it.
About Contexts
In order to manage clusters with kubectl, you need to set up a context.
A context is a set of access parameters that defines which cluster kubectl communicates with, as well as the user credentials and namespace to use. They are defined in the kubeconfig file, and can be configured using the kubectl config command.
TIP
Contexts are useful when you have multiple clusters to manage, as they allow you to switch between them easily.
Configuration
kubectl uses a configuration file, typically located at ~/.kube/config, to store information about contexts, clusters, and users.
To view the current context:
kubectl config current-contextMost likely, you will be using a cloud provider’s managed Kubernetes service, such as Amazon EKS, Google GKE, or Azure AKS. Each provider has its own method for configuring kubectl to connect to the cluster.
# For EKS
aws eks update-kubeconfig --name <cluster-name> --region <region>
# For GKE
gcloud container clusters get-credentials <cluster-name> --location <zone>
# For AKS
az aks get-credentials --name <cluster-name> --resource-group <resource-group>If you are running a local cluster with Minikube, you can set up kubectl with:
kubectl config use-context minikubeOnce configured, you can verify the connection by listing the nodes in the cluster:
kubectl get nodes