helm部署软件前自定义chart-自动部署软件

我们需要自定义chart配置选项,安装过程中有两种方法可以传递配置数据:

--values(或-f):指定带有覆盖的YAML文件。这可以多次指定,最右边的文件优先

--set:在命令行上指定替代。如果两者都用,--set优先级高

--values使用,先将修改的变量写到一个文件中

操作步骤:

[root@node-16 ~]# helm show values stable/mysql >values.yaml 

-------------------------------------------------------------------------------------

[root@node-16 ~]#

[root@node-16 ~]# vim values.yaml

 

mysqlRootPassword: jisibi9894008

mysqlUser: k8s

mysqlPassword: k8s123

mysqlDatabase: k8s

persistence:

  enabled: true

  storageClass: "managed-nfs-storage"

  accessMode: ReadWriteOnce

  size: 2Gi

 

 

[root@node-16 ~]#

 

------------------------------------------------------------------------------------

 

[root@node-16 ~]#

[root@node-16 ~]#

接下来使用上面的命令,不用手动创建PV ,自动创建PV 的案例

 

[root@node-16 ~]#

[root@node-16 ~]# helm list

NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION

db01    default         1               2020-04-26 13:56:58.07831662 +0800 CST  deployed        mysql-1.6.3     5.7.28    

[root@node-16 ~]#

 

 

[root@node-16 ~]# helm install db02 -f values.yaml stable/mysql    //创建一个db02

NAME: db02

LAST DEPLOYED: Mon Apr 27 15:17:27 2020

NAMESPACE: default

STATUS: deployed

REVISION: 1

NOTES:

MySQL can be accessed via port 3306 on the following DNS name from within your cluster:

db02-mysql.default.svc.cluster.local

 

To get your root password run:

 

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default db02-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

 

To connect to your database:

 

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

 

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il

 

2. Install the mysql client:

 

    $ apt-get update && apt-get install mysql-client -y

 

3. Connect using the mysql cli, then provide your password:

    $ mysql -h db02-mysql -p

 

To connect to your database directly from outside the K8s cluster:

    MYSQL_HOST=127.0.0.1

    MYSQL_PORT=3306

 

    # Execute the following command to route the connection:

    kubectl port-forward svc/db02-mysql 3306

 

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}

[root@node-16 ~]#

 

 

[root@node-16 ~]#

[root@node-16 ~]# helm list

NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION

db01    default         1               2020-04-26 13:56:58.07831662 +0800 CST  deployed        mysql-1.6.3     5.7.28    

db02    default         1               2020-04-27 15:17:27.883462606 +0800 CST deployed        mysql-1.6.3     5.7.28    

[root@node-16 ~]#

[root@node-16 ~]#

 

[root@node-16 ~]# kubectl get pv|grep db02

pvc-64b143e0-f83f-499c-b8a4-1b575b5bc5de   2Gi        RWO            Delete           Bound    default/db02-mysql                         managed-nfs-storage            3m25s

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]# kubectl get pvc|grep db02

db02-mysql     Bound    pvc-64b143e0-f83f-499c-b8a4-1b575b5bc5de   2Gi        RWO            managed-nfs-storage   3m37s

[root@node-16 ~]#

[root@node-16 ~]# kubectl get pod|grep db02

db02-mysql-68bdf7c6f9-skmzf               0/1     CrashLoopBackOff   5          3m53s

[root@node-16 ~]#

 

 

 

[root@node-16 ~]# kubectl get deployment

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

db01-mysql               1/1     1            1           28h

db02-mysql               1/1     1            1           18s

metrics-app              2/2     2            2           3d8h

nfs-client-provisioner   1/1     1            1           4d

nginx-deploy             2/2     2            2           5d8h

nginx-deploy-nfs         2/2     2            2           6d1h

rbd-provisioner          1/1     1            1           5d8h

web                      1/1     1            1           4d1h

 

 

 

[root@node-16 ~]# kubectl get pod

NAME                                      READY   STATUS    RESTARTS   AGE

db01-mysql-6ff46d6ccb-6whjz               1/1     Running   0          28h

db02-mysql-59976896d-fj28z                1/1     Running   0          29s

metrics-app-7674cfb699-5mbxm              1/1     Running   2          3d8h

metrics-app-7674cfb699-ttdgz              1/1     Running   1          46h

nfs-client-provisioner-657b74d847-9k7zz   1/1     Running   2          3d9h

nginx-deploy-7cfd95c58-jlrr5              1/1     Running   0          5d7h

nginx-deploy-7cfd95c58-w69mq              1/1     Running   0          46h

nginx-deploy-nfs-5c5bd755b4-b2cj5         1/1     Running   3          6d1h

nginx-deploy-nfs-5c5bd755b4-mmf4b         1/1     Running   1          46h

rbd-provisioner-75b85f85bd-4d8nl          1/1     Running   2          5d8h

web-77cd4569c-zd5gr                       1/1     Running   3          4d1h

[root@node-16 ~]#

 

 

[root@node-16 ~]#

[root@node-16 ~]# kubectl get secret --namespace default db02-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo

uZNfMNPNz0

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

 

[root@node-16 ~]# kubectl exec db02-mysql-59976896d-fj28z -it /bin/bash

 

root@db02-mysql-59976896d-fj28z:/#

root@db02-mysql-59976896d-fj28z:/# mysql -uroot -puZNfMNPNz0

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 84

Server version: 5.7.28 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> set password for root@localhost = password('jisibi9894008'); 

Query OK, 0 rows affected, 1 warning (0.01 sec)

 

mysql> exit

Bye

root@db02-mysql-59976896d-fj28z:/#

 

root@db02-mysql-59976896d-fj28z:/# mysql -uroot -pjisibi9894008

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 121

Server version: 5.7.28 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

 

 

 

删除DB02

[root@node-16 ~]#

[root@node-16 ~]# helm uninstall db02

release "db02" uninstalled

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

 

[root@node-16 ~]# helm uninstall db03

release "db03" uninstalled

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值