Kubernetes

Cluster Information

Display information about the Kubernetes cluster.

$ kubectl cluster-info

List all nodes in the cluster.

$ kubectl get nodes

List all pods in all namespaces.

$ kubectl get pods --all-namespaces

List all services in all namespaces.

$ kubectl get services --all-namespaces

List all deployments in all namespaces.

$ kubectl get deployments --all-namespaces

List all configmaps in all namespaces.

$ kubectl get configmaps --all-namespaces

List all secrets in all namespaces.

$ kubectl get secrets --all-namespaces

List all namespaces in the cluster.

$ kubectl get namespaces

Pod Management

List all pods in the current namespace.

$ kubectl get pods

Display detailed information about a pod.

$ kubectl describe pod <pod_name>

Display the logs of a pod.

$ kubectl logs <pod_name>

Open an interactive shell inside a pod.

$ kubectl exec -it <pod_name> -- /bin/bash

Forward a local port to a port on the pod.

$ kubectl port-forward <pod_name> <local_port>:<pod_port>

Delete a pod.

$ kubectl delete pod <pod_name>

Scale the number of replicas in a deployment.

$ kubectl scale deployment <deployment_name> --replicas=<replica_count>

Restart a deployment.

$ kubectl rollout restart deployment <deployment_name>

Service Management

List all services in the current namespace.

$ kubectl get services

Display detailed information about a service.

$ kubectl describe service <service_name>

Expose a deployment as a service on a specific port.

$ kubectl expose deployment <deployment_name> --type=NodePort --port=<port>

Delete a service.

$ kubectl delete service <service_name>

Configuration and Secrets

List all configmaps in the current namespace.

$ kubectl get configmaps

Display detailed information about a configmap.

$ kubectl describe configmap <configmap_name>

List all secrets in the current namespace.

$ kubectl get secrets

Display detailed information about a secret.

$ kubectl describe secret <secret_name>

Namespace Management

List all namespaces in the cluster.

$ kubectl get namespaces

Create a new namespace.

$ kubectl create namespace <namespace_name>

Delete a namespace and all its resources.

$ kubectl delete namespace <namespace_name>

Deployment and Rollout

List all deployments in the current namespace.

$ kubectl get deployments

Display detailed information about a deployment.

$ kubectl describe deployment <deployment_name>

Scale the number of replicas in a deployment.

$ kubectl scale deployment <deployment_name> --replicas=<replica_count>

Check the status of a deployment rollout.

$ kubectl rollout status deployment <deployment_name>

Show the rollout history of a deployment.

$ kubectl rollout history deployment <deployment_name>

Ingress and Networking

List all ingresses in the current namespace.

$ kubectl get ingresses

Display detailed information about an ingress.

$ kubectl describe ingress <ingress_name>

Apply an Ingress resource defined in a YAML file.

$ kubectl apply -f ingress.yaml

List all network policies in the current namespace.

$ kubectl get networkpolicies

Display detailed information about a network policy.

$ kubectl describe networkpolicy <networkpolicy_name>

Storage and Volumes

List all persistent volumes in the cluster.

$ kubectl get pv

Display detailed information about a persistent volume.

$ kubectl describe pv <pv_name>

List all persistent volume claims in the current namespace.

$ kubectl get pvc

Display detailed information about a persistent volume claim.

$ kubectl describe pvc <pvc_name>

List all storage classes in the cluster.

$ kubectl get storageclasses

Display detailed information about a storage class.

$ kubectl describe storageclass <storageclass_name>

List all stateful sets in the current namespace.

$ kubectl get statefulsets

Display detailed information about a stateful set.

$ kubectl describe statefulset <statefulset_name>

Configurations and RBAC

List all roles in the current namespace.

$ kubectl get roles

Display detailed information about a role.

$ kubectl describe role <role_name>

List all role bindings in the current namespace.

$ kubectl get rolebindings

Display detailed information about a role binding.

$ kubectl describe rolebinding <rolebinding_name>

List all service accounts in the current namespace.

