Skip to content

Instantly share code, notes, and snippets.

@a-robinson
Last active April 27, 2020 12:43
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save a-robinson/173ae84e906d10d25a58f1b26c38066b to your computer and use it in GitHub Desktop.
Save a-robinson/173ae84e906d10d25a58f1b26c38066b to your computer and use it in GitHub Desktop.
# Make sure that you’ve installed minikube and run `minikube start` to get your Kubernetes cluster running.
minikube version (should be at least 0.19.0)
minikube start
kubectl version (should be at least 1.6.0 for both client and server)
-------------------
# Create the CockroachDB cluster and other relevant resources
kubectl create -f https://bit.ly/crdb-k8s-yaml
# Check out everything that got created
kubectl get pods
kubectl get services
kubectl get pvc
# Verify that the Cockroachdb cluster started up successfully
kubectl logs cockroachdb-0
# Open a sql shell against the cluster
kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never -- sql --insecure --host=cockroachdb-public
# SQL commands to run within the shell
show databases;
create database foo;
show databases;
# Run a load generator in Kubernetes to generate a steady load against the CockroachDB cluster
kubectl run loadgen --image=cockroachdb/loadgen-kv:0.1 -- /kv --max-rate=100 --tolerate-errors postgres://root@cockroachdb-public:26257/?sslmode=disable
# See that the load generator is running
kubectl get pods
# Optionally check out the load generator’s logs with: kubectl logs <loadgen-pod-name>
# Port-forward into one of the pods so that you can look at the admin UI
kubectl port-forward cockroachdb-0 8080
# Open up admin UI at http://localhost:8080/
# Scale up the cluster
kubectl scale statefulset cockroachdb --replicas=5
kubectl get pods
# Open up the UI again to show the scaling
# Try killing a process to see how it affects the running cluster
kubectl delete pod cockroachdb-3
# Upgrade the version of CockroachDB
kubectl edit statefulset cockroachdb
# this will open up your default text editor - find the line containing `image: cockroachdb/cockroach:v1.0.1` and replace "v1.0" with "v1.0.1"
# Demonstrate that this didn't truly update the running pods
kubectl describe statefulset cockroachdb | grep Image
kubectl describe pod cockroachdb-0 | grep Image
# Delete the first pod and show it changes to the "new" version
kubectl delete pod cockroachdb-0
kubectl describe pod cockroachdb-0 | grep Image
# Update the other pods one-by-one
for i in {1..4}; do kubectl delete pod "cockroachdb-${i}"; sleep 45; done
# Tear things down - note that this will take a little while due to our graceful termination setting
kubectl delete deployment loadgen
kubectl delete -f https://tiny.cc/cockroachdb-statefulset
# Show that volumes are still around in case we wanted to restart everything
# We could bring everything back up by just rerunning the `kubectl create` command
kubectl get pvc
kubectl delete pvc -l app=cockroachdb
kubectl get pv
@hanhy17
Copy link

hanhy17 commented Jul 26, 2017

Does not work with Minikube 0.21.0, error message as below:
$ kubectl create -f https://bit.ly/crdb-k8s-yaml
service "cockroachdb-public" created
service "cockroachdb" created
poddisruptionbudget "cockroachdb-budget" created
The StatefulSet "cockroachdb" is invalid: spec.template.annotations.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey: Required value: can not be empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment