Kubeadm Kubernetes
This is a note for my on premise Kubeadm Kubernetes Project.
I create 2 VMs with this spec “2 CPU Mem 2G Ubuntu 18.04.3 docker version 19.03.6”. First machine is for etcd and controlpane node. The other is for worknode.
You have to install docker first, if you don’t have one.
This page is really helpful.
This Tutorial is also helpful.
Add Kubernetes signing key for both machine.
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
Add Xenial Kubernetes Repository for both machine.
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Install kubeadm for both machine.
sudo apt install kubeadm
Turn off swap for both machine.
swapoff -a
Make it permanent by edit /etc/fstab.
Comment out swap line.
kubeadm init on controlpane node machine only
kubeadm init --pod-network-cidr=10.222.0.0/16
You will get this result.
Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configYou 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/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 128.199.97.209:6443 --token qi8czh.sho75uqbuh0t6i43 \--discovery-token-ca-cert-hash sha256:a9c5225f31daa859befb8ec8843667448cc549603659b35b7769e965c74e7f55
Take note for your token. You need it later to Deploy worker node.
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
If you try “kubectl get node”, you will see that master is not ready. We need to deploy Pod network first.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Then allow ufw tcp port 6443 on your master. This will allow your worknode to connect to your controlplane.
ufw allow 6443/tcp
Then we join worker node in worknode machine.
kubeadm join 128.199.97.209:6443 --token qi8czh.sho75uqbuh0t6i43 \--discovery-token-ca-cert-hash sha256:a9c5225f31daa859befb8ec8843667448cc549603659b35b7769e965c74e7f55
Go back to controlplane machine and run kubectl get nodes
. You will see Status is Ready.
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 6h25m v1.18.3
k8s-worker01 Ready <none> 6h18m v1.18.3
When you’re done. Let’s try this Tutorial to validate your installation.
Tutorial PHP Guestbook will deploy Redis Master, Redis Slave and PHP Frontend. It start with deployent of Redis Master
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-deployment.yaml
Then Service Redis Master.
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-service.yaml
Check your Service with kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 1m
redis-master ClusterIP 10.0.0.151 <none> 6379/TCP 8s
Next, deploy Redis Slave.
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-slave-deployment.yaml
Then deploy Redis Slave Service.
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-slave-service.yaml
Deploy Frontend.
kubectl apply -f https://k8s.io/examples/application/guestbook/frontend-deployment.yaml
Then deploy Frontend service.
kubectl apply -f https://k8s.io/examples/application/guestbook/frontend-service.yaml
Check Service with kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend NodePort 10.0.0.112 <none> 80:30798/TCP 6s
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 4m
redis-master ClusterIP 10.0.0.151 <none> 6379/TCP 2m
redis-slave ClusterIP 10.0.0.223 <none> 6379/TCP 1m
Config your firewall to allow Nodeport (In my case is port 30798).
Open your Web browser with IP of worker machine and NodePort Assign (In my case is port 30798)
:)