k8s - 使用helm安装mysql
Hlemk8s的包管理,类似于管理docker镜像的docker hub安装官网提供了很多中安装方式,看自己的爱好以及条件。以下是源码安装:$ git clone https://github.com/helm/helm.git$ cd helm$ make如果网络有问题,可以使用二进制安装tar -zxvf helm-v3.0.0-linux-amd64.tar.gzmv linux-amd64
安装Helm
helm是k8s的包管理,类似于管理docker镜像的docker hub
官网提供了很多中安装方式,看自己的爱好以及条件。以下是源码安装:
git clone https://github.com/helm/helm.git
cd helm
make
如果网络有问题,可以使用二进制安装
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
Three Big Concepts
A Chart is a Helm package. It contains all of the resource definitions necessary to run an application, tool, or service inside of a Kubernetes cluster. Think of it like the Kubernetes equivalent of a Homebrew formula, an Apt dpkg, or a Yum RPM file.
A Repository is the place where charts can be collected and shared. It’s like Perl’s CPAN archive or the Fedora Package Database, but for Kubernetes packages.
A Release is an instance of a chart running in a Kubernetes cluster. One chart can often be installed many times into the same cluster. And each time it is installed, a new release is created. Consider a MySQL chart. If you want two databases running in your cluster, you can install that chart twice. Each one will have its own release, which will in turn have its own release name.
安装mysql
参考这个网站可以在线安装
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-release bitnami/mysql
如果是内网,下载安装包后离线安装
helm install my-release mysql-0.1.1.tgz
参考提示信息可以操作mysql
NAME: my-release
LAST DEPLOYED: Sat Nov 20 11:21:22 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 8.8.12
APP VERSION: 8.0.27
** 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 Primary: my-release-mysql.default.svc.cluster.local:3306
Execute the following to get the administrator credentials:
echo Username: root
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-release-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 my-release-mysql-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.27-debian-10-r8 --namespace default --command -- bash
2. To connect to primary service (read/write):
mysql -h my-release-mysql.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"
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 my-release-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
helm upgrade --namespace default my-release bitnami/mysql --set auth.rootPassword=$ROOT_PASSWORD
使用mysql
拿到mysql的登录密码
echo MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-release-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
进入mysql容器pod
kubectl exec -ti my-release1-mysql-0 -- bash
登录mysql
mysql -u root -p
ysql> show databases;
删除mysql
查看
helm ls
删除
helm delete my-release
更多推荐
所有评论(0)