1.先下载helm并从阿里源上pull下来一个mysql,我下的是helm-v3.7.1-linux-amd64.tar.gz。
https://blog.51cto.com/u_13760351/2898442
2.尝试helm install mysql --generate-name,报错如下,另外版本要换成apps/v1
问题1:不知道为什么源没有selector
[root@VM-0-36-centos helm]# helm install mysql --generate-name
Error: INSTALLATION FAILED: Deployment.apps "mysql-1650434540-mysql" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"mysql-1650434540-mysql"}: `selector` does not match template `labels`
解决1:确保selector和metadata里保持一致
spec:
selector:
matchLabels:
app: {{ template "mysql.fullname" . }}
template:
metadata:
labels:
app: {{ template "mysql.fullname" . }}
问题2:pod没起来,进去看看,发现时PVC的问题。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 61s default-scheduler running "VolumeBinding" filter plugin for pod "mysql-1650434761-mysql-76875b4b6c-z9rcx": pod has unbound immediate PersistentVolumeClaims
解决2:这里又要再梳理下PV,PVC,SC的概念了
用户提交请求创建pod,Kubernetes发现这个pod声明使用了PVC,那就靠PersistentVolumeController帮它找一个PV配对。
没有现成的PV,就去找对应的StorageClass,帮它新创建一个PV,然后和PVC完成绑定。
于是我装了nfs
https://blog.51cto.com/u_14306186/2522546
部署过程遇到了很多问题,
起初是发现mysql这个pod没起来,并且pvc是pending的
[root@VM-0-36-centos nfs]# kubectl get all -n=nfs
NAME READY STATUS RESTARTS AGE
pod/nfs-client-provisioner-7489699876-jfpzq 0/1 ContainerCreating 0 30m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nfs-client-provisioner 0/1 1 0 33m
NAME DESIRED CURRENT READY AGE
replicaset.apps/nfs-client-provisioner-655bf8888 0 0 0 33m
replicaset.apps/nfs-client-provisioner-7489699876 1 1 0 30m
[root@VM-0-36-centos helm]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-1650442406-mysql Pending stateful-nfs 108s
于是看了一下provisioner的pod情况
Events: Type Reason Age From Message
---- ------ ---- ---- ------- Normal Scheduled 33m default-scheduler Successfully assigned
nfs/nfs-client-provisioner-7489699876-jfpzq to vm-0-36-centos
Warning FailedMount 26m kubelet MountVolume.SetUp
failed for volume “nfs-client-root” : mount failed: exit status 32
我去provisioner的deployment yam文件检查了下,
env: - name: PROVISIONER_NAME value: nfs-storage #provisioner名称,请确保该名称与 nfs-StorageClass.yaml文件中的provisioner名称保持一致 - name: NFS_SERVER value: XXX.XXX.XXX.XXX #NFS Server IP地址 - name: NFS_PATH
有可能是这个volumns没起来,端口问题? open 2049
[root@VM-0-36-centos nfs]# kubectl get pod -n=nfs
^[[B^[[B^[[BNAME READY STATUS RESTARTS AGE
nfs-client-provisioner-7489699876-g4j6g 0/1 ContainerCreating 0 41s
[root@VM-0-36-centos nfs]# kubectl get pod -n=nfs
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-7489699876-g4j6g 1/1 Running 0 2m18s
果然可以了!
[root@VM-0-36-centos nfs]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-13ed1e5f-27a5-48c8-a02c-f269509ab6b9 8Gi RWO Delete Bound default/mysql-1650442406-mysql stateful-nfs 18m
[root@VM-0-36-centos nfs]# kubectl get pvv
error: the server doesn't have a resource type "pvv"
[root@VM-0-36-centos nfs]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-1650442406-mysql Bound pvc-13ed1e5f-27a5-48c8-a02c-f269509ab6b9 8Gi RWO stateful-nfs 48m
[root@VM-0-36-centos nfs]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
standard (default) k8s.io/minikube-hostpath Delete Immediate false 23d
stateful-nfs nfs-storage Retain Immediate false 68m
但是mysql的pod还是pending的呢?
helm ls , helm delete, helm install 重新部署,
最后mysql 里面还是有密码的问题,但是PV 没问题了,今天就到这吧,不弄了。。。