Skip to content

Instantly share code, notes, and snippets.

@coolpalani
Forked from jamesbuckett/kubeadm.md
Created November 29, 2017 11:23
Show Gist options
  • Save coolpalani/e663a99b63db421c7d4668e7f7e4c0a1 to your computer and use it in GitHub Desktop.
Save coolpalani/e663a99b63db421c7d4668e7f7e4c0a1 to your computer and use it in GitHub Desktop.
kubeadm

01 - Deploy a Kubernetes cluster and Microservices Application

Deploy a Kubernetes cluster on Digital Ocean

Deploy the Socks Shop Microservices Application

Wednesday 26/07/2017

tl;dr - Kubernetes is a container orchestration engine.

tl;dr - Microservices are software components that are independently deployable and scalable.

Kubeadm Documentation : https://kubernetes.io/docs/getting-started-guides/kubeadm/

Digital Ocean

Provision three or four Ubuntu droplets on Digital Ocean.

Distribution : Ubuntu 16.04.2 x64 ($5 or $10 or $20)

I find the $20 droplets have the best performance for this exercise.

Don't forget to add your SSH key.

If you want to use Digital Ocean for this exercise, use this referral link to get $10 in credit.

Referral Link : https://m.do.co/c/ac62c560d54a

This example assumes Ubuntu as the Operating system for the Masters and Workers.

Operating System Preparation

On master and workers : ubuntu-1gb-sgp1-01/ubuntu-1gb-sgp1-02/ubuntu-1gb-sgp1-03

apt-get update && apt-get install -y apt-transport-https

curl -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
EOF

apt-get update

apt-get install -y docker.io

apt-get install -y kubelet kubeadm kubectl kubernetes-cni

kubeadm init

On master : ubuntu-1gb-sgp1-01

kubeadm init

Starting in Version 1.8, tokens will expire after 24 hours by default (if you require a non-expiring token use --token-ttl 0)

kubeadm init --token-ttl 0

(Grab the final output of this command to add the worker nodes in the kubeadm join section below)

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Install the overlay network :

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

kubeadm join

On workers : ubuntu-1gb-sgp1-02 / ubuntu-1gb-sgp1-03

sudo su -

kubeadm join --token=<token> <master-ip> --skip-preflight-checks

In separate terminal execute this to watch the status of the kubernetes services.

watch -t -n1 'echo kube-system Pods && kubectl get pods -o wide -n kube-system && echo && echo kube-system Services && kubectl get svc -n kube-system && echo && echo Nodes && kubectl get nodes -o wide'

Socks Shop

Only do this part if you want to deploy a sample microservices sample application.

Socks Shop Documentation : https://microservices-demo.github.io/

On Master - ubuntu-1gb-sgp1-01

kubectl create namespace sock-shop

kubectl apply -n sock-shop -f "https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true"

kubectl get pods -n sock-shop -w

In separate terminal execute this to watch the status of the socks shop application.

watch -t -n1 'echo sock-shop Pods && kubectl get pods -n sock-shop -o wide && echo && echo sock-shop Services && kubectl get svc -n sock-shop && echo && echo Nodes && kubectl get nodes -o wide'

Shock Shop UI = On any worker node (ubuntu-1gb-sgp1-02 or ubuntu-1gb-sgp1-03) ip a | grep eth0 + 30000 range port from kubectl get svc

On any worker node get the IP address : ip a | grep eth0

On master get the port of the front-end service : kubectl get svc -n sock-shop | grep front-end

User ID's and Passwords to access the Socks Shop Application.

Username and Passwords : user password user1 password Eve_Berger eve

Weave Cloud (Optional)

kubectl apply -f 'https://cloud.weave.works/launch/k8s/weavescope.yaml?service-token=<token>'

https://cloud.weave.works/

kubetail (Optional)

Bash script to tail Kubernetes logs from multiple pods at the same time

Link : https://github.com/johanhaleby/kubetail

wget https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail

chmod +x kubetail

kubectl get pods -n sock-shop

./kubetail cart -n sock-shop

End of Section

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