How to deploy a functioning WordPress web page in 30 minutes

Clarusway
8 min readDec 22, 2021

How to deploy a functioning WordPress web page in 30 minutes

This the last article of 2021.

You have just decided to launch your first WordPress web page and attach a MySQL data base, but you don’t know where to start? This is your lucky day. Here is all you need to know. I promise, 30 minutes is not a long time, and you will have 3 breaks during the installation.

Warning: this task uses a lot of highly toxic current DevOps technologies such as AWS EC2, Terraform, Bash Script, Docker, Rancher, Kubernetes, AWS EKS, etc.

Thistask is to deploy Kubernetes cluster on AWS EKS using Rancher. Rancher container will run on an AWS EC2 instance. For provisioning rancher server, we will use infrastructure as code, Terraform.

Breakdown of the task in hand:

1- Provisioning ec2 instance for rancher server with terraform.

2- Install docker, docker compose, kubectl, rancher etc using user data with terraform.

3- Provision eks cluster, kubernetes infrastructure using rancher user interface.

4- Deploy wordpress, deploy mysql data base, deploy and mount persistent volume using rancher user interface command line

Short notes before start:

1- ec2 must have sufficient resources to run rancher. min 2 vcpus and 8 gb ram required. (t2.large or a larger ec2 instance.)

2- We will tag the ec2 name as rancher.

