Category : Kubernetes | Sub Category : Learn Kubernetes | By Prasad Bonam Last updated: 2023-11-22 07:30:58 Viewed : 610
Interacting with a Kubernetes cluster using kubectl
involves various commands to manage resources, inspect the cluster state, and troubleshoot issues. Here is a guide to some common kubectl
commands:
Get Resources:
bashkubectl get pods kubectl get services
bashkubectl get pods <pod-name> -o yaml
Create and Apply:
bashkubectl apply -f my-pod.yaml
Delete Resource:
bashkubectl delete pod <pod-name> kubectl delete -f my-pod.yaml
Cluster Info:
bashkubectl cluster-info
Node Info:
bashkubectl get nodes
Describe:
bashkubectl describe pod <pod-name> kubectl describe node <node-name>
Logs:
bashkubectl logs <pod-name>
Exec into Pod:
bashkubectl exec -it <pod-name> -- /bin/bash
Port Forwarding:
bashkubectl port-forward <pod-name> 8080:80
Deployments:
bashkubectl get deployments kubectl scale deployment <deployment-name> --replicas=3
Rolling Update:
bashkubectl set image deployment/<deployment-name> nginx=nginx:1.17 --record
Services:
bashkubectl get services
Expose Deployment:
bashkubectl expose deployment <deployment-name> --type=NodePort --port=8080
Create and Switch Namespace:
bashkubectl create namespace my-namespace kubectl config set-context --current --namespace=my-namespace
List Resources in Namespace:
bashkubectl get pods --namespace=my-namespace
Events:
bashkubectl get events
Describe Resource for Troubleshooting:
bashkubectl describe pod <pod-name>
Logs and Exec for Troubleshooting:
bashkubectl logs <pod-name>
kubectl exec -it <pod-name> -- /bin/bash
These are just a few examples of the numerous kubectl
commands available. The command-line tool is powerful and flexible, allowing you to manage and interact with your Kubernetes cluster efficiently. You can explore more commands and options in the kubectl documentation.