Helm v3.1.2 安裝使用

下載Helm

wget https://get.helm.sh/helm-v3.1.2-linux-amd64.tar.gz
# 解壓下載 helm
tar -xvf helm-v3.1.2-linux-amd64.tar.gz
# 放到 /bin目錄
cd linux-amd64/
mv helm /bin/

Helm 源添加

#微軟的
helm repo add stable http://mirror.azure.cn/kubernetes/charts
helm repo add incubator http://mirror.azure.cn/kubernetes/charts-incubator
helm repo add svc-cat http://mirror.azure.cn/kubernetes/svc-catalog-charts
# 私有倉庫源 以私有harbor  helm-charts 爲參考
helm repo add --username=admin --password=Harbor12345 myrepo https://域名/chartrepo/
#具體的項目地址
helm repo add --username=admin --password=Harbor12345 library https://域名/chartrepo/library 
# 更新源
helm repo update
# 顯示添加源包
helm repo list

添加helm-push插件

helm plugin install https://github.com/chartmuseum/helm-push 
# 測試上傳私有倉庫
# 以mysql 爲例:
helm search   repo mysql
# 下載mysql 包   舊版本下載包方法helm fetch stable/mysql
helm  pull stable/mysql 
# 上傳mysql 包
helm push mysql-1.6.2.tgz myrepo

測試helm 安裝應用 mysql

# 更新源數據
helm repo update 
# 所搜包名
root@Qist:~# helm search   repo mysql
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION
incubator/mysqlha                       1.0.1           5.7.13          MySQL cluster with a single master and zero or ...
myrepo/mysql                            1.6.2           5.7.28          Fast, reliable, scalable, and easy to use open-...
stable/mysql                            1.6.2           5.7.28          Fast, reliable, scalable, and easy to use open-...
stable/mysqldump                        2.6.0           2.4.1           A Helm chart to help backup MySQL databases usi...
stable/prometheus-mysql-exporter        0.5.2           v0.11.0         A Helm chart for prometheus mysql exporter with...
stable/percona                          1.2.1           5.7.26          free, fully compatible, enhanced, open source d...
stable/percona-xtradb-cluster           1.0.3           5.7.19          free, fully compatible, enhanced, open source d...
stable/phpmyadmin                       4.3.4           5.0.1           DEPRECATED phpMyAdmin is an mysql administratio...
stable/gcloud-sqlproxy                  0.6.1           1.11            DEPRECATED Google Cloud SQL Proxy
stable/mariadb                          7.3.13          10.3.22         DEPRECATED Fast, reliable, scalable, and easy t...
# 選擇一個合適包安裝 關閉創建pvc 這裏只做測試。生產或者工作環境請創建pvc 不然重啓丟失數據
helm install  my-mysql --set persistence.enabled=false stable/mysql
# 私有的關閉創建pvc 
 helm install  my-mysql --set persistence.enabled=false myrepo/mysql 
 [root@k8s-master helm]#  helm install  my-mysql --set persistence.enabled=false stable/mysql
NAME: my-mysql
LAST DEPLOYED: Thu Apr  2 16:55:57 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
my-mysql.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-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 my-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/my-mysql 3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
 # 顯示安裝服務
 helm list
 [root@k8s-master helm]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
my-mysql        default         1               2020-04-02 16:55:57.89091694 +0800 CST  deployed        mysql-1.6.2     5.7.28
# 查看mysql 是否部署成功
[root@k8s-master helm]# kubectl get all | grep my-mysql
pod/my-mysql-69495b585-b78lj     1/1     Running   0          27m
service/my-mysql     ClusterIP   10.96.107.156   <none>        3306/TCP       27m
deployment.apps/my-mysql    1/1     1            1           27m
replicaset.apps/my-mysql-69495b585     1         1         1       27m
# 查看mysql密碼進入mysql
[root@k8s-master helm]# kubectl get secret --namespace default my-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode
aXsSW9pXBJ
# 進入mysql 容器
kubectl exec -ti my-mysql-69495b585-b78lj /bin/bash
root@my-mysql-69495b585-b78lj:/# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 232
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>
mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
mysql> select Host,User from mysql.user;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
4 rows in set (0.00 sec)
# 一切正常
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章