[Sticky] Kubernetes top 50 kubectl commands
-
Get Cluster Information:
bashkubectl cluster-info
-
Get Nodes:
bashkubectl get nodes
-
Get Pods:
bashkubectl get pods
-
Get Services:
bashkubectl get services
-
Get Deployments:
bashkubectl get deployments
-
Get Configurations:
bashkubectl get configmaps
-
Get Namespaces:
bashkubectl get namespaces
-
Describe Pod:
bashkubectl describe pod <pod_name>
-
Expose a Service:
bashkubectl expose deployment <deployment_name> --type=LoadBalancer --port=80 --target-port=8080
-
Scale a Deployment:
bashkubectl scale deployment <deployment_name> --replicas=3
-
Delete a Pod:
bashkubectl delete pod <pod_name>
-
Delete a Service:
bashkubectl delete service <service_name>
-
Delete a Deployment:
bashkubectl delete deployment <deployment_name>
-
Pod Logs:
bashkubectl logs <pod_name>
-
Exec into a Pod:
bashkubectl exec -it <pod_name> -- /bin/bash
-
Port Forwarding:
bashkubectl port-forward <pod_name> 8080:80
-
Apply Configuration:
bashkubectl apply -f <file.yaml>
-
Get Persistent Volumes:
bashkubectl get pv
-
Get Persistent Volume Claims:
bashkubectl get pvc
-
Create a Namespace:
bashkubectl create namespace <namespace_name>
-
Delete a Namespace:
bashkubectl delete namespace <namespace_name>
-
Get All Resources in a Namespace:
bashkubectl get all -n <namespace_name>
-
Get ReplicaSets:
bashkubectl get replicasets
-
Get Ingress Resources:
bashkubectl get ingresses
-
Describe a Persistent Volume:
bashkubectl describe pv <pv_name>
-
Describe a Persistent Volume Claim:
bashkubectl describe pvc <pvc_name>
-
Get Resource Utilization (CPU, Memory):
bashkubectl top pods
-
Get API Resources:
bashkubectl api-resources
-
Create a Secret:
bashkubectl create secret generic <secret_name> --from-literal=key1=value1 --from-literal=key2=value2
-
Get Secrets:
bashkubectl get secrets
-
Create a ConfigMap:
bashkubectl create configmap <configmap_name> --from-literal=key1=value1 --from-literal=key2=value2
-
Rolling Restart of Deployments:
bashkubectl rollout restart deployment <deployment_name>
-
Label a Resource:
bashkubectl label pod <pod_name> env=production
-
Get Events:
bashkubectl get events
-
Create a Horizontal Pod Autoscaler:
bashkubectl autoscale deployment <deployment_name> --cpu-percent=50 --min=1 --max=10
-
Get Horizontal Pod Autoscalers:
bashkubectl get hpa
-
Get Storage Classes:
bashkubectl get storageclasses
-
Get Roles and RoleBindings:
bashkubectl get roles
kubectl get rolebindings
-
Get ClusterRoles and ClusterRoleBindings:
bashkubectl get clusterroles
kubectl get clusterrolebindings
-
Get StatefulSets:
bashkubectl get statefulsets
-
Create a Service Account:
bashkubectl create serviceaccount <serviceaccount_name>
-
Get Service Accounts:
bashkubectl get serviceaccounts
-
Resource Quotas:
bashkubectl create quota <quota_name> --hard=cpu=1,memory=1G,pods=2,replicationcontrollers=2,services=2
-
Attach to Persistent Volume:
bashkubectl attach -i <pod_name> -c <container_name> -it /bin/bash
-
Apply Resources from a Directory:
bashkubectl apply -f <directory>
-
Get Endpoints:
bashkubectl get endpoints
-
Network Policies:
bashkubectl get networkpolicies
-
Drain Node (for Maintenance):
bashkubectl drain <node_name> --ignore-daemonsets --delete-local-data
-
Uncordon Node:
bashkubectl uncordon <node_name>
-
Get All Resources Across All Namespaces:
bashkubectl get all --all-namespaces
These commands cover a range of Kubernetes management tasks. Adjust them based on your specific use case and requirements.