Commands - cordonezjolon/kubernetesCourses GitHub Wiki

List of commands to use Kubernetes

Get objects

  • kubectl get <TypeObject> <NameObject>

Create or update objects

  • kubectl <create or apply> -f fileName.yaml

Delete objects

  • kubectl delete <TypeObject> <NameObject>

Describe objects

  • kubectl describe <TypeObject> <NameObject>

Edit objects definition

  • kubectl edit <TypeObject> <NameObject>

Scale command to change number of replicas

  • kubectl scale <TypeObject> <NameObject> --replicas=<NumberOfReplicas>

Apply changes from file create/ update

  • kubectl apply -f <FileName>

Deployment commands

  • Apply version changes to deployment kubectl rollout deployment/<DeploymentName>
  • View deployment history kubectl rollout history deployment/<DeploymentName>
  • Rollback deployment kubectl rollout undo deployment/<DeploymentName>
  • Status deployment current status/ status logs kubectl rollout status deployment/<DeploymentName>

Get object from specific namespace

  • kubectl get <object> --namespace=<namespaceName>

Set conext to move to specific namespace

  • kubectl config set-context $(kubectl config current-context) --namespace=<namespaceName> After this command you dont have to use namespace flag.

List objects from all namespaces

  • kubectl get <object> --all-namespaces

Create files for specifik kind of object, instead create files from scratch

  • kubectl run nginx --image=nginx --dry-run=client -o yaml Use de --dry-run=cliente to validate imperative commands and -o yaml to export the file on yaml format without create a file or an object inside the cluster. Also you can add > nginx-deployment.yaml to create a file and after that edit it.

View admission controller enabled which are normally disabled

grep enable-admission-plugins /etc/kubernetes/manifests/kube-apiserver.yaml

View enabled and disabled plugins in cluster

ps -ef | grep kube-apiserver | grep admission-plugins

ApiGroups information

This command allows you kubectl proxy 8001& start a proxy server on your local machine to access the API whitout expose it to internet.

curl localhost:8001/curl localhost:8001/apis/authorization.k8s.io to get information from API

Change API Version with kubectl convert to migrate versions and save in output file

kubectl convert -f ingress-old.yaml --output-version networking.k8s.io/v1 > ingress-new.ya ml

⚠️ **GitHub.com Fallback** ⚠️