LAUNCING WORDPRESS ON THE TOP OF KUBERNETES CLUSTER (MINIKUBE) AND DATABASE ON THE TOP OF RDS ON AWS
Nishant Singh
Senior Software Engineer@HCL Tech | Red Hat Certified System Administrator | AWS Certified Solution Architect-Associate | AWS Certified Developer Associate | AWS Cloud Practitioner Certified
What is Cloud Computing?
Cloud computing is a term referred to storing and accessing data over the internet. It doesn't store any data on the hard disk of your personal computer. In cloud computing, you can access data from a remote server.
What is AWS?
Amazon web service is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions.
AWS is a comprehensive, easy to use computing platform offered Amazon. The platform is developed with a combination of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.
AWS is a public cloud which provides multiple services to multiple users. A public cloud is an external cloud over the internet that provide services to different users/tenants under the same cloud infrastructure.There are multiple services provided by AWS such as EC2, IAM, Cloudfront, S3, Global accelerator, Amazon SageMaker etc.
What is Terraform?
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
- terraform init (To install all the required plugins)
- terraform validate (To check the code)
- terraform plan (To see the complete detail which we want to create)
- terraform apply -auto-approve (To apply all the resources and run the code)
- terraform destroy -auto-approve (To delete all services initiated by terraform code in a single go)
What is Kubernetes?
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
The name Kubernetes originates from Greek, meaning helmsman or pilot. Google open-sourced the Kubernetes project in 2014. Kubernetes combines over 15 years of google's experience running production workloads at scale with best-of-breed ideas and practices from the community.
Why you need Kubernetes and what it can do?
Containers are a good way to bundle and run your applications. In a production environment, you need to manage the containers that run the applications and ensure that there is no downtime. For example, if a container goes down, another container needs to start.
Kubernetes provides you with:
1) Service discovery and load balancing
Kubernetes can expose a container using the DNS name or using their own IP address. If traffic to a container is high, Kubernetes is able to load balance and distribute the network traffic so that the deployment is stable.
2) Storage orchestration
Kubernetes allows you to automatically mount a storage system of your choice, such as local storages, public cloud providers, and more.
3) Automated rollouts and rollbacks
You can describe the desired state for your deployed containers using Kubernetes, and it can change the actual state to the desired state at a controlled rate. For example, you can automate Kubernetes to create new containers for your deployment, remove existing containers and adopt all their resources to the new container.
4) Automatic bin packing
You provide Kubernetes with a cluster of nodes that it can use to run containerized tasks. You tell Kubernetes how much CPU and memory (RAM) each container needs. Kubernetes can fit containers onto your nodes to make the best use of your resources.
5) Self-healing
Kubernetes restarts containers that fail, replaces containers, kills containers that don’t respond to your user-defined health check, and doesn’t advertise them to clients until they are ready to serve.
6) Secret and configuration management
Kubernetes lets you store and manage sensitive information, such as passwords, OAuth tokens, and SSH keys. You can deploy and update secrets and application configuration without rebuilding your container images, and without exposing secrets in your stack configuration.
What is AWS RDS ?
Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.
Problem Statement:
Deploy the Wordpress application on Kubernetes and AWS using terraform including the following steps;
1. Write an Infrastructure as code using terraform, which automatically deploy the Wordpress application
2. On AWS, use RDS service for the relational database for Wordpress application.
3. Deploy the Wordpress as a container either on top of Minikube or EKS or Fargate service on AWS
4. The Wordpress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.
Solution:
Before going to the solution firstly we have to configure the aws profile. We can configure the aws profile by typing aws configure command in cmd. In my case, I already configure my aws profile but you can configure your profile with the help of access key and secret key.
Create the terraform code which launch the wordpress deployment on kubernetes cluster (Minikube- Single Node Cluster) :
Note: For the complete process you have to setup and install minikube in your system.
provider "kubernetes" { config_context_cluster = "minikube" } resource "kubernetes_deployment" "task6" { metadata { name = "mywp" } spec { replicas = 5 selector { match_labels = { env="production" app="wordpress" } } template { metadata { labels = { env="production" app="wordpress" } } spec { container { image = "wordpress" name = "mywp-os" } } } } } resource "kubernetes_service" "ldbalancer" { metadata { name = "ldbalancer" } spec { selector = { env="production" app="wordpress" } port { node_port = 31000 port = 80 target_port = 80 } type = "NodePort" } }
Before create this terraform code, First we initialize the terraform plugins for kubernetes
terraform init
Secondly we have to validate the code
terraform validate
We have to check the plan
terraform plan
Now we apply the code by typing this command
terraform apply
Now when we apply this code by typing terraform apply it will create a deployment on minikube and also expose it. Now check from cmd that deployment is running.
Creating the mysql database instance on RDS on AWS:
provider "aws" { region = "ap-south-1" profile = "nishant" } resource "aws_db_instance" "mydb" { storage_type = "gp2" allocated_storage = 10 engine = "mysql" engine_version = "5.7" instance_class = "db.t2.micro" name = "RDS" username = "nishantsingh" password = "redhat123" port = "3306" parameter_group_name = "default.mysql5.7" iam_database_authentication_enabled = true publicly_accessible = true skip_final_snapshot = true tags = { Name = "mydb" } }
Before create this terraform code, First we initialize the terraform plugins for AWS.
terraform init
Now we have to validate the code
terraform validate
We have to check the plan
terraform plan
Now we apply the code by typing this command
terraform apply
Now when we apply this code by typing terraform apply it will create the mysql database for running wordpress deployment.
Now we can access the wordpress by typing minikube ip and Node Port exposed port.
Finally I deployed wordpress pod on Minikube and mysql on RDS (AWS) successfully.
Github Link:
Thanks For Reading!!!
Revenue Sub Inspector (GoUP)
4 年Great !