https://kubernetes.feisky.xyz/concepts/objects/persistent-volume#volume-sheng-ming-zhou-qi
以官网的 Quick Start 安装 MySQL Demo 为例
安装 Mysql
helm install bitnami/mysql --generate-name
root@l2:~# helm install bitnami/mysql --generate-name
NAME: mysql-1653818407
LAST DEPLOYED: Sun May 29 18:00:11 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.1.1
APP VERSION: 8.0.29
** 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: mysql-1653818407.default.svc.cluster.local:3306
Execute the following to get the administrator credentials:
echo Username: root
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1653818407 -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 mysql-1653818407-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.29-debian-10-r23 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash
2. To connect to primary service (read/write):
mysql -h mysql-1653818407.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"
检测 helm mysql 状态 helm ls
已经 deploy
root@l2:~# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1653818407 default 1 2022-05-29 18:00:11.948612292 +0800 CST deployed mysql-9.1.1 8.0.29
检测 pods 状态. kubectl get pods
一直在 pending
root@l2:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-1653818407-0 0/1 Pending 0 69s
nginx-deployment-5d59d67564-2njn5 1/1 Running 0 3h45m
nginx-deployment-5d59d67564-bxmvz 1/1 Running 0 3h45m
检测 pods 详细信息. kubectl describe pods mysql-1653818407-0
root@l2:~# kubectl describe pods mysql-1653818407-0
Name: mysql-1653818407-0
Namespace: default
Priority: 0
Node: <none>
Labels: app.kubernetes.io/component=primary
app.kubernetes.io/instance=mysql-1653818407
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=mysql
controller-revision-hash=mysql-1653818407-99f56b499
helm.sh/chart=mysql-9.1.1
statefulset.kubernetes.io/pod-name=mysql-1653818407-0
Annotations: checksum/configuration: 5f2e6634a70542ab714fcd83f049db0bac4249e8fbd85f5325315fcf54c3e940
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/mysql-1653818407
Containers:
mysql:
Image: docker.io/bitnami/mysql:8.0.29-debian-10-r23
Port: 3306/TCP
Host Port: 0/TCP
Liveness: exec [/bin/bash -ec password_aux="${MYSQL_ROOT_PASSWORD:-}"
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
fi
mysqladmin status -uroot -p"${password_aux}"
] delay=5s timeout=1s period=10s #success=1 #failure=3
Readiness: exec [/bin/bash -ec password_aux="${MYSQL_ROOT_PASSWORD:-}"
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
fi
mysqladmin status -uroot -p"${password_aux}"
] delay=5s timeout=1s period=10s #success=1 #failure=3
Startup: exec [/bin/bash -ec password_aux="${MYSQL_ROOT_PASSWORD:-}"
if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
fi
mysqladmin status -uroot -p"${password_aux}"
] delay=15s timeout=1s period=10s #success=1 #failure=10
Environment:
BITNAMI_DEBUG: false
MYSQL_ROOT_PASSWORD: <set to the key 'mysql-root-password' in secret 'mysql-1653818407'> Optional: false
MYSQL_DATABASE: my_database
Mounts:
/bitnami/mysql from data (rw)
/opt/bitnami/mysql/conf/my.cnf from config (rw,path="my.cnf")
/var/run/secrets/kubernetes.io/serviceaccount from mysql-1653818407-token-twpqk (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: data-mysql-1653818407-0
ReadOnly: false
config:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mysql-1653818407
Optional: false
mysql-1653818407-token-twpqk:
Type: Secret (a volume populated by a Secret)
SecretName: mysql-1653818407-token-twpqk
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 62s (x4 over 3m12s) default-scheduler 0/3 nodes are available: 3 pod has unbound immediate PersistentVolumeClaims.
检测 pvc 状态 kubectl get pvc
root@l2:~# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-mysql-1653818407-0 Pending 5m57s
进一步确认 mysql pvc 状态 kubectl describe pvc data-mysql-1653818407-0
root@l2:~# kubectl describe pvc data-mysql-1653818407-0
Name: data-mysql-1653818407-0
Namespace: default
StorageClass:
Status: Pending
Volume:
Labels: app.kubernetes.io/component=primary
app.kubernetes.io/instance=mysql-1653818407
app.kubernetes.io/name=mysql
Annotations: <none>
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Mounted By: mysql-1653818407-0
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal FailedBinding 22s (x26 over 6m34s) persistentvolume-controller no persistent volumes available for this claim and no storage class is set