本文介绍如何通过Helm CLI部署WordPress应用。

前提条件

安装配置阿里云CLI和kubectl

  • 安装Helm。您可以选择以下三种方式:
    • 通过源码或二进制方式安装,请参见Installing Helm
    • 通过执行以下脚本安装。
      curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
    • 通过包管理器工具安装。
      • OS X安装:请参见Homebrew,安装包管理工具后,执行以下命令安装Helm。
        brew install helm
      • Windows 安装:请参考Chocolatey,安装包管理工具后,执行以下命令安装Helm。
        choco install kubernetes-helm
  • 配置Helm Repo。
    • 执行以下命令配置稳定版Repo。
      helm repo add stable https://kubernetes-charts.storage.googleapis.com/
    • 执行以下命令搜索Repo。
      helm search repo stable
  • 安装和设置kubectl客户端,详情请参见Install and Set Up kubectl

部署WordPress

  1. 执行以下命令,添加WordPress官方Repo地址。
    helm repo add bitnami https://charts.bitnami.com/bitnami
  2. 执行以下命令部署WordPress。
    helm install wordpress bitnami/wordpress \
        --set mariadb.primary.persistence.enabled=true \
        --set mariadb.primary.persistence.storageClass=alicloud-disk-ssd \
        --set mariadb.primary.persistence.size=20Gi \
        --set persistence.enabled=false                        
    说明
    • 为了实现数据的持久化,mariadb使用持久化存储卷保存数据。
    • 持久化存储选用阿里云SSD云盘,大小为20 GiB,并通过配置StorageClassName自动化创建。
    • WordPress不需要进行数据持久化,数据卷persistence.enabled可配置为false。

    系统输出类似以下结果,表示已经部署完成。

    NAME: wordpress
    LAST DEPLOYED: Tue Sep  8 10:37:05 2020
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    NOTES:
    ** Please be patient while the chart is being deployed **
    
    Your WordPress site can be accessed through the following DNS name from within your cluster:
    
        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 wordpress'
    
       export SERVICE_IP=$(kubectl get svc --namespace default 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. Login with the following credentials below to see your blog:
    
      echo Username: user
      echo Password: $(kubectl get secret --namespace default wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
                            

访问WordPress

  1. 安装Helm成功后,根据部署提示,执行以下命令获取访问IP地址。
    kubectl get svc --namespace default wordpress-acs-sample --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"

    系统输出类似以下结果:

    192.168.171.110  
  2. 执行以下命令获取admin访问密码。
    kubectl get secret --namespace default wordpress-ack-wordpress-sample -o jsonpath="{.data.wordpress-password}" | base64 --decode

    预期输出:

    K*****X**7
  3. 在地址栏中输入<IP地址>/login访问WordPress应用,然后使用用户名admin和访问密码登录admin界面。
    36

删除应用

您可以执行以下命令删除部署的WordPress。
helm delete wordpress
release "wordpress" uninstalled