helm安裝mysql

slnngk發表於2024-08-30

環境:

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

相關文章