helm 安装 mysql 相关注意事项及记录

配置持久化到nfs

参考 https://blog.csdn.net/gs80140/article/details/93199622

 

mysql默认配置是写到外面的/var/lib/mysql目录, 所以这里面不改配置的情况下,把外面的/var/lib/mysql目录建好, 并mount到 nfs上

 

 initContainers:
      - name: "remove-lost-found"
        image: "{{ .Values.busybox.image}}:{{ .Values.busybox.tag }}"
        imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
        resources:
{{ toYaml .Values.initContainer.resources | indent 10 }}
        command:  ["rm", "-fr", "/var/lib/mysql/lost+found"]
        volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
          {{- if .Values.persistence.subPath }}
          subPath: {{ .Values.persistence.subPath }}

volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
          {{- if .Values.persistence.subPath }}
          subPath: {{ .Values.persistence.subPath }}
          {{- end }}

 

然后执行安装

 

helm install --name mysql \
  --set mysqlRootPassword=root,mysqlUser=my-user,mysqlPassword=my-password,mysqlDatabase=my-database \
    stable/mysql

 

报错 pod has unbound immediate PersistentVolumeClaims

 

查看 持久化 kubectl describe PersistentVolumeClaim/mysql

 

Name:          mysql
Namespace:     default
StorageClass:  
Status:        Pending
Volume:        
Labels:        app=mysql
               chart=mysql-1.2.0
               heritage=Tiller
               release=mysql
Annotations:   
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      
Access Modes:  
VolumeMode:    Filesystem
Events:
  Type       Reason         Age                   From                         Message
  ----       ------         ----                  ----                         -------
  Normal     FailedBinding  14s (x12 over 2m44s)  persistentvolume-controller  no persistent volumes available for this claim and no storage class is set
Mounted By:  mysql-b76bd86d7-d5fw7

 

 

上面是因为缺少pv的定义 , 参考 https://blog.csdn.net/gs80140/article/details/93475231

 

重新运行,添加配置

helm install --name mysql \
  --set mysqlRootPassword=root,mysqlUser=myname,mysqlPassword=mypsw,mysqlDatabase=mydb,livenessProbe.initialDelaySeconds=300,persistence.size=2Gi,persistence.storageClass=nfs,persistence.accessMode=ReadWriteOnce \
    stable/mysql

 

报错 Error: a release named mysql already exists.

通过 命令 helm ls --all 查看所有 release

然后通过 helm del --purge mysql 去删除 , 这种状态显示是DELETE, 应该是helm delete没有实际删除导致的.

 

当会用nfs-client 外部存储动态创建卷的时候(参考https://blog.csdn.net/gs80140/article/details/93599120),换一下存储类

从nfs 换成 nfs-client

helm install --name mysql \
  --set mysqlRootPassword=root,mysqlUser=myname,mysqlPassword=mypsw,mysqlDatabase=mydb,livenessProbe.initialDelaySeconds=300,persistence.size=2Gi,persistence.storageClass=nfs-client,persistence.accessMode=ReadWriteOnce \
    stable/mysql

将端口映射出来,供外部ip使用

kubectl expose deployment mysql-mysql --port=3307 --target-port=3306 --external-ip=192.168.220.129

可以直接用数据库连接工具连接 192.168.220.129:3307 root root
在网上看到的解释看的一头雾水, target port就是容器里的mysql端口, port就是外面可以访问的端口

mysql-mysql是deployment的名字

 

你可能感兴趣的:(各种问题,mysql,k8s,mysql,helm)