Kubectl Basics
kubectl is the command‑line tool used to interact with your Kubernetes cluster. It’s how you deploy applications, inspect resources, and troubleshoot issues. Mastering basic kubectl commands is essential.Checking kubectl Installation
Minikube automatically installs
kubectl. Verify it’s available:kubectl version --clientCommon kubectl Commands
- Get resources:
kubectl get nodes,kubectl get pods,kubectl get deployments. - Describe details:
kubectl describe pod pod-nameshows detailed status. - Create resources:
kubectl create -f file.yamlorkubectl apply -f file.yaml. - Delete resources:
kubectl delete pod pod-nameorkubectl delete -f file.yaml. - View logs:
kubectl logs pod-name. - Run a command in a pod:
kubectl exec -it pod-name -- /bin/sh.
Example: Running a Simple Pod
Create a pod with an Nginx container:
kubectl run nginx --image=nginx --restart=NeverCheck the pod status:kubectl get podsGet details:kubectl describe pod nginxDelete the pod:kubectl delete pod nginxUsing YAML Files
Most Kubernetes resources are defined in YAML files. For example, save this as
nginx-pod.yaml:apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginxThen apply it:kubectl apply -f nginx-pod.yamlTwo Minute Drill
kubectl get– list resources.kubectl describe– show detailed info.kubectl apply -f file.yaml– create/update resources from YAML.kubectl delete– remove resources.kubectl logs– view container logs.
Need more clarification?
Drop us an email at career@quipoinfotech.com
