➜ Create a HA production ready cluster with Kubespray
➜ Deploy the demo microservice
➜ Setup and run experiments (repeat steps for each experiment)
- Kubernetes/kubectl
- Python3
- pip3
- VirtualBox
Note: This repo uses kubespray and this demo microservice
Note: This repo uses kubespray
-
clone the repo and cd into it
https://github.com/kubernetes-sigs/kubespray.git cd kubespray #modify: group_vars/k8s-cluster/k8s-cluster.yml to kubeconfig_localhost: true
-
Install dependencies
pip3 install -r requirements.txt
-
Bring up vagrant (this can take awhile)
vagrant up
-
Setup access to the cluster globally
#navigate to artifacts directory #/inventory/sample/artifacts cp admin.conf ~/.kube/config
-
Check nodes are up
kubectl get nodes kubectl get pods --all-namespaces
-
Create a namespace for the microservice
kubectl create namespace sock-shop
-
Deploy it
kubectl apply -f sock-shop.yaml
-
Check pods are running
kubectl get pods --namespace sock-shop #or kubectl get pods --namespace sock-shop --watch
-
Get front-end deployment port info and setup port forwarding
kubectl get deploy front-end -n sock-shop -o jsonpath='{.spec.template.spec.containers[?(@.name == "front-end")].ports[0].containerPort}' kubectl port-forward deploy/front-end -n sock-shop 3000:8079 #127.0.0.1:3000
-
Clone the repo in
/chaos-mesh
https://github.com/chaos-mesh/chaos-mesh.git
-
Install and create chaos mesh
kubectl apply -f ./chaos-mesh/manifests/crd.yaml kubectl create ns chaos-mesh helm upgrade --install chaos-mesh ./chaos-mesh/helm/chaos-mesh \ -n chaos-mesh \ --set dashboard.create=true
-
Check pods are running and CRDs are present
kubectl get pods --namespace chaos-mesh kubectl get crds
-
Get chaos-dashboard port info
kubectl get deploy chaos-dashboard -n chaos-mesh -o=jsonpath="{.spec.template.spec.containers[0].ports[0].containerPort}{'\n'}"
-
Expose port
kubectl port-forward -n chaos-mesh svc/chaos-dashboard 2333:2333 #127.0.0.1:2333
-
Run experiments via yaml config
kubectl apply -f chaos-experiments/pod-kill.yaml
-
Monitor results
kubectl describe podchaos -n chaos-mesh http://localhost:2333
-
Clean up
kubectl delete -f chaos-experiments/pod-kill.yaml -n chaos-mesh helm delete chaos-mesh -n chaos-mesh kubectl delete namespace sock-shop vagrant halt vagrant destroy -f kubectl config use-context docker-desktop