Application Demo: WordPress

Demo application logo This tutorial explains how to run WordPress on APPUiO Cloud.

If you aren’t familiar with issuing commands on a terminal session, we recommend familiarizing yourself with it before continuing this tutorial.

Requirements

To follow this guide, please make sure that you have the following tools installed:

oc

You can download the OpenShift command directly from APPUiO Cloud, selecting the help menu (marked as a question mark) and selecting the "Command line tools" entry

About the Application

WordPress is the world’s most popular blogging and content management platform. Powerful yet simple, everyone from students to global corporations use it to build beautiful, functional websites.

Step 1: Create a Project

All the following steps are currently only working on the Exoscale APPUiO Zone because of the Application Catalog service availability.

Follow these steps to login to APPUiO Cloud on your terminal:

  1. Login to the APPUiO Cloud console:

    oc login --server=https://api.${zone}.appuio.cloud:6443

    You can find the exact URL of your chosen zone in the APPUiO Cloud Portal.

    This command displays a URL on your terminal:

    You must obtain an API token by visiting
    https://oauth-openshift.apps.${zone}.appuio.cloud/oauth/token/request
  2. Click on the link above and open it in your browser.

  3. Click "Display token" and copy the login command shown as "Log in with this token"

  4. Paste the oc login command on the terminal:

    oc login --token=sha256~_xxxxxx_xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxx-X \
        --server=https://api.${zone}.appuio.cloud:6443
  5. Create a new project called "[YOUR_USERNAME]-application-demo"

    oc new-project "[YOUR_USERNAME]-application-demo"

Step 2: Deploy the application

To deploy the application we will use standard Kubernetes objects. Save the example YAML Kubernetes resources into a file and apply it with oc apply -f <myfile.yaml>.

  1. First, we need a database:

    Database ordering from the VSHN Application Catalog
    apiVersion: exoscale.appcat.vshn.io/v1
    kind: ExoscaleMySQL
    metadata:
      name: example-app
    spec:
      writeConnectionSecretToRef:
        name: mysql-creds

    This will create a MySQL DBaaS instance with default settings. See the AppCat docs for more information.

  2. Then we deploy the application:

    Application deployment with all other needed resources
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: wordpress
      labels:
        app.kubernetes.io/name: demo-app
    spec:
      selector:
        matchLabels:
          app.kubernetes.io/name: demo-app
      replicas: 1
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app.kubernetes.io/name: demo-app
        spec:
          containers:
            - name: wordpress
              image: docker.io/bitnami/wordpress:latest
              imagePullPolicy: Always
              env:
                - name: WORDPRESS_DATABASE_HOST
                  valueFrom:
                    secretKeyRef:
                      name: mysql-creds
                      key: MYSQL_HOST
                - name: WORDPRESS_DATABASE_PORT_NUMBER
                  valueFrom:
                    secretKeyRef:
                      name: mysql-creds
                      key: MYSQL_PORT
                - name: WORDPRESS_DATABASE_NAME
                  valueFrom:
                    secretKeyRef:
                      name: mysql-creds
                      key: MYSQL_DB
                - name: WORDPRESS_DATABASE_USER
                  valueFrom:
                    secretKeyRef:
                      name: mysql-creds
                      key: MYSQL_USER
                - name: WORDPRESS_DATABASE_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: mysql-creds
                      key: MYSQL_PASSWORD
                - name: WORDPRESS_ENABLE_DATABASE_SSL
                  value: "yes"
                - name: WORDPRESS_DATABASE_SSL_CA_FILE
                  value: /srv/db-ca/ca.crt
                - name: WORDPRESS_ENABLE_HTTPS
                  value: "yes"
                - name: WORDPRESS_ENABLE_REVERSE_PROXY
                  value: "yes"
                - name: WORDPRESS_BLOG_NAME
                  value: "APPUiO Cloud Demo"
              ports:
                - name: web
                  containerPort: 8080
                  protocol: TCP
              resources:
                limits: {}
                requests: {}
              volumeMounts:
                - name: app-data
                  mountPath: /bitnami
                - name: db-ca
                  mountPath: /srv/db-ca
          volumes:
            - name: app-data
              persistentVolumeClaim:
                claimName: app-data
            - name: db-ca
              secret:
                secretName: mysql-creds
                optional: false
                items:
                  - key: ca.crt
                    path: ca.crt
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: example-app
      labels:
        app.kubernetes.io/name: demo-app
    spec:
      type: ClusterIP
      sessionAffinity: None
      ports:
        - name: web
          port: 443
          protocol: TCP
          targetPort: web
      selector:
        app.kubernetes.io/name: demo-app
    ---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: app-data
      labels:
        app.kubernetes.io/name: demo-app
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: "1Gi"
    ---
    apiVersion: route.openshift.io/v1
    kind: Route
    metadata:
      name: example-app
    spec:
      port:
        targetPort: web
      to:
        kind: Service
        name: example-app
        weight: 100
      wildcardPolicy: None
      tls:
        termination: edge
        insecureEdgeTerminationPolicy: Redirect
  3. Now wait until your pod appears with the status "Running":

    oc get pods --watch
  4. Last but not least retrieve the URL of your WordPress blog:

    oc get route example-app -o jsonpath='{.spec.host}'

You can now login to your WordPress instance on /wp-admin with the default credentials by the image:

  • Username: user

  • Password: bitnami

This example configuration isn’t meant for a production ready service.

What’s next?

For a production ready service, we recommend the following parts to be implemented and configured:

Especially for this example application:

  • Change the default username and password immediately.

  • Review the documentation of the used image to learn more about the configuration and possibilities.

  • WordPress needs a proper mail sending configuration in production, we recommend using a managed mail sending service for that, for example Mailgun.

Once you’re done evaluating this example application, cleanup again to not cause any unwanted costs:

oc delete project [YOUR_USERNAME]-application-demo
We’re happy to help you running your application. Contact us and let us know how we can help.