$ kubectl get serviceaccounts

Display detailed information about a service account.

$ kubectl describe serviceaccount <serviceaccount_name>

List secrets in a specific namespace.

$ kubectl get secrets --namespace=<namespace>

Display detailed information about a secret in a specific namespace.

$ kubectl describe secret <secret_name> --namespace=<namespace>

Custom Resources

List all custom resource definitions in the cluster.

$ kubectl get customresourcedefinitions

Display detailed information about a custom resource definition.

$ kubectl describe customresourcedefinition <crd_name>

List all custom resources in the current namespace.

$ kubectl get customresources

Display detailed information about a custom resource.

$ kubectl describe customresource <cr_name>

Helm Commands

List all Helm releases in the current namespace.

$ helm list

Install a Helm chart and create a release.

$ helm install <release_name> <chart>

Upgrade a Helm release to a new version.

$ helm upgrade <release_name> <chart>

Rollback a Helm release to a specific revision.

$ helm rollback <release_name> <revision>

Uninstall and delete a Helm release.

$ helm uninstall <release_name>

Autoscaling

Set up autoscaling for a deployment based on CPU usage.

$ kubectl autoscale deployment <deployment_name> --min=<min_replicas> --max=<max_replicas> --cpu-percent=<cpu_percentage>

List all horizontal pod autoscalers in the current namespace.

$ kubectl get hpa

Display detailed information about a horizontal pod autoscaler.

$ kubectl describe hpa <hpa_name>

Delete a horizontal pod autoscaler.

$ kubectl delete hpa <hpa_name>

Logging and Monitoring

Display logs from a specific container in a pod.

$ kubectl logs <pod_name> -c <container_name>

Display resource usage (CPU and memory) for nodes.

$ kubectl top nodes

Display resource usage (CPU and memory) for pods.

$ kubectl top pods

Display resource usage (CPU and memory) for deployments.

$ kubectl top deployments

Display resource usage (CPU) for horizontal pod autoscalers.

$ kubectl top hpa

Apply a Prometheus configuration defined in a YAML file.

$ kubectl apply -f prometheus.yaml

List all Prometheus instances in the current namespace.

$ kubectl get prometheus

Display detailed information about a Prometheus instance.

$ kubectl describe prometheus <prometheus_name>

List all Alertmanager instances in the current namespace.

$ kubectl get alertmanagers

Display detailed information about an Alertmanager instance.

$ kubectl describe alertmanager <alertmanager_name>

Security and RBAC

List all roles in all namespaces.

$ kubectl get roles --all-namespaces

Display detailed information about a role in a specific namespace.

$ kubectl describe role --namespace=<namespace> <role_name>

List all role bindings in all namespaces.

$ kubectl get rolebindings --all-namespaces

Display detailed information about a role binding in a specific namespace.

$ kubectl describe rolebinding --namespace=<namespace> <rolebinding_name>

List all cluster roles.

$ kubectl get clusterroles

Display detailed information about a cluster role.

$ kubectl describe clusterrole <clusterrole_name>

List all cluster role bindings.

$ kubectl get clusterrolebindings

Display detailed information about a cluster role binding.

$ kubectl describe clusterrolebinding <clusterrolebinding_name>

List all pod security policies in the cluster.

$ kubectl get podsecuritypolicies

Display detailed information about a pod security policy.

$ kubectl describe podsecuritypolicy <podsecuritypolicy_name>

Custom Resource Definitions (CRDs)

List all custom resource definitions in the cluster.

$ kubectl get crds

Display detailed information about a custom resource definition.

$ kubectl describe crd <crd_name>

List all custom resources in the current namespace.

$ kubectl get customresources

Display detailed information about a custom resource.

$ kubectl describe customresource <cr_name>

Pod Disruption Budgets (PDB)

List all pod disruption budgets in the current namespace.

$ kubectl get poddisruptionbudgets

Display detailed information about a pod disruption budget.

$ kubectl describe poddisruptionbudget <pdb_name>