Technologies


# Notes

Kubernetes vs. Docker

  • Pod = Container

  • Deployment = Image

  • LoadBalancer = Service, that distributes users equally between pods


# Kubernetes

  • Build an image
  • docker build -t kub-first-app .
  • Make sure cluster is running
  • minikube status
  • See list of available kubectl commands
  • kubectl help
  • Create deployment object
  • kubectl create deployment first-app --image=kub-first-app
  • Get list of created deployments and pods
  • kubectl get deployments
  • kubectl get pods
  • This should not have worked. Images need to be pulled from registry by Kubernetes. You need to push your image first to docker hub, or use the trueberryless/kub-first-app image.
  • First delete the previous deployment
  • kubectl delete deployment first-app
  • then create the new deployment
  • kubectl create deployment first-app --image=trueberryless/kub-first-app
  • minikube dashboard
  • Expose a port
  • kubectl expose deployment first-app --type=LoadBalancer --port=8080
  • See services
  • kubectl get services

# Minikube

Local Kubernetes

  • On a cloud infrastructure we would get an external IP. For minikube we need:
  • minikube service first-app
  • You can crash the app by going to the /error route. You will see the pod gets restarted automatically (taking longer and longer each time).
  • You can also scale your deployment
  • kubectl scale deployment/first-app --replicas=3
  • Have a look at your pods again
  • kubectl get pods
  • You can update your deployment by running. Images will only be pulled if they have a different tag.
  • kubectl set image deployment/first-app kub-first-app=trueberryless/kub-first-app:v2
  • view the deployment status
  • kubectl rollout status deployment/first-app
  • Run a deployment with a non-existing image/tag.
  • kubectl set image deployment/first-app kub-first-app=trueberryless/kub-first-app:not-exist
  • Checking the status of your rollout you will see, the old pods won’t be terminated because the new ones can’t be started due to an image pulling error.
  • Rollout to last deployment
  • kubectl rollout undo deployment/first-app
  • See deployment history
  • kubectl rollout history deployment/first-app
  • kubectl rollout history deployment/first-app --revision=3
  • You can also rollback to a specific revision
  • kubectl rollout undo deployment/first-app --to-revision=1
CommandExplanationUse-Case
minikube statusMaking sure, cluster is running
git commit -mCreate new commit with message-flag
git branch newBranchCreates a new branchHere: creates ‘newBranch’
git checkout newBranchMove to other branchHere: moves to ‘newBranch’
git merge newBranchCombines two branchesHere: combining ‘newBranch’ & ‘main’
git rebase mainMoves commits from current branch in other branch - new linear historyHere: combining ‘newBranch’ & ‘main’