Basic Kubernetes (K8s) Commands | minikube | Pods | Services

Kubernetes Basics

Using minikube to create a single node cluster

minikube cli screenshot

Check if minikube is installed

minikube version

Start the cluster

minikube start

Check if kubectl is installed

kubectl version

Check cluster details

kubectl cluster-info

View nodes in the cluster

kubectl get nodes

Deploy an app

kubectl create deployment kubernetes-bootcamp

List your deployment

kubectl get deployments

Check existing pods

kubectl get podskubectl get pods -o wide

Describe pods

kubectl describe pods

Check logs of a container running in pod

kubectl logs $POD_NAME

Execute command directly inside container running in a pod

kubectl exec $POD_NAME env

Start a bash session in a pod container

kubectl exec -ti $POD_NAME bash

To close your container connection type exit.

List current services from your cluster

kubectl get services

Create a new service and expose it to external traffic with NodePort as paramter

kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

Describe a service

kubectl describe services/kubernetes-bootcamp

Test your app on the externally exposed port

curl $(minikube ip):$NODE_PORT

Query list of pods using label

kubectl get pods -l run=kubernetes-bootcamp

Query list of services using label

kubectl get services -l run=kubernetes-bootcamp

Apply a new label to the object

kubectl label pod $POD_NAME app=v1

Deleting a service

kubectl delete service -l run=kubernetes-bootcamp

Scale up the service

kubectl scale deployments/kubernetes-bootcamp --replicas=4

Scale down the service

kubectl scale deployments/kubernetes-bootcamp --replicas=2

Rolling update, Update the image of your application

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

Confirm an update

kubectl rollout status deployments/kubernetes-bootcamp

Rollback an update

kubectl rollout undo deployments/kubernetes-bootcamp



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store