k8s包管理(helm)使用helm安装mysql到k8s

举报
xcc-2022 发表于 2022/08/07 19:51:17 2022/08/07
【摘要】 安装Helmhelm是k8s的包管理,类似于管理docker镜像的docker hub官网提供了很多中安装方式,看自己的爱好以及条件。以下是源码安装:git clone https://github.com/helm/helm.gitcd helmmake如果网络有问题,可以使用二进制安装tar -zxvf helm-v3.0.0-linux-amd64.tar.gzmv linux-amd...

安装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
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。