Microservices — Kubernetes First…
I recently spent much of my time learning about microservices, and I am pleased with the results of that investment. Where I had only an inkling of what microserices might be, I now have a good picture as covered in my Microservices — From Idea To Starting Line article.
Now I am moving from a pure research phase and into a test run the available tech phase. I want to begin by setting up an off-the-shelf, open source service mesh — namely, Istio. I have chosen Istio for its (relative) maturity as a control plane and its use of Envoy which has even more maturity as the data plane. Frankly, I really liked what I saw in a demonstration video in how it manages the security of the services.
Istio requires Kubernetes, as do many of the other microservices mesh infrastructure software. Therefore, I am off to get Kubernetes working.
Setting up Kubernetes
Step one is met with hurdle one: Kubernetes is not for the weak of will. At first blush, the documentation is overwhelming. Amazon’s hosted setup is still in preview mode (awaiting my acceptance into the preview now!). Google’s hosted setup was throwing errors as I clicked the “Start Free Trial” button and refused to let me access it. Damn. Tectonic by CoreOS has a “call us for pricing” statement that absolutely turns me away. I could set it up using minikube, but my operations background demands something a little more production like for this initial swim.
Ye Old Manual Install
In the end I found it incredibly quick and easy to spin up two Ubuntu 16.04 Droplets on Digital Ocean; one for the master node and one to run workers. The following was executed on both nodes:
# Execute on both nodes
apt-get update && apt-get upgrade -yapt-get install -y docker.io apt-transport-httpscurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg |
apt-key add -cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOFapt-get update
apt-get install -y kubelet kubeadm kubectl
sed -i '${s/$/ --cgroup-driver=cgroupfs/}' /etc/systemd/system/kubelet.service.d/10-kubeadm.confsystemctl daemon-reload
systemctl restart kubelet
Then, on the master node:
kubeadm init --pod-network-cidr=10.244.0.0/16
export KUBECONFIG=/etc/kubernetes/admin.confkubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
The kubeadm init
output will provide a kubeadm join
command for adding nodes. Copy that and paste it on the secondary node and you will be automatically configure and join the cluster.
Once it is done, on the master you can issue kubectl get nodes
to see the two nodes. Woohoo! I used these two documents as my guide for these steps:
- https://kubernetes.io/docs/setup/independent/install-kubeadm/
- https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
With this running, you can also use this document to start up an nginx pod just to see a bit of minimal functionality: https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/
The New Fangled Automated Way
Doing things manually is not my style. It never has been; even in my old system admin days I automated the crap out of everything I possibly could. My parents told me being lazy was never going to get me anywhere in life. Little did they know that being lazy lead me to automation which took me places!
In my digging around about Kubernetes, I ran across Terraform by HashiCorp. I have been a very long-time fan of Vagrant and Packer, so I took the time to give Terraform a try. Boy, was I glad I did!
You can clone my kubernetes-terraform git repository and get started right away. The README.md covers setting some environment variables, and it is as easy as terraform apply
to get started. It will always spin up one master node, and then any number of actual worker nodes. Using this repository, you can have your own kubernetes cluster up and running in about 5 minutes.
Next-Level Automation: Typhoon
What I have setup is a very simple use of Terraform (mostly to learn a bit about Terraform). If you want to use Terraform and get a lot more functionality out of the box, I recommend looking at Typhoon — a project which uses Terraform to deliver a Kubernetes cluster in various environments and with much more functionality than I have setup here.
Next: Istio!
My next step will be to layer Istio on top of this. Stay tuned!