下载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)
# 一切正常
来源:51CTO
作者:juestnow
链接:https://blog.51cto.com/juestnow/2484431