3- According to rancher documentation (https://rancher.com/docs/rancher/v2.5/en/installation/) current terminology is as follows:

- The Rancher server manages and provisions Kubernetes clusters. You can interact with downstream Kubernetes clusters through the Rancher server’s user interface.

- RKE (Rancher Kubernetes Engine) is a certified Kubernetes distribution and CLI/library which creates and manages a Kubernetes cluster.

- K3s (Lightweight Kubernetes) is also a fully compliant Kubernetes distribution. It is newer than RKE, easier to use, and more lightweight, with a binary size of less than 100 MB.

- RKE2 is a fully conformant Kubernetes distribution that focuses on security and compliance within the U.S. Federal Government sector.

- RancherD is a new tool for installing Rancher, which is available as of Rancher v2.5.4. It is an experimental feature. RancherD is a single binary that first launches an RKE2 Kubernetes cluster, then installs the Rancher server Helm chart on the cluster.

4- According to rancher documentation web page, rancher v2.x described as:

- Rancher was originally built to work with multiple orchestrators, and it included its own orchestrator called Cattle. With the rise of Kubernetes in the marketplace, Rancher 2 exclusively deploys and manages Kubernetes clusters running anywhere, on any provider.

- Rancher can provision Kubernetes from a hosted provider, provision compute nodes and then install Kubernetes onto them, or import existing Kubernetes clusters running anywhere.

- One Rancher server installation can manage thousands of Kubernetes clusters and thousands of nodes from the same user interface.

- Rancher adds significant value on top of Kubernetes, first by centralizing authentication and role-based access control (RBAC) for all of the clusters, giving global admins the ability to control cluster access from one location.

- It then enables detailed monitoring and alerting for clusters and their resources, ships logs to external providers, and integrates directly with Helm via the Application Catalog. If you have an external CI/CD system, you can plug it into Rancher, but if you don’t, Rancher even includes Fleet to help you automatically deploy and upgrade workloads.

- Rancher is a complete container management platform for Kubernetes, giving you the tools to successfully run Kubernetes anywhere.

Now we are done with the rancher lecture let’s get on with the job

Create a folder.

$ mkdir rancher
$ cd rancher

Write the required terraform file for deploying ec2 instance which will run as rancher server

User data will install docker, docker compose, kubectl, rancher in the ec2.

$ vim user-data-rancher.sh

Run the script to provision infrastructure on aws with terraform.

$ terraform init
$ terraform fmt
$ terraform validate
$ terraform plan
$ terraform apply -auto-approve

As promised, you can now take your first break, or you can check out the vpc chart.

When you are back, copy the ip address and make ssh connection to the instance and see the hello world container run.

Once terraform script run and ec2 started, ec2 instance public ip will be displayed on your screen.

Copy and paste rancher server ec2 public ip address displayed on the screen to your internet browser you should see: (please also see screenshot 1 on github repo)

Howdy! Welcome to Rancher It looks like this is your first time visiting Rancher; if you pre-set your own bootstrap password, enter it here. Otherwise a random one has been generated for you. To find it: For a "docker run" installation: Find your container ID with docker ps, then run: docker logs container-id <container id> | grep "Bootstrap Password:" For a Helm installation, run: kubectl get secret - namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'

Few more notes to bear in mind when start using Rancher:

You can use your own password if you like. Rancher gives you default admin username as admin. You can then generate as many users as necessary from rancher user panel.

Once user credentials recorded you can start deploying kubernetes cluster using rancher.

We have k8s and k3s option. we are using latest image for rancher container therefore it should come up as k3s. k3s use less resources to do the same job.

Secrets, security and hardened kubernetes practices need to be considered.

Connect to ec 2 instance, and from ec2 command line:

$ docker ps

Copy container id, use the container id of rancher container for finding bootstrap password following command:

$ docker logs <container id> | grep "Bootstrap Password:"

Find the bootstrap password highlighted in red, which should look like:

gtvzw46prlwdtj0cwp67z4d8dlsv57tlm65cdd52f548nvhphw2dgx

And copy the password and paste the same to password section on the welcome to rancher page. and click “Log in with Local User”

At the next screen make sure to take copy and note the new password, and click continue and you should see screenshot 2.

Create a cluster using rancher control panel:

create, amazon eks, give cluster name (we have decided name the cluster as wp1), click labels&annotations, click add label, key=name, value=wp1, click account access, region eu-west-2, enter your amazon aws access key and secret key, click create, cluster options, add tag, key=name, value=rancher, configure network, click custom, select subnets, instance type t3.medium, node volume size 8 gb, node group name=wp1, desired asg size=1, maximum asg size=5, minimum asg size=1, click create.

Click wp1, click kubectl shell icon (top right hand side), when shell command line in the bottom window ready to use;

$ vi kustomization.yaml

Then paste the yaml files for kubernetes deployments of wordpress and mysql each as follows:

$ vi wordpress-deployment.yaml $ vi wordpress-deployment.yaml

Run the yaml files to deploy wordpress and mysql:

$ kubectl apply -k ./

Take your second break. When you are back at your desk, check the resources as follows:

$ kubectl get secrets
$ kubectl get pvc
$ kubectl get pods
$ kubectl get svc

Copy wordpress external ip from the services list on the screen and paste the same to internet browser and you should see screen shot 3. When prompted give a user name and password (see screenshot 4). Once you entered and saved credentials you should see the main page of wordpress as shown on screenshot 5.

Click workload, click pods, see wordpress and wordpress-mysql pods are running (screenshot 6) and continue as desired.

Remark: Please bear in mind that we have picked a minimal ec2 instance as rancher server therefore we have not been able to install monitoring. we are using 2 vcpus and 4 gib memory, if you want to install monitoring (prometheus, grafana) you would need to use bigger instances such as t2.2xlarge. If you have the bigger instance, You can follows: install monitoring, monitoring, install. and customise as rerquired.

Bonus: you can do the same using rancher control panel or you can use terraform scripts to deploy cluster and services. if you want to use rancher user interface, you can practise as follows:

Go to rancher control panel and click:

create, amazon eks, give cluster name, we have decided name the cluster as wp1, click labels&annotations, click add label, key=name, value=wp1, click account access, region eu-west-2, enter amazon aws access key and secret key, click create, cluster options, add tag, key=name, value=rancher, configure network, click custom, select subnets, instance type t3.medium, node volume size 8 gb, node group name=wp1, desired asg size=1, maximum asg size=5, minimum asg size=1, click create.

Now when you click home, click cluster namagement, click clusters, you should see two of them namely local and wp1.

Take your third break. Or, wait few minutes until state of the cluster changes to “provisioning”, “waiting”, and then to “active”, once cluster become active, click explore,

To run highly available service, you will need persistent volumes, make sure to create necessary number and size persistent volumes first and then you can go and create deployments along with persistent volume claims for each.

From home screen click cluster management,

wp1, explore, perojects/namespaces, create a project, name=wppg1, description=wordpress postgres 1, click create, go to wppg1, create namespace, name=dev, description=dev, create, click storage, persistentvolumes, click create, name=wppv1, description=wppv1, volume plucgin=hostpath, capacity=1, path on the node=/tmp/, the path on the node must be a directory or create if does not exist, click create, click storage, persistent volume claim, namescpace=dev, name=wppvc1, description=wordpress persistentvolumeclaim 1, use existing persistent volume, persistent volume, from pull down list wppv1, click create.

And then click

workload, deployments, create, namespace=dev, name=wppg1, description=worpress postgresql, replicas=1, general, standard container, contaner image=ntninja/wordpress-postgresql, pull policy=ifnotpresent, labels&annotations, add label, key=name, value=wppg1, storage, add volume, persistent volume claim, volume name=vol0, persistent volume claim=wppvc1, click create.

Finally, in order to avoid unnecessary cost destroy the resources.

1- On rancher command line

$ kubectl delete -k ./

2- Delete whatever resources deployed with rancher user panel from the rancher user panel.

3- From inside the rancher folder.

$ terraform destroy -auto-approve

I hope this task helps you boost your confidence around rancher user interface.

If you want see similar articles, please visit:

I wish 2022 brings happiness and prosperity to all.

Author:
M. Altun
17 December 2021, London
DevOps Engineer @ Finspire Technology

Originally published at https://ivymatt2017.medium.com on December 22, 2021.

--

--