- Consulting
- Training
- Partners
- About Us
x
In this blog, we will create a Kubernetes multi-node Cluster in a Virtual Machine Instance (EC2) and deploy a WordPress application on top of it.
Here, I am developing a cluster that gives us complete control over the nodes.
To Deploy a WordPress application in Kubernetes, you will need the following:
Step 1: Create three instances of t3.medium running ubuntu 20.14 in the AWS console in any region.
Step 2: Add the security group Kubernetes-related port number and calico port number
Step 3: Tag one Instance as a Master node,
Remaining instances as worker one and worker two nodes.
SSH into the master and worker instance and Run the following commands.
#REMOVE OLD DOCKER
1 |
sudo apt-get remove docker docker-engine docker.io contained runs |
#INSTALL DOCKER PRE-REQUISITES
1 2 |
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release |
#ADD GPG KEY
1 2 3 4 |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
#INSTALL DOCKER ENGINE
1 2 3 4 5 6 7 |
sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io sudo docker run hello-world cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF |
# Restart nodes to load them the br_netfilter and overlay
1 2 |
sudo modprobe overlay sudo modprobe br_netfilter |
#ALLOW BRIDGED TRAFFIC FOR KUBEADM
1 2 3 4 5 |
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sudo sysctl --system |
#INSTALL K8S PRE-REQUISITES
1 2 |
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl |
#DOWNLOAD GOOGLE CLOUD PUBLIC SIGNINIG KEY
1 2 |
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg |
# ADD K8S APT REPO
1 2 3 |
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list |
# INSTALL K8S COMPONENTS
1 2 3 4 5 6 7 8 9 10 11 12 |
sudo apt-get update sudo apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00 sudo apt-mark hold kubelet kubeadm kubectl kubectl taint nodes --all node-role.kubernetes.io/master- sudo touch /etc/docker/daemon.json cat <<EOF | sudo tee /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"] } EOF sudo swapoff –a #to disable the swapping sudo sed -i '/ swap / s/^/#/' /etc/fstab # To persist the swap disable |
#init
1 2 |
sudo systemctl daemon-reload sudo systemctl restart docker |
Step 4: On the Master, node instance, follow the below commands to Initiate the Kubeadm, generate the token and Install Calico network plugin.
#Kubeadm init
1 2 3 4 |
kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all export KUBECONFIG=/etc/kubernetes/admin.conf sudo cp /etc/kubernetes/admin.conf $HOME/admin.conf sudo chown $(id -u):$(id -g) $HOME/admin.conf |
#Generate Token
1 2 3 4 |
token=$(kubeadm token generate) rm -f home/ubuntu/nodes-join-token.out kubeadm token create $token --print-join-command --ttl=0 > /home/ubuntu/nodes-join-token.out cat /home/ubuntu/nodes-join-token.out |
#Install calico networking
1 2 3 4 5 6 7 8 9 10 11 12 13 |
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml kubectl get cs kubectl get components tatus kubectl cluster-info kubectl get pods -n kube-system mv $HOME/.kube $OME/.kube.bak mkdir $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config sudo systemctl restart docker.service sudo systemctl enable docker.service sudo service kubelet restart |
Step 5: A file is created in the master node named “nodes-join-token”. Open it and copy the token
1 |
Cat nodes-join-token |
Step 6: Past the token in both the worker nodes to join them into the cluster.
Step 7: After the above step, run the below command in the master node to verify whether nodes are joined.
1 |
$:-Kubectl gets nodes |
Successfully created Kubernetes Cluster using Kubeadm.
Step 8: SSH into the master node and execute the below code To Download the WordPress application.
#Install GIt
1 |
Sudo apt-get install git-all |
#make a directory
1 2 3 4 5 |
mkdir /home/ubuntu/Kubernetes cd /home/ubuntu/Kubernetes git init git remote add kube https://github.com/v-karthik-kumar/kubernetes-karthik.git git pull kube master |
Step 9: Deploy yaml code in a sequence on the master nodes.
Step 9.1: Go to the Kubernetes directory
1 |
Cd /home/ubuntu/Kubernetes |
Step 9.2: Deploy persistent volume for MySQL
1 |
Kubectl apply -f pvMysql.yml |
Step 9.3: Deploy persistent volume claim for MySQL
1 |
Kubectl apply -f pvcMysql.yml |
Step 9.4: Deploy service for MySQL
1 |
Kubectl apply -f mysql-svc.yml |
Step 9.5: Deploy secrets
1 |
Kubectl apply -f secret.yml |
Step 9.6: Deploy Deployment of mysql
1 |
Kubectl apply -f mysql.yml |
Step 9.7: Deploy persistent volume for WordPress
1 |
Kubectl apply -f pvWordpress.yml |
Step 9.8: Deploy persistent volume claim for WordPress
1 |
Kubectl apply -f pvcWordpress.yml |
Step 9.9: Deploy service for WordPress
1 |
Kubectl apply -f wordpress-svc.yml |
Step 9.10: Deploy Deployment of WordPress
1 |
Kubectl apply -f wordpress.yml |
Step 10: Access the WordPress application in the browser.
1 |
http://<master/worker instance public Ip address>:30050 |
Kubeadm is the right tool to bootstrap the Kubernetes cluster on your virtual machines. Kubeadm sets up a minimal viable cluster. It is designed to have all the components you need in one place in one cluster regardless of where you are running them. An advantage of kubeadm is that it can be used anywhere —even Raspberry Pi— to set up a cluster and try it out before committing to something like kops
CloudThat is the official AWS Advanced Consulting Partner, Microsoft Gold Partner, and Google Cloud Partner, helping people develop knowledge on the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
Feel free to drop a comment or any queries that you have regarding AWS services, Kubernetes Engine, or consulting requirements and we will get back to you quickly. To get started, go through our Expert Advisory page and Managed Services Package that is CloudThat’s offerings.
ANS: Both are Designed for testing, research, and learning. Minikube is a fast and straightforward solution for deploying a single-node Kubernetes cluster, but it is not a minimum viable solution and production-ready cluster. According to Kubeadm, it is a minimum viable and production-ready cluster and allows us to choose the runtime environment, although it has a docker by default.
ANS: It is highly necessary to disable memory swap before creating a kubeadm cluster. Because the scheduler in Kubernetes chooses the best node to deploy the newly provisioned resources like pods. If the swapping is allowed that leads to stability and performance issues in the Kubernetes cluster.
Voiced by Amazon Polly |
Karthik Kumar Patro Voona is a Research Associate (Kubernetes) at CloudThat Technologies. He Holds Bachelor's degree in Information and Technology and has good programming knowledge of Python. He has experience in both AWS and Azure. He has a passion for Cloud-computing and DevOps. He has good working experience in Kubernetes and DevOps Tools like Terraform, Ansible, and Jenkins. He is a very good Team player, Adaptive and interested in exploring new technologies.
Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!
Shivani Gandhi
May 27, 2022
Informative !!
swaraj santosh sirsat
May 26, 2022
great blog
Click to Comment