Skip to content

Latest commit

 

History

History
109 lines (93 loc) · 3.74 KB

Kubernetes.md

File metadata and controls

109 lines (93 loc) · 3.74 KB

Kubernetes Deployment

Docker Desktop is one of the easiest way to get started with Kubernetes on Mac or Windows.
Other possible solutions are Kind, Minikube, Rancher Desktop. Here are quick instructions for a Kubernetes cluster with Docker Desktop.

Install Docker, enable its Kubernetes plugin, then run:

./scripts/cassandra.sh

There is a manual step here (TODO: automate): you have to first apply CQL changes to Cassandra. There is a DDL file for that: (cassandra.cql). See Cassandra.md for details: wait for cassandra to be up first, then run its DDL.
And then run bikes.sh:

./scripts/bikes.sh

The yaml deployment files are in directory kubernetes.
They are separated in different scripts so that they can be incrementally deployed.

Script Description

This section describes what the script bikes.sh does and other useful commands.
First, it builds the docker image:

sbt docker:publishLocal

Then sets the context:

sbt package docker:build   # in order to generate the docker image
export KUBECONFIG=~/.kube/config  # this file is created by docker for desktop when enabling kubernetes.
kubectl config set-context docker-desktop

Then deploys 3 nodes and creates a load balancer so that you can access monitor.html from the browser:

kubectl apply -f kubernetes/add-bikes-cluster-1.json
kubectl config set-context --current --namespace=bikes-cluster-1
kubectl apply -f kubernetes/bikes-cluster-deployment.yml
kubectl expose deployment bikes-cluster-demo --type=LoadBalancer --name=bikes-service

Clean up

kubectl delete service -l app=bikes-cluster-demo
kubectl delete deployments -l app=bikes-cluster-demo

Troubleshoot

Other useful commands to check if things are good along the way, or useful to troubleshoot:

kubectl config view
kubectl get deployments
kubectl get pods 
kubectl get pods --all-namespaces
kubectl get replicasets
kubectl get services bikes-service
kubectl describe services bikes-service
kubectl get pods --output=wide
kubectl get pods -o wide

kubectl config current-context
kubectl cluster-info
kubectl get ing
kubectl get all --all-namespaces
kubectl get all -n bikes-cluster-1
kubectl get namespaces
kubectl cluster-info dump
kubectl logs bikes-cluster-demo-86f4ff69f9-6k9dz
kubectl logs --selector app=bikes-cluster-demo --tail=200
lsof -i :8084

kubectl wait --for=condition=ready pod -l app=bikes

Get a shell to the running container:

kubectl exec --stdin --tty shell-demo -- /bin/bash

In order to destroy the entire kubernetes deployment, you can do:

# will delete all under that namespace:
kubectl delete namespaces bikes-cluster-1

but that will not remove the volumes Cassandra used. In order to properly clean up Cassandra, see here.

Minikube

Random Notes

With Minikube, the provisioner for cassandra's StatefulSet is not docker.io/hostpath but k8s.io/minikube-hostpath

In order to load the generated bikes image into minikube:

sbt docker:publishLocal
minikube image load bikes:0.3
minikube image ls
# which should produce something like:
#    registry.k8s.io/pause:3.9
#    ...
#    docker.io/library/bikes:0.3