安装Helm
helm是k8s的包管理,类似于管理docker镜像的docker hub
官网提供了很多中安装方式,看自己的爱好以及条件。以下是源码安装:
git clone https://github.com/helm/helm.gitcd helmmake
如果网络有问题,可以使用二进制安装
tar -zxvf helm-v3.0.0-linux-amd64.tar.gzmv linux-amd64/helm /usr/local/bin/helm
Three Big Concepts
AChart 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.
ARepository 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.
ARelease 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 repoadd bitnami https://charts.bitnami.com/bitnami
helminstall my-release bitnami/mysql
如果是内网,下载安装包后离线安装
helminstall my-release mysql-0.1.1.tgz
参考提示信息可以操作mysql
NAME: my-release
LAST DEPLOYED: Sat Nov2011:21:222022
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 patientwhile 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: rootMYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-release-mysql -ojsonpath="{.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 --bash2. To connect to primaryservice(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 andset the'root.password' parameter as shown below:ROOT_PASSWORD=$(kubectl get secret --namespace default my-release-mysql -ojsonpath="{.data.mysql-root-password}"| base64 --decode)
helm upgrade --namespace default my-release bitnami/mysql --set auth.rootPassword=$ROOT_PASSWORD
使用mysql
拿到mysql的登录密码
echoMYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-release-mysql -ojsonpath="{.data.mysql-root-password}"| base64 --decode)
进入mysql容器pod
kubectlexec -ti my-release1-mysql-0 --bash
登录mysql
mysql -u root -p
ysql> show databases;
删除mysql
查看
helmls
删除
helm delete my-release