Skip to content

Instantly share code, notes, and snippets.

@aweijnitz
Last active February 19, 2020 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweijnitz/5b1e72c76a8049de741727c6a7400efa to your computer and use it in GitHub Desktop.
Save aweijnitz/5b1e72c76a8049de741727c6a7400efa to your computer and use it in GitHub Desktop.
kubernetes basics with minikube
# Installation (Mac)
brew update; brew install minikube
minikube version
minikube start
# kubectl
kubectl version
kubectl cluster-info
kubectl get nodes
## Installing the web UI
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
kubectl proxy
open http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
minikube dashboard
## Create deployment from docker image (related 'docker build')
kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
kubectl get deployments
## Expose cluster using the proxy (CTRL-C aborts proxy)
kubectl proxy
minicube ip
## Now you can access the private cluster network on localhost:8001
kubectl get pods
kubectl describe pods
## get logs from a comntainer in a pod
kubectl logs
## Get resources from a pod
kubectl get
## Run command in a container in a pod
kubectl exec
## Start interactive shell
kubectl exec -ti $PODNAME bash
kubectl get servcies
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl get services/kubernetes-bootcamp
## Get pods by matching/selecting by label
kubectl get pods -l run=kubernetes-bootcamp
## Set label on pod
kubectl label pod $POD_NAME app=v1
## Delete service by label
kubectl delete service -l run=kubernetes-bootcamp
# Scaling
# Scaling is the same as increasing the number of replicas in a deployment.
## get the replica set
kubectl get rs
## Scale to 4 replicas
kubectl scale deployments/kubernetes-bootcamp --replicas=4
kubectl get pods -o wide
# Rolling updates
## Upgrade deployment (set new image)
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
## Check status
kubectl rollout status deployments/kubernetes-bootcamp
## Roll back deployment
kubectl rollout undo deployments/kubernetes-bootcamp
# Related
## Building Docker images
https://docs.docker.com/engine/reference/commandline/build/
# Read more (local docker deamon and deplyoments in minikube locally)
https://gist.github.com/kevin-smets/b91a34cea662d0c523968472a81788f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment