Deploy a WordPress Web Application

    • You need to create a MySQL StatefulSet, see the Deploy a MySQL Application if not yet.
    • You need to sign in with and enter into the corresponding project.

    About 15 minutes.

    Step 1: Create a ConfigMap

    1.1. Enter the project, navigate to Configuration Center → ConfigMaps, then choose Create ConfigMap.

    1.2. Fill in the basic information, e.g. Name : wordpress-configmap. Then choose Next when you’re done.

    basic information

    1.3. ConfigMap parameter is composed of a set of key-value pairs, fill in the blanks with the following values and select Create.

    • key: WORDPRESS_DB_PASSWORD
    • value: 123456

    Step 2: Create a Volume

    2.1. Navigate to Volumes, and click Create. Then fill in the basic information, e.g. Name : wordpress-pvc, choose Next when you’re done.

    2.2. Volume settings depends on your storage class configuration, local volume is set to the default storage class if used all-in-one installation, its volume settings as below screenshot:

    Volume settings

    2.3. We simply keep the default label settings as app: wordpress-pvc, then choose Create.

    2.4. when you redirect to the Volumes list, you will be able to see the volume wordpress-pvc has been created successfully.

    Step 3: Create a Deployment

    Navigate to Workloads → Deployments, then click Create.

    Create a Deployment

    Step 4: Basic Information

    Fill in the basic information, e.g. Name : wordpress. Then choose Next when you’re done.

    Step 5: Pod Template

    5.1. Click Add Container, Container Name can be customized by the user, fill in the image with wordpress:4.8-apache, leave the CPU and Memory at their default values. Click Advanced Options.

    Add Container

    5.2. We’ll simply set the Ports and Environmental Variables according to the following hints.

    • Ports:

      • Name: Port
      • Protocol: TCP
      • Port: 80
    • Environmental Variables (It requires to create 2 environmental variables in this section)

      • Choose Reference Config Center
      • Fill in the name with WORDPRESS_DB_PASSWORD
      • Select resource: select wordpress-configmap
      • Select Key: WORDPRESS_DB_PASSWORD

    Then select Add Environmental Variable, and fill in the name/value:

    • Value: mysql-service

    Choose Save when you’re done.

    5.3. No need to modify the Replicas and Horizontal Pod Autoscaling, For Update Strategy you can keep which is a recommended strategy. Then click Next.

    Step 6: Volume Settings

    6.1. Choose Add Existing Volume, select the wordpress-pvc which was created in Step 2.

    6.2. Set the Mount Path to /var/www/html and select ReadAndWrite. Then click Save and select Next when you’re done.

    Volume Settings

    Step 7: View the Deployment

    7.1. We simply keep the default label settings as app: wordpress. There is no need to set Node Selector in this demo, you can choose Create directly.

    7.2. You will be able to see the WordPress Deployment displays “updating” since this process requires a series of operations such as pulling a Docker image of the specified tag, creating a container, and connecting the MySQL database. Normally, it will change to “running” at around 1 min.

    Step 8: Create a Service

    8.1. Navigate to Network & ServiceService, choose Create.

    Create a Service

    8.2. Fill in the basic information, e.g. Name : wordpress-service. Then choose Next when you’re done.

    8.3. Reference the following information to complete the Service Settings:

    • Service Type: choose the first item (Virtual IP: Access the service through the internal IP of the cluster)
    • Selector: Click Specify Workload, then select wordpress and click Save.
    • Ports:

      • Name: nodeport
      • Protocol: TCP
      • Port: 80
      • Target port: 80
    • Session Affinity: None.

    service-setting

    8.4. We simply keep the default label settings as app: wordpress-service, then choose Next.

    8.5. We are going to expose this service via Route (Ingress), so leave the Access Method at None. Then click Create, the wordpress-service has been created successfully.

    Step 9: Create a Route

    9.1. Navigate to Network & ServiceRoutes and choose Create Route.

    9.2. Fill in the basic information, e.g. Name: wordpress-ingress, click Next when you’re done.

    Basic information

    9.3. Choose Add Route Rule, set the Route Rule according to the following hints:

    • Hostname:it can be customized by user, e.g. wordpress.demo.io, wordpress service will be accessed via this hostname.
    • Protocol:select (if select https please create the related certificates in secrets)
    • Paths:

      • Path: enter /
      • Service: choose wordpress-service

    9.4. Add a line of record ({$EIP} {$hostname}) to the your local hosts file. For example, if the EIP of your KubeSphere is 139.198.16.160 and the hostname has been set to wordpress.demo.io, then we need to add a line of record to /etc/hosts as following:

    9.5. Skip the Annotation, then keep the default label settings as app: wordpress-ingress.

    9.6. Click Create, the wordpress-ingress will be created successfully.

    Created successfully

    Step 10: Configure the Gateway

    10.1. Navigate to Project-Settings → Internet Access, then click Set Gateway.

    10.2. Make sure the Access Method is set to NodePort, then choose Save.

    10.3. It will generate 2 node ports, represent http and https respectively, e.g. 31499 and 32646.

    Node ports

    Access the WordPress service

    At this point, WordPress is exposed to the outside by the Ingress, thus we can access it in your browser via {$hostname}:{$NodePort} i.e. since we selected http protocol previously.

    Hope you could be familiar with the basic features of Deployments and StatefulSets right now, see the and StatefulSets for the details.