Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Kubernetes - Getting started

Install kubectl

 brew install kubernetes-cli

Install minikube

 brew install minikube

Starting the cluster

 minikube start

Looking up cluster information

 kubectl cluster-info

Looking up nodes

 kubectl get nodes

Identifying minikube ip

 minikube ip

To open minikube dashboard

 minikube dashboard

Deploying application

Create deployment.yaml file

Applying the deployment

 kubectl apply -f "<path of deployment.yaml file>"

Display information about the deployment

 kubectl describe deployment <deployment name from yaml file>

List the pods assigned for deployment

 kubectl get pods -l app=<appname>

Display info about the POD

 kubectl describe pod <pod-name>

Get the deployment status

 kubectl get deployments

Get the replica sets

 kubectl get rs 

To update the image version in the deployment

 kubectl set image deployment/<deploymentname> <containername>=<imagename>:<version>

To get the rollout status of a deployment

 kubectl rollout status deployment/<deployment-name>

To get the rollout history of a deployment

 kubectl rollout history deployment/<deployment-name>

To get the details of a specific revision

 kubectl rollout history deployment/<deployment-name> --revision=<revision number>

Rolling back deployment to the previous version

 kubectl rollout undo deployment/<deployment-name>

Rolling back to a specific revision number

 kubectl rollout undo deployment/<deployment-name> --to-revision=<revision-number>

Scaling a deployment

 kubectl scale deployment <deployment-name> --replicas=<new replicas number>

Autoscaling the deployment

 kubectl autoscale deployment <deployment-name> --min=<min number of pods> --max=<max number of pods> --cpu-percent = <cpu percentage>

Deleting a deployment

 kubectl delete deployment <deployment-name>

To get all the services

 kubectl get services

Deleting a service

 kubectl delete service <service-name>

Running containers inside cluster

To run a docker image from docker hub/Azure Container Registry

 kubectl run <name> --image=<image-name> --port=<container-port>

To expose the container as a service

 kubectl expose deployment <deployment-name> --type=NodePort

Connect to AKS from local kubectl

Get the credentials to connect

 az aks get-credentials --resource-group build18-recap-rg --name build18-recap-k8s

To change context to AKS

 kubectl config use-context <context-name> 

To view the dashboard

  • Using az aks browse az aks browse --resource-group build18-recap-rg --name build18-recap-k8s

  • Using kubectl proxy kubectl proxy

Full url for kubernetes-dashboard!/overview?namespace=default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment