Updated on 2024-09-29 GMT+08:00

Deploying WordPress Using Helm

Helm is a package manager that streamlines the deployment, upgrade, and management of Kubernetes applications. Helm uses charts (a packaging format that defines Kubernetes resources) to encapsulate all elements deployed by Kubernetes, including application code, dependencies, configuration files, and deployment instructions. With Helm, you can easily deploy and manage complex Kubernetes applications, simplifying application development and deployment.

This section describes how to deploy a WordPress workload using Helm.

Prerequisites

You have created a CCE cluster that contains at least one node with 4 vCPUs and 8 GiB memory. The node is bound with an EIP for pulling the WordPress images from an external repository. For details on how to create a cluster, see Creating a Kubernetes Cluster.

Preparations

  1. Download and configure kubectl to access the cluster.

    Log in to the CCE console and click the target cluster name to access the cluster console. In the Connection Information area of the Overview page, click Configure next to kubectl and configure kubectl as instructed.

    Figure 1 kubectl
  2. Install Helm 3.

Deploying WordPress

  1. Add the official WordPress repository.

    helm repo add bitnami https://charts.bitnami.com/bitnami

  2. Run the following commands to create a WordPress workload:

    helm install myblog bitnami/wordpress \
        --set mariadb.primary.persistence.enabled=true \
        --set mariadb.primary.persistence.storageClass=csi-disk \
        --set mariadb.primary.persistence.size=10Gi \
        --set persistence.enabled=false
    • MariaDB uses persistent volumes (PVs) to store data. The PV is automatically created with an EVS disk of 10 GiB by configuring StorageClassName.
    • Data persistence is not required for WordPress. Set persistence.enabled to false for the data volume.

    Information similar to the following is displayed:

    coalesce.go:223: warning: destination for mariadb.networkPolicy.egressRules.customRules is a table. Ignoring non-table value ([])
    NAME: myblog
    LAST DEPLOYED: Mon Mar 27 11:47:58 2023
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    NOTES:
    CHART NAME: wordpress
    CHART VERSION: 15.2.57
    APP VERSION: 6.1.1
    
    ** Be patient while the chart is being deployed.**
    
    Your WordPress site can be accessed through the following DNS name from within your cluster:
    
        myblog-wordpress.default.svc.cluster.local (port 80)
    
    To access your WordPress site from outside the cluster, follow the steps below:
    
    1. Get the WordPress URL by running these commands:
    
      NOTE: It may take a few minutes for the LoadBalancer IP to be available.
            Watch the status with: 'kubectl get svc --namespace default -w myblog-wordpress'
    
       export SERVICE_IP=$(kubectl get svc --namespace default myblog-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
       echo "WordPress URL: http://$SERVICE_IP/"
       echo "WordPress Admin URL: http://$SERVICE_IP/admin"
    
    2. Open a browser and access WordPress using the obtained URL.
    
    3. Log in with the following credentials below to see your blog:
    
      echo Username: user
      echo Password: $(kubectl get secret --namespace default myblog-wordpress -o jsonpath="{.data.wordpress-password}" | base64 -d)

    The command output shows how to obtain the WordPress URL and the username and password for accessing the WordPress backend.

Accessing WordPress

  1. Modify the WordPress Service configuration.

    Additional annotation configuration is required for using a LoadBalancer Service in CCE. However, bitnami/wordpress does not have this configuration. You need to manually modify the configuration.

    kubectl edit svc myblog-wordpress

    Add kubernetes.io/elb.autocreate and kubernetes.io/elb.class to metadata.annotations and save the modification. The two annotations are used to create a shared load balancer so that the WordPress workload can be accessed through the EIP of the load balancer.

    apiVersion: v1
    kind: Service
    metadata:
      name: myblog-wordpress
      namespace: default
      annotations:
        kubernetes.io/elb.autocreate: '{ "type": "public", "bandwidth_name": "myblog-wordpress", "bandwidth_chargemode": "bandwidth", "bandwidth_size": 5, "bandwidth_sharetype": "PER", "eip_type": "5_bgp" }'
        kubernetes.io/elb.class: union
    spec:
      ports:
        - name: http
    ...

  2. Obtain the public network load balancer IP address of Service myblog-wordpress and access it.

    On the Services tab, locate myblog-wordpress and find its public network load balancer IP address.

    In the address box of a browser, enter <Public IP address of the load balancer>:80 to access WordPress.

    In the address box of a browser, enter <EIP of the load balancer>:80/login to access the WordPress backend as user. Run the following command to obtain the password of user:

    kubectl get secret --namespace default myblog-wordpress -o jsonpath="{.data.wordpress-password}" | base64 -d

Deleting the WordPress Workload

  1. Run the following command to delete the WordPress workload:

    helm delete myblog

    Information similar to the following is displayed:
    release "myblog" uninstalled

  2. Delete the PersistentVolumeClaim (PVC) used by the mariadb component in WordPress.

    kubectl delete pvc data-myblog-mariadb-0

    Information similar to the following is displayed:
    persistentvolumeclaim "data-myblog-mariadb-0" deleted