Saturday, August 17, 2024

Kubernetes Commands

 Kubernetes commands are executed using the `kubectl` command-line tool, which is the primary way to interact with a Kubernetes cluster. Here’s a rundown of some essential `kubectl` commands and their usage:

General Commands via bash

Get Cluster Info -> kubectl cluster-info

Get Kubernetes Version -> kubectl version

Commands for Context and configuration

View Current Context -> kubectl config current-context

List Contexts-> kubectl config get-contexts

Set Context-> kubectl config use-context <context-name>

View Configurations-> kubectl config view

Commands for Pods

List Pods-> kubectl get pods

Describe Pod-> kubectl describe pod <pod-name>

Get Pod Logs-> kubectl logs <pod-name>

Execute Command in Pod-> kubectl exec -it <pod-name> -- <command>

Delete Pod-> kubectl delete pod <pod-name>

Commands for Deployments

List Deployments-> kubectl get deployments

Describe Deployment-> kubectl describe deployment <deployment-name>

Create Deployment-> kubectl create deployment <deployment-name> --image=<image>

Scale Deployment-> kubectl scale deployment <deployment-name> --replicas=<number>

Update Deployment-> kubectl set image deployment/<deployment-name> <container-name>=<new-image>

Delete Deployment-> kubectl delete deployment <deployment-name>

Commands for Services

List Services->kubectl get services

Describe Service-> kubectl describe service <service-name>

Expose Deployment as Service-> kubectl expose deployment <deployment-name> --type=<type> --port=<port> --target-port=<target-port>

Commands for Namespaces

List Namespaces-> kubectl get namespaces

Create Namespace-> kubectl create namespace <namespace-name>

Delete Namespace-> kubectl delete namespace <namespace-name>

Commands for ConfigMaps and Secrets

List ConfigMaps-> kubectl get configmaps

Describe ConfigMap-> kubectl describe configmap <configmap-name>

Create ConfigMap-> kubectl create configmap <configmap-name> --from-literal=<key>=<value>

Delete ConfigMap-> kubectl delete configmap <configmap-name>

List Secrets-> kubectl get secrets

Describe Secret-> kubectl describe secret <secret-name>

Create Secret-> kubectl create secret generic <secret-name> --from-literal=<key>=<value>

Delete Secret-> kubectl delete secret <secret-name>

Commands for Persistent Volumes and Claims

List Persistent Volumes->  kubectl get pv

Describe Persistent Volume-> kubectl describe pv <pv-name>

List Persistent Volume Claims->  kubectl get pvc

Describe Persistent Volume Claim-> kubectl describe pvc <pvc-name>

Commands for General Resource Management

Apply Configuration from File->  kubectl apply -f <file.yaml>

Delete Resource from File-> kubectl delete -f <file.yaml>

Get Resource-> kubectl get <resource-type>

 Describe Resource-> kubectl describe <resource-type> <resource-name>

Commands for Troubleshooting

View Cluster Events-> kubectl get events

Describe Node-> kubectl describe node <node-name>

These commands cover a wide range of Kubernetes operations and should be useful for managing and interacting with your Kubernetes clusters.

No comments:

Post a Comment