> For the complete documentation index, see [llms.txt](https://docs.neevcloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neevcloud.com/neevcloud-guide/kubernetes/deploy-wordpress-in-kubernetes..md).

# Deploy WordPress in Kubernetes.

Deploying WordPress on Kubernetes requires creating several resources, including Deployments, Services, Persistent-Volume-Claims, and MySQL database.

## WordPress in Kubernetes

## Prerequisite

You have to set the Kubernetes cluster to follow these [links](https://docs.neevcloud.com/neevcloud-products/kubernetes/launch-kubernetes-cluster)

### Accessing the Kubernetes Master Node

To access the master node in a Kubernetes cluster, follow these [LINK](/neevcloud-products/kubernetes/launch-kubernetes-cluster.md):

Open a terminal session.

Use the SSH protocol to connect:

```
ssh -i access_keuser@master-node-address
```

{% hint style="info" %}
Replace `user` with your username and `master-node-address` with the IP address or hostname of the master node.
{% endhint %}

Enter your password or authenticate with your SSH key when prompted.

Once connected, you can perform administrative tasks on the Kubernetes master node.

## Create WordPress Directory

To initiate the process of setting up WordPress, begin by creating a directory for WordPress files:

1. Open your terminal or command prompt and access the Kubernetes master node by  [SSH](/neevcloud-products/kubernetes/launch-kubernetes-cluster.md) and [kubeconfig-file](https://youtu.be/08rXIjTFefs?si=bAW0gxoDdjAcMTB1).
2. Navigate to the Kubernetes Master node where you want to store your WordPress files.
3. Run the following command to create a new directory in the Kubernetes master node:

```
mkdir wordpress
```

This command creates a new folder named **WordPress** where you can proceed with the installation and configuration of your WordPress site.

Then navigate to the WordPress directory:

```bash
cd wordpress
```

To set up a web application using Kubernetes, you'll need to deploy both **MySQL** and **WordPress**. This setup involves creating three primary configuration files: a deployment file for MySQL, a PersistentVolumeClaim (PVC) for ensuring the database storage persists, and a deployment file for WordPress. Each component plays a critical role in ensuring your application is resilient, scalable, and has reliable storage.

### **WordPress Deployment YAML** (wordpress-deployment.yaml):

```
vi wordpress-deployment.yaml 
```

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - name: wordpress
        image: wordpress:latest
        ports:
        - containerPort: 80
        env:
        - name: WORDPRESS_DB_HOST
          value: mysql-service
        - name: WORDPRESS_DB_USER
          value: root
        - name: WORDPRESS_DB_PASSWORD
          value: Password123@#@!
        - name: WORDPRESS_DB_NAME
          value: wordpress_db
---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
spec:
  selector:
    app: wordpress
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer
```

Ensure you replace placeholder values like your\_db\_user, your\_db\_password, your\_db\_name, and your\_mysql\_root\_password with appropriate values for your setup.

{% code fullWidth="false" %}

```

Note: To access WordPress in the browser, we are utilizing a LoadBalancer service type.

```

{% endcode %}

### **MySQL Deployment YAML** (mysql-deployment.yaml):

```
vi mysql-deployment.yaml
```

```
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  selector:
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:latest
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: Password123@#@!
        - name: MYSQL_DATABASE
          value: wordpress_db

```

Ensure you replace placeholder values like your\_db\_user, your\_db\_password, your\_db\_name, and your\_mysql\_root\_password with appropriate values for your setup.

### **PersistentVolumeClaim YAML** (persistent-volume-claim.yaml):

```
vi persistent-volume-claim.yaml
```

```
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wordpress-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
```

### Apply the YAML file to create the WordPress

You can apply these YAML files to your Kubernetes cluster using the **kubectl apply -f** command. For example:

```
kubectl apply -f wordpress-deployment.yaml 
```

```
kubectl apply -f mysql-deployment.yaml 
```

```
kubectl apply -f persistent-volume-claim.yaml
```

Ensure you replace placeholder values like your\_db\_user, your\_db\_password, your\_db\_name, and your\_mysql\_root\_password with appropriate values for your setup.

This configuration sets up WordPress with a MySQL database backend and a LoadBalancer service for external access to WordPress. Adjustments may be necessary depending on your specific requirements and environment.

To find your external IP address, open your web browser.

<figure><img src="/files/zyyvtSP0ZjSjK77O025b" alt=""><figcaption></figcaption></figure>

{% embed url="http\://external\_ip" %}

<figure><img src="/files/jZWq64B59ijORUNqZ9QF" alt=""><figcaption></figcaption></figure>
