{"id":12264,"date":"2022-05-26T07:41:19","date_gmt":"2022-05-26T07:41:19","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=12264"},"modified":"2024-06-25T10:59:51","modified_gmt":"2024-06-25T10:59:51","slug":"deploying-wordpress-application-kubernetes-cluster-using-kubeadm-tool-aws-ec2-instances","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/deploying-a-wordpress-application-in-kubernetes-cluster-using-kubeadm-tool-in-aws-ec2-instances","title":{"rendered":"Deploying A WordPress Application In Kubernetes Cluster Using Kubeadm Tool In AWS EC2 Instances"},"content":{"rendered":"<table style=\"height: 255px;\" border=\"3\" width=\"391\">\n<tbody>\n<tr>\n<td>\n<h2><span style=\"color: #000080;\"><strong>TABLE OF CONTENT<\/strong><\/span><\/h2>\n<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#introduction\">1. Introduction<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#deploymentarchitecture\">2. Deployment Architecture <\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#prerequisites\">3. Prerequisites<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#kubernetescomponents \">4. Kubernetes Components Leveraged<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#overview\">5. A Brief Overview of the steps involved<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#stepbystepguide\">6. Step-by-Step Guide<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#conclusion\">7. Conclusion <\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#aboutcloudthat\">8. About CloudThat <\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#faqs\">9. FAQs<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"introduction\"><strong>1. Introduction<\/strong><\/h2>\n<p>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.<\/p>\n<p>Here, I am developing a cluster that gives us complete control over the nodes.<\/p>\n<h2 id=\"deploymentarchitecture\"><strong>2. Deployment Architecture<\/strong><\/h2>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12267\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube1.png\" alt=\"Kubernetes Architecture\" width=\"991\" height=\"923\" \/><\/a><\/p>\n<h3 id=\"prerequisites\"><strong>3. Perquisites:<\/strong><\/h3>\n<p>To Deploy a WordPress application in Kubernetes, you will need the following:<\/p>\n<ul>\n<li>An AWS account<\/li>\n<li>Kubeadm Tool<\/li>\n<li>Calico Network plugin<\/li>\n<li>Docker<\/li>\n<\/ul>\n<h3 id=\"kubernetescomponents\"><strong>4. Kubernetes Components Leveraged:<\/strong><\/h3>\n<ul>\n<li>Deployment<\/li>\n<li>Stateful set<\/li>\n<li>Services<\/li>\n<li>Secrets<\/li>\n<li>Volumes<\/li>\n<li>3 EC2 instances: One master node, two worker nodes<\/li>\n<\/ul>\n<h2 id=\"overview\"><strong>5. A brief overview of the steps involved:<\/strong><\/h2>\n<ol>\n<li>Launching three instances<\/li>\n<li>Setup kubeadm cluster<\/li>\n<li>Joining the worker nodes with the master node<\/li>\n<li>Deploying WordPress application<\/li>\n<\/ol>\n<h2 id=\"stepbystepguide\"><strong>6. Step-by-Step Guide<\/strong><\/h2>\n<p>Step 1: Create three instances of t3.medium running ubuntu 20.14 in the AWS console in any region.<\/p>\n<p>Step 2: Add the security group Kubernetes-related port number and calico port number<\/p>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12268\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube2.png\" alt=\"Kubeadm tool\" width=\"632\" height=\"85\" \/><\/a><\/p>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12269\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube3.png\" alt=\"Kubeadm tool\" width=\"587\" height=\"349\" \/><\/a><\/p>\n<p>Step 3: Tag one Instance as a Master node,<\/p>\n<p>Remaining instances as worker one and worker two nodes.<\/p>\n<p>SSH into the master and worker instance and Run the following commands.<\/p>\n<p><strong>#REMOVE OLD DOCKER<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo apt-get remove docker docker-engine docker.io contained runs<\/pre>\n<p><strong>#INSTALL DOCKER PRE-REQUISITES<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo apt-get update\r\nsudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release<\/pre>\n<p><strong>#ADD GPG KEY<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo gpg --dearmor -o \/usr\/share\/keyrings\/docker-archive-keyring.gpg\r\necho \\\r\n  \"deb [arch=amd64 signed-by=\/usr\/share\/keyrings\/docker-archive-keyring.gpg] https:\/\/download.docker.com\/linux\/ubuntu \\\r\n  $(lsb_release -cs) stable\" | sudo tee \/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null\r\n<\/pre>\n<p><strong>#INSTALL DOCKER ENGINE<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo apt-get update\r\nsudo apt-get install -y docker-ce docker-ce-cli containerd.io\r\nsudo docker run hello-world\r\ncat &lt;&lt;EOF | sudo tee \/etc\/modules-load.d\/k8s.conf\r\noverlay\r\nbr_netfilter\r\nEOF\r\n<\/pre>\n<p><strong># Restart nodes to load them the br_netfilter and overlay<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo modprobe overlay\r\nsudo modprobe br_netfilter<\/pre>\n<p><strong>#ALLOW BRIDGED TRAFFIC FOR KUBEADM<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">cat &lt;&lt;EOF | sudo tee \/etc\/sysctl.d\/k8s.conf\r\nnet.bridge.bridge-nf-call-ip6tables = 1\r\nnet.bridge.bridge-nf-call-iptables = 1\r\nEOF\r\nsudo sysctl --system<\/pre>\n<p><strong>#INSTALL K8S PRE-REQUISITES<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo apt-get update\r\nsudo apt-get install -y apt-transport-https ca-certificates curl<\/pre>\n<p><strong>#DOWNLOAD GOOGLE CLOUD PUBLIC SIGNINIG KEY<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo curl -fsSLo \/usr\/share\/keyrings\/kubernetes-archive-keyring.gpg\r\nhttps:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg<\/pre>\n<p><strong># ADD K8S APT REPO<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">echo \"deb [signed-by=\/usr\/share\/keyrings\/kubernetes-archive-keyring.gpg] \r\nhttps:\/\/apt.kubernetes.io\/ kubernetes-xenial main\" | sudo tee \r\n\/etc\/apt\/sources.list.d\/kubernetes.list<\/pre>\n<p><strong># INSTALL K8S COMPONENTS<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo apt-get update\r\n sudo apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00\r\nsudo apt-mark hold kubelet kubeadm kubectl\r\nkubectl taint nodes --all node-role.kubernetes.io\/master-\r\nsudo touch \/etc\/docker\/daemon.json\r\ncat &lt;&lt;EOF | sudo tee \/etc\/docker\/daemon.json\r\n{\r\n        \"exec-opts\": [\"native.cgroupdriver=systemd\"]\r\n}\r\nEOF\r\nsudo swapoff \u2013a      #to disable the swapping \r\nsudo sed -i '\/ swap \/ s\/^\/#\/' \/etc\/fstab      # To persist the swap disable\r\n<\/pre>\n<p><strong>#init <\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">sudo systemctl daemon-reload\r\nsudo systemctl restart docker<\/pre>\n<p>Step 4: On the Master, node instance, follow the below commands to Initiate the Kubeadm, generate the token and Install Calico network plugin.<\/p>\n<p><strong>#Kubeadm init<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">kubeadm init --pod-network-cidr=10.244.0.0\/16 --ignore-preflight-errors=all\r\nexport KUBECONFIG=\/etc\/kubernetes\/admin.conf\r\nsudo cp \/etc\/kubernetes\/admin.conf $HOME\/admin.conf\r\nsudo chown $(id -u):$(id -g) $HOME\/admin.conf<\/pre>\n<p><strong>#Generate Token<\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">token=$(kubeadm token generate)\r\nrm -f home\/ubuntu\/nodes-join-token.out\r\nkubeadm token create $token --print-join-command --ttl=0 &gt; \/home\/ubuntu\/nodes-join-token.out\r\ncat \/home\/ubuntu\/nodes-join-token.out<\/pre>\n<p><strong>#Install calico networking <\/strong><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">kubectl apply -f https:\/\/docs.projectcalico.org\/manifests\/calico.yaml\r\nkubectl get cs\r\nkubectl get components tatus\r\nkubectl cluster-info\r\nkubectl get pods -n kube-system\r\n\r\nmv $HOME\/.kube $OME\/.kube.bak\r\nmkdir $HOME\/.kube\r\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\r\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config\r\nsudo systemctl restart docker.service\r\nsudo systemctl enable docker.service\r\nsudo service kubelet restart<\/pre>\n<p>Step 5: A file is created in the master node named \u201cnodes-join-token\u201d. Open it and copy the token<\/p>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12270\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube4.png\" alt=\"Kubeadm tool\" width=\"602\" height=\"75\" \/><\/a><\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Cat nodes-join-token<\/pre>\n<p>Step 6: Past the token in both the worker nodes to join them into the cluster.<\/p>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12272\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube5.png\" alt=\"Kubeadm tool\" width=\"506\" height=\"164\" \/><\/a><\/p>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12271\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube6.png\" alt=\"Kubeadm tool\" width=\"424\" height=\"198\" \/><\/a><\/p>\n<p>Step 7: After the above step, run the below command in the master node to verify whether nodes are joined.<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">$:-Kubectl gets nodes<\/pre>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12273\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube7.png\" alt=\"Kubeadm tool\" width=\"602\" height=\"78\" \/><\/a><\/p>\n<p><strong>Successfully created Kubernetes Cluster using Kubeadm.<\/strong><\/p>\n<p>Step 8: SSH into the master node and execute the below code To Download the WordPress application.<\/p>\n<p>#Install GIt<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Sudo apt-get install git-all<\/pre>\n<p>#make a directory<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">mkdir \/home\/ubuntu\/Kubernetes \r\ncd \/home\/ubuntu\/Kubernetes \r\ngit init\r\ngit remote add kube https:\/\/github.com\/v-karthik-kumar\/kubernetes-karthik.git\r\ngit pull kube master<\/pre>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12274\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube8.png\" alt=\"Kubeadm tool\" width=\"602\" height=\"150\" \/><\/a><\/p>\n<p>Step 9: Deploy yaml code in a sequence on the master nodes.<\/p>\n<p>Step 9.1: Go to the Kubernetes directory<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Cd \/home\/ubuntu\/Kubernetes<\/pre>\n<p>Step 9.2: Deploy persistent volume for MySQL<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f pvMysql.yml<\/pre>\n<p>Step 9.3: Deploy persistent volume claim for MySQL<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f  pvcMysql.yml<\/pre>\n<p>Step 9.4: Deploy service for MySQL<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f mysql-svc.yml<\/pre>\n<p>Step 9.5: Deploy secrets<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f  secret.yml<\/pre>\n<p>Step 9.6: Deploy Deployment of mysql<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f  mysql.yml<\/pre>\n<p>Step 9.7: Deploy persistent volume for WordPress<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f  pvWordpress.yml<\/pre>\n<p>Step 9.8: Deploy persistent volume claim for WordPress<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true\">Kubectl apply -f  pvcWordpress.yml<\/pre>\n<p>Step 9.9: Deploy service for WordPress<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f wordpress-svc.yml<\/pre>\n<p>Step 9.10: Deploy Deployment of WordPress<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">Kubectl apply -f  wordpress.yml<\/pre>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12275\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube9.png\" alt=\"Kubeadm tool\" width=\"602\" height=\"257\" \/><\/a><\/p>\n<p>Step 10: Access the WordPress application in the browser.<\/p>\n<pre class=\"nums:false nums-toggle:false lang:default decode:true \">http:\/\/&lt;master\/worker instance public Ip address&gt;:30050<\/pre>\n<h3><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12276\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/kube10.png\" alt=\"Kubeadm tool\" width=\"602\" height=\"278\" \/><\/a><\/h3>\n<h3 id=\"conclusion\"><strong>7. Conclusion:<\/strong><\/h3>\n<p>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 \u2014even Raspberry Pi\u2014 to set up a cluster and try it out before committing to something like kops<\/p>\n<h3 id=\"aboutcloudthat\"><strong>8. About CloudThat<\/strong><\/h3>\n<p><a href=\"https:\/\/www.cloudthat.com\/\"><strong>CloudThat<\/strong>\u00a0<\/a>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\u00a0a robust\u00a0cloud computing ecosystem by disseminating\u00a0knowledge on technological intricacies within the cloud space.\u00a0Our blogs, webinars,\u00a0case studies, and white papers\u00a0enable all the stakeholders in the cloud computing sphere.<\/p>\n<p>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\u00a0our\u00a0<a href=\"https:\/\/www.cloudthat.com\/expert-advisory\/?utm_source=blog-website&amp;utm-medium=text-link&amp;utm_campaign=expert-advisory\"><strong>Expert Advisory\u00a0<\/strong><\/a>page\u00a0and\u00a0<a href=\"https:\/\/www.cloudthat.com\/managed-services-packages\/\"><strong>Managed Services Package<\/strong><\/a><strong>\u00a0<\/strong>that is\u00a0<a href=\"https:\/\/cloudthat.com\/?utm_source=blog-website&amp;utm-medium=text-link&amp;utm_campaign=cloudthat.com\/\"><strong>CloudThat<\/strong><\/a><strong>\u2019s<\/strong>\u00a0offerings.<\/p>\n<h3 id=\"faqs\"><strong>9. FAQs:<\/strong><\/h3>\n<ol>\n<li>\n<h3><strong>What is the difference between minikube and kubeadm?<\/strong><\/h3>\n<\/li>\n<\/ol>\n<p>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.<\/p>\n<ol start=\"2\">\n<li>\n<h3><strong>Why is it needed to disable the memory swapping while installing the Kubernetes cluster?<\/strong><\/h3>\n<\/li>\n<\/ol>\n<p>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.<\/p>\n","protected":false},"author":299,"featured_media":12459,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607,5388],"user_email":"karthikv@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12264"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/299"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=12264"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12264\/revisions"}],"predecessor-version":[{"id":46029,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12264\/revisions\/46029"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=12264"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=12264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}