helm安装mysql
环境:
3节点的k8s集群
前提条件:配置好nfs
1.下载镜像获取配置文件
1.# 拉取 mysql helm charts 到本地目录
[root@master ~]# cd ~
[root@master ~]# helm pull stable/mysql --untar
# 修改定义配置即可
[root@master ~]# cd mysql
[root@master ~]#vim values.yaml
修改镜像镜像地址
原来的
image: "mysql"
imageTag: "5.7.30"
strategy:
type: Recreate
busybox:
image: "busybox"
tag: "1.32"
testFramework:
enabled: true
image: "bats/bats"
tag: "1.2.1"
imagePullPolicy: IfNotPresent
securityContext: {}
修改为:
image: "registry.cn-shenzhen.aliyuncs.com/hxlk8s00/mysql"
imageTag: "5.7.30"
strategy:
type: Recreate
busybox:
image: "registry.cn-shenzhen.aliyuncs.com/hxlk8s00/busybox"
tag: "1.32"
testFramework:
enabled: true
image: "registry.cn-shenzhen.aliyuncs.com/hxlk8s00/bats"
tag: "1.2.1"
imagePullPolicy: IfNotPresent
securityContext: {}
2.指定配置文件进行安装
cd /root/mysql
helm install db stable/mysql -f values.yaml
指定values.yaml配置文件安装的目的是可以自定义镜像,因为默认的镜像访问不了了.
3.创建pv
准备配置文件
cd /root/
# cat pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: dbdata
spec:
capacity:
storage: 8Gi
accessModes:
- ReadWriteOnce
nfs:
path: /nfs/k8s
server: 192.168.1.102
注意:/nfs/k8s目录不需要有任何文件,否则mysql初始化失败
创建pv
cd /root
kubectl apply -f pv.yml
查看运行情况
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
db-mysql-bfcf7bbdb-5hspk 1/1 Running 3 (21s ago) 2m17s
4.登录mysql
直接进入容器,查看mysql可以使用
# 查看mysql密码
# kubectl get secret --namespace default db-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo
输出结果:
qxkiydybKY
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
db-mysql-bfcf7bbdb-fq6v9 1/1 Running 0 3m11s
# kubectl exec -it db-mysql-bfcf7bbdb-5hspk bash
# mysql -uroot -p