Manage Pods
In Kubernetes we can have clusters, if we run these commands they will target the default cluster. For more info about clusters you can look at cluster section
kubectl get pods -A # all namespaces
kubectl get pods -n <namespace> # find the pods by their namespace, e.g. it can be smart-novel
kubectl get pods -A -o wide # with node and IP
kubectl get pods -A -w # watch for changes
Cluster
A Kubernetes cluster is a set of machines/nodes that run your containerized workloads, managed as one unit. It has two parts:
- Control plane: the API server, scheduler, and etcd. It stores the desired state and decides which pod runs where.
- Worker nodes: the machines that run the pods, each with a kubelet and a container runtime.
You describe what you want (deployments, services), and the cluster keeps reality matching it.
kind ("Kubernetes IN Docker") creates a real cluster on your machine in which each node is a Docker container instead of a VM or physical server.
kind get clusters # Lists clusters
kubectl config get-contexts # Return the current cluster which receive your kubectl commands
kubectl config use-context kind-<cluster-name> # Select the desired cluster
Note
The cluster name comes from
kind get clusters.
And in case you do not wanna change your context:
kubectl --context kind-<cluster-name> get pods -A
Important
kubectlreads contexts from~/.kube/config, and if you haveminikubecontext it will be there too. But e.g. in smart-novel when you have a Terraform which start the app and project's start script writes the kind cluster'skubeconfigto its own file, so thekind-smart-novelcontext never reached your default config.kind get clustersstill lists the cluster becausekindfinds clusters through Docker, not throughkubeconfig.The fix is to point
kubectlat that file with--kubeconfig infra/terraform/envs/local/smart-novel-configorexport KUBECONFIG=.... Thekind-prefix added to the EKS context name was a separate mistake, since only kind-created contexts have it:kubectl --kubeconfig infra/terraform/envs/local/smart-novel-config get pods -A
Look at the Logs
export KUBECONFIG=infra/terraform/envs/local/smart-novel-config # you can have this if you have a kind cluster
kubectl logs <pod> -n <namespace> # print logs of a
kubectl logs -f <pod> -n <namespace> # follow (stream)
kubectl logs --tail=100 <pod> -n <namespace> # last 100 lines
kubectl logs --since=10m <pod> -n <namespace> # last 10 minutes
kubectl logs -p <pod> -n <namespace> # previous container (after a crash)
kubectl logs <pod> -c <container> -n <namespace> # specific container in a multi-container pod
Important
If you have a namespace you must pass it.
- Ponos-OS: https://github.com/Ponos-OS
- My portfolio: https://kasir-barati.github.io
Top comments (1)
This is really useful for someone learning Kubernetes. I like that you explain what a cluster is and not just the commands. Saving this one!