Skip to content

on2itsecurity/meetup-kubernetes-introduction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Introduction to Kubernetes

Setting up a single-node cluster

Prerequisites:

  • Clean debian install
  • add-user meetup
  • Swap off 'sudo swapoff -a'

Install CRI - Docker

sudo apt install -y ca-certificates software-properties-common curl apt-transport-https
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"

sudo apt update && sudo apt install -y docker-ce=18.06.0~ce~3-0~debian

Install kubeadm, kubelet and kubectl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null

sudo apt update && sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Deploy the node

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

You will see something like this:

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  sudo kubeadm join 172.16.153.131:6443 --token bfvz2a.ie09qb8tj256t9tu --discovery-token-ca-cert-hash sha256:63572357080e3d0da5693baa7c20d19bcd804c9f639dd20338a3249793081fe5

Hint: Write down the kubeadm command, including the token en hash, it will come in handy when expanding the cluster

mkdir -p /home/meetup/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/meetup/.kube/config
sudo chown meetup:users /home/meetup/.kube/config

Take a look at your brand new kubernetes cluster:

kubectl get all --all-namespaces

Notice that coredns will not start, cause the CNI (network) is missing.

Install CNI (Flannel)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

Convert to single node cluster

To make sure pods will also be scheduled on this node.

kubectl taint nodes --all node-role.kubernetes.io/master-

WAIT - for the next lab

Ingress controller

As an ingress controller 'nginx-ingress' will be used. More information: https://kubernetes.github.io/ingress-nginx/deploy/

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml

WAIT - for the next lab

Deploy 'Whack-A-Pod'

More info: https://github.com/tpryan/whack_a_pod

Get the contents from github

cd
git clone https://github.com/ljkoning/whack_a_pod.git

(Note: original repo: git clone https://github.com/tpryan/whack_a_pod.git)

Deploy the game

Make sure the context is set, since the make command will use it.

kubectl config set-context $(kubectl config current-context) --namespace=default

Copy the Sample.properties to MAkefile.properties

cd ~/whack_a_pod
cp Sample.properties Makefile.properties

Edit DOCKERREPO in Makefile.properties

nano Makefile.properties

DOCKERREPO=cloudowski

Deploy the game.

make deploy.generic

Access the game

As you can see from the whack-a-pod directory in 'apps/ingress/ingress.generic.yaml', the hostname that is used by default is 'whackapod.example.com'.

To access the game, we need to add name to the hosts file of your windows jump host, with the IP of the node.

On windows, edit the file:

C:\Windows\System32\drivers\etc\hosts

To include this line (make sure to replace the IP address with your node address)

10.10.10.x1 whackapod.example.com

Lookup the NodePort on which the ingress controller is listening.

kubectl get service --namespace=ingress-nginx

In the below example it is: 32602

NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   NodePort   10.100.75.185   <none>        80:32602/TCP,443:31226/TCP   20h

Go to the browser of your windows jumphost, and go to desired url:

Clean up the deployment

To clean up

make clean.generic

WAIT - for the next lab

(EXTRA) Add an additional node

  • Login to the new node (host)

Install CRI - Docker

sudo apt install -y ca-certificates software-properties-common curl apt-transport-https

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"

sudo apt update && sudo apt install -y docker-ce=18.06.0~ce~3-0~debian

Install kubeadm, kubelet and kubectl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null

sudo apt update && sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Join the cluster

sudo kubeadm join 172.16.153.131:6443 --token bfvz2a.ie09qb8tj256t9tu --discovery-token-ca-cert-hash sha256:63572357080e3d0da5693baa7c20d19bcd804c9f639dd20338a3249793081fe5

With the following commands from the master (there is kubectl configured) you can check if the node is ready and the cluster is healthy.

kubectl get nodes
kubectl get componentstatus

Tips

  • Kubectl auto-completion (tab tab)
source <(kubectl completion bash)

Add this to '.bashrc' if you want this in every (new) session.

About

Lab files for the meetup "kubernetes introduction"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •