0% found this document useful (0 votes)
21 views13 pages

K8s Important Commands

This document provides a list of important Kubernetes commands using kubectl, detailing how to manage resources such as pods, services, and deployments. It includes commands for listing, describing, applying, deleting, viewing logs, executing commands inside pods, scaling deployments, exposing services, port-forwarding, managing rollouts, and configuring kubeconfig. Additionally, it encourages following the author for more tips on related topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views13 pages

K8s Important Commands

This document provides a list of important Kubernetes commands using kubectl, detailing how to manage resources such as pods, services, and deployments. It includes commands for listing, describing, applying, deleting, viewing logs, executing commands inside pods, scaling deployments, exposing services, port-forwarding, managing rollouts, and configuring kubeconfig. Additionally, it encourages following the author for more tips on related topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11

important
kubernetes
cmds

[Link]/omerbsezer
kubectl get

list resources
(pods, services, nodes, deployments)

user@k8s:$ kubectl get pods # list all pods


user@k8s:$ kubectl get services # list all services
user@k8s:$ kubectl get deployments # list all deployments
user@k8s:$ kubectl get nodes # list all nodes
user@k8s:$ kubectl get pods -o wide -A # all pods in all namespaces

[Link]/in/omerberatsezer
kubectl describe

show detailed information


about a specific resource

user@k8s:$ kubectl describe pod <pod-name>


# details of a specific pod in default namespace
user@k8s:$ kubectl describe service <service-name>
# details of a specific service in default namespace
user@k8s:$ kubectl describe pod <pod-name> -n <namespace>
# details of a specific pod in specific namespace

[Link]/in/omerberatsezer
kubectl apply

create or update resources


using a YAML file

user@k8s:$ kubectl apply -f <[Link]>


# apply changes from a YAML file

[Link]/in/omerberatsezer
kubectl delete

remove resources
from the cluster

user@k8s:$ kubectl delete pod <pod-name>


# delete a specific pod
user@k8s:$ kubectl delete -f <[Link]>
# delete resources defined in a YAML file

[Link]/in/omerberatsezer
kubectl logs

view logs from


a specific pod or container

user@k8s:$ kubectl logs <pod-name>


# logs from a single-container pod
user@k8s:$ kubectl logs <pod-name> -c <container-name>
# logs from a specific container in a pod

[Link]/in/omerberatsezer
kubectl exec

execute a command
inside a running pod

user@k8s:$ kubectl exec -it <pod-name> -- /bin/bash


# start a bash shell in a pod
user@k8s:$ kubectl exec <pod-name> -- ls /app
# run `ls /app` inside the pod

[Link]/in/omerberatsezer
kubectl scale

adjust the number of


replicas for a deployment

user@k8s:$ kubectl scale deployment <deployment-name> --replicas=3


# scale to 3 replicas

[Link]/in/omerberatsezer
kubectl expose

create a service to expose


a pod or deployment

user@k8s:$ kubectl expose deployment <deployment-name> --


type=NodePort --port=8080
# expose a deployment on port 8080

[Link]/in/omerberatsezer
kubectl port-forward

forward local ports to a pod


for testing or debugging

user@k8s:$ kubectl port-forward <pod-name> 8080:80


# forward local port 8080 to pod's port 80

[Link]/in/omerberatsezer
kubectl roll-out

manage and monitor


deployment rollouts
(status, undo)

user@k8s:$ kubectl rollout status deployment/<deployment-name>


# check the status of a rollout
user@k8s:$ kubectl rollout undo deployment/<deployment-name>
# rollback to the previous version

[Link]/in/omerberatsezer
kubectl config

manage kubeconfig file


(for multiple cluster switching)

user@k8s:$ kubectl config get-contexts


# list available contexts.
user@k8s:$ kubectl config use-context <context-name>
# switch to a specific context.
user@k8s:$ kubectl config view
# view current configuration details.

[Link]/in/omerberatsezer
user@k8s:$ ####################################

Follow for Tips on AWS, K8s, Docker, Linux


DevOps, MLOps, LLM, AI
Why? Cause; More will unfold over time
||
V
[Link]

[Link]

Feel free to like, share, or repost


to help more people see it

user@k8s:$ ####################################

[Link]/in/omerberatsezer

You might also like