- Utility to configure and operate Kubernetes
- kubectl can point to multiple clusters
How kubectl connects to a cluster
- Kubectl connects to cluster using config file
- Location of config file (in order of precendence)
- Config file is located under location “C:\Users\Tyson\.kube\config”
- kubectl config –kubeconfig=”C:\folder\file”
- KUBECONIFG — Environment variable sets the path
- Config file has three parts
- clusters (and https endpoint)
- Cluster has information about the server details
- certificate-authority-data for that Cluster
- users
- User has list of users who can connect to any cluster
- contexts
- Context Combines User and Clusters, letting us know which user can connect to which cluster
- clusters (and https endpoint)
Commands
- kubectl config current-context
- To find the current context
- kubectl config get-contexts
- List all the context
- kubectl config use-context <context-name>
Kubectl get commands
- kubectl get pods
- kubectl get deployments
- kubectl get services
- kubectl get configmaps
- kubectl get secrets
- kubectl get ingress
Namespace
- Normally resources are scoped to a namespace
- Namespaces are like project groups or a resource group
- Allows resources to be separated from one another
- By default all the commands run against be default namespace
- You can query to a specific name space by passing an argument -n <namespace>
Command
- kubectl get namespaces
- List all the namespaces
- kubectl create namespace <new-namespace-name>
- To create a new namespace
- kubectl get pods -n <namespace-name>
- List all the pods in a namespace
Describe Command (Troubleshooting command)
- kubectl describe <resource> <name>
Example :
- Lets take an example of a system namespace that bydefault comes with K8
- And then describe it to see its details
Command
- kubectl get namespace
- kubectl get pods -n kube-system
- kubectl describe pod coredns-565d847f94-fpvkp -n kube-system
Important labels to look for
- Event section usually shows an error description if the pod is in a crashback look
Reference :