Link Search Menu Expand Document

Deploying WordPress

In this tutorial you will learn how to deploy WordPress which is one of the most used content management systems in the industry.

WordPress

Prerequirements

  • Playground tools are installed (kubectl & playground)
  • A napptive-kubeconfig file is available
$ playground login
Login success

Deploying the application

WordPress is an application composed of two main components: a database, and the WordPress frontend. To deploy WordPress save the contents of the following files:

010.mysql.component.yaml

apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: mysql-db
spec:
  workload:
    apiVersion: core.oam.dev/v1alpha2
    kind: ContainerizedWorkload
    metadata:
      name: mysql-db
    spec:
      osType: linux
      containers:
        - name: mysql
          securityContext:
            runAsUser: 1001
          image: mysql:5.7
          imagePullPolicy: IfNotPresent
          resources:
            cpu:
              required: 150m
            memory:
              required: 256Mi
          ports:
            - name: port
              value: 3306
              containerPort: 3306
              type: tcp
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: ""
  parameters:
    - name: password
      required: true
      fieldPaths:
        - "spec.containers[0].env[0].value"
    - name: portNumber
      required: false
      fieldPaths:
        - "spec.containers[0].ports[0].value"
        - "spec.containers[0].ports[0].containerPort"

020.wordpress.component.yaml

apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: wordpress
spec:
  workload:
    apiVersion: core.oam.dev/v1alpha2
    kind: ContainerizedWorkload
    metadata:
      name: wordpress
    spec:
      osType: linux
      containers:
        - name: wordpress
          securityContext:
            runAsUser: 1001
          image: bitnami/wordpress:5
          imagePullPolicy: IfNotPresent
          resources:
            cpu:
              required: 150m
            memory:
              required: 256Mi
          ports:
            - containerPort: 8080
              name: wordpressport
              protocol: TCP
          env:
            - name: MARIADB_HOST
              value: ""
            - name: WORDPRESS_DATABASE_PASSWORD
              value: ""
            - name: WORDPRESS_DATABASE_USER
              value: "root"
            - name: WORDPRESS_DATABASE_NAME
              value: "bitnami_wordpress"
            - name: MYSQL_CLIENT_CREATE_DATABASE_NAME
              value: "bitnami_wordpress"
            - name: MYSQL_CLIENT_CREATE_DATABASE_USER
              value: "root"
            - name: MYSQL_CLIENT_CREATE_DATABASE_PASSWORD
              value: ""
            - name: MARIADB_ROOT_PASSWORD
              value: ""
  parameters:
    - name: host
      required: true
      fieldPaths:
        - "spec.containers[0].env[0].value"
    - name: dbpass
      required: true
      fieldPaths:
        - "spec.containers[0].env[1].value"
        - "spec.containers[0].env[6].value"
        - "spec.containers[0].env[7].value"

030.healthscope.yaml

apiVersion: core.oam.dev/v1alpha2
kind: HealthScope
metadata:
  name: wordpress-health
spec:
  workloadRefs: []

040.wordpress.appconfig.yaml

apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
  name: my-wordpress
  annotations:
    version: v1.0.0
    description: "Customized version of wordpress-mysql"
spec:
  components:
    - componentName: mysql-db
      parameterValues:
        - name: password
          value: "root"
        - name: portNumber
          value: 3306
      scopes:
        - scopeRef:
            apiVersion: core.oam.dev/v1alpha2
            kind: HealthScope
            name: wordpress-health
    - componentName: wordpress
      parameterValues:
        - name: dbpass
          value: "root"
        - name: host
          value: "mysql-db"
      traits:
        - trait:
            apiVersion: core.napptive.com/v1alpha1
            kind: Ingress
            metadata:
              name: wp-ingress
            spec:
              name: wordpress
              protocol: HTTP
              port: 8080
              path: /
              rewritePath: /
        - trait:
            apiVersion: core.oam.dev/v1alpha2
            kind: ManualScalerTrait
            metadata:
              name: wordpress-replication
            spec:
              replicaCount: 1
      scopes:
        - scopeRef:
            apiVersion: core.oam.dev/v1alpha2
            kind: HealthScope
            name: wordpress-health

After all files are saved, the simplest way to deploy the application is executing:

$ playground apps deploy <path_to_wordpress_files>
STATUS     INFO
SUCCESS    application [my-wordpress] deployed

CREATED
core.oam.dev/v1alpha2, Kind=Component "wordpress" created
core.oam.dev/v1alpha2, Kind=HealthScope "wordpress-health" created
core.oam.dev/v1alpha2, Kind=Component "mysql-db" created
core.oam.dev/v1alpha2, Kind=ApplicationConfiguration "my-wordpress" created

$ playground apps
NAME      STATUS
my-wordpress    APP_OK

On the web interface, you will see the app is now ready, and you can easily explore what is doing and the cluster usage.

Wordpress deployed

To connect to the web interface, check the created ingresses:

$ playground app info my-wordpress
NAME            STATUS
my-wordpress    APP_OK

COMPONENT    STATUS    SCOPES    TRAITS
mysql-db     OK
wordpress    OK                  wp-ingress, wordpress-replication

COMPONENT    INGRESSES
wordpress    wordpress-<your_username>.apps.staging.napptive.dev

And connect to the ingress listed above.

To connect to the wordpress admin page, go to https:// wordpress-<your_username>.apps.playground.napptive.dev/admin and use the following credentials:

user: user@example.com
password: bitnami

Other tutorials