云原生应用管理:原理与实践
上QQ阅读APP看书,第一时间看更新

2.2.4 安装第一个Chart

我们使用helm install命令就可以直接安装Chart,既可以安装本地文件的Chart,也可以安装远程的Chart,这里我们采用默认方式安装Helm社区提供的Chart。由于Helm社区提供的Chart安装地址不方便访问,所以使用阿里云提供的apphub代替,具体安装情况如下。


[root@iZ8vb0qditk1qw27yu4k5nZ ~]# helm repo add apphub https:// apphub.aliyuncs.com/
"apphub" has been added to your repositories
[root@iZ8vb0qditk1qw27yu4k5nZ ~]# helm search apphub | grep mysql
apphub/mysql                             5.0.6         8.0.16
       Chart to create a Highly available mysql cluster
apphub/mysqldump                         2.4.2         2.4.1
       A Helm Chart to help backup mysql databases using mysqldump
apphub/mysqlha                           0.5.1         5.7.13
       mysql cluster with a single master and zero or more slave...
apphub/prometheus-mysql-exporter         0.3.4         v0.11.0
       A Helm Chart for prometheus mysql exporter with cloudsqlp...
[root@iZ8vb0qditk1qw27yu4k5nZ ~]# helm install apphub/mysql
NAME:   yummy-catfish
LAST DEPLOYED: Mon Aug  5 19:23:46 2019
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                        DATA  AGE
yummy-catfish-mysql-master  1     0s
yummy-catfish-mysql-slave   1     0s

==> v1/Pod(related)
NAME                          READY  STATUS   RESTARTS  AGE
yummy-catfish-mysql-master-0  0/1    Pending  0         0s
yummy-catfish-mysql-slave-0   0/1    Pending  0         0s

==> v1/Secret
NAME                 TYPE    DATA  AGE
yummy-catfish-mysql  Opaque  2     0s

==> v1/Service
NAME                       TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)   AGE
yummy-catfish-mysql        ClusterIP  172.26.5.135  <none>       3306/TCP  0s
yummy-catfish-mysql-slave  ClusterIP  172.26.8.17   <none>       3306/TCP  0s

==> v1beta1/StatefulSet
NAME                        READY  AGE
yummy-catfish-mysql-master  0/1    0s
yummy-catfish-mysql-slave   0/1    0s


NOTES:

Please be patient while the Chart is being deployed

Tip:

  Watch the deployment status using the command: kubectl get pods -w --namespace default

Services:

  echo Master: yummy-catfish-mysql.default.svc.cluster.local:3306
  echo Slave:  yummy-catfish-mysql-slave.default.svc.cluster.local:3306

Administrator credentials:

  echo Username: root
  echo Password : $(kubectl get secret --namespace default yummy-catfish-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)

To connect to your database:

  1. Run a pod that you can use as a client:

     kubectl run yummy-catfish-mysql-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.16-debian-9-r33 --namespace default --command -- bash

  2. To connect to master service (read/write):

     mysql -h yummy-catfish-mysql.default.svc.cluster.local -uroot -p my_database

  3. To connect to slave service (read-only):

     mysql -h yummy-catfish-mysql-slave.default.svc.cluster.local -uroot -p my_database

To upgrade this helm Chart:

  1. Obtain the password as described on the 'Administrator credentials' section and set the 'root.password' parameter as shown below:

      ROOT_PASSWORD=$(kubectl get secret --namespace default yummy-catfish-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
      helm upgrade yummy-catfish bitnami/mysql --set root.password=$ROOT_PASSWORD

如上例所示,apphub/mysql已经被安装到集群中,这个安装实例的专有名称为Release。这个Release的名称是yummy-catf ish,我们也可以在安装的时候通过helm install--name来指定Release名称。

安装命令发送后,下面的文本资料就是介绍后续如何使用这个Chart,我们可以在任何时候通过helm status命令来获取这段文字。