KEMBAR78
K8s Important Commands | PDF | Operating System Families | Computer Engineering
0% found this document useful (0 votes)
16 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)
16 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
You are on page 1/ 13

11

important
kubernetes
cmds

github.com/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

linkedin.com/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

linkedin.com/in/omerberatsezer
kubectl apply

create or update resources


using a YAML file

user@k8s:$ kubectl apply -f <file.yaml>


# apply changes from a YAML file

linkedin.com/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 <file.yaml>
# delete resources defined in a YAML file

linkedin.com/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

linkedin.com/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

linkedin.com/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

linkedin.com/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

linkedin.com/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

linkedin.com/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

linkedin.com/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.

linkedin.com/in/omerberatsezer
user@k8s:$ ####################################

Follow for Tips on AWS, K8s, Docker, Linux


DevOps, MLOps, LLM, AI
Why? Cause; More will unfold over time
||
V
https://linkedin.com/in/omerberatsezer

https://github.com/omerbsezer

Feel free to like, share, or repost


to help more people see it

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

linkedin.com/in/omerberatsezer

You might also like