[英]Kubernetes stateful set are not using storage class to create persistance volume
我是kubenetes的新手。 我已經在兩台機器上設置了一個Kubernetes集群。 當我使用有狀態集部署Pod時。但是kubernetes沒有創建pvc。
我正在做POC以在kubernets集群上安裝Redis集群,因此為此,我從站點URL下方下載了有狀態集。 [ https://medium.com/zero-to/setup-persistence-redis-cluster-in-kubertenes-7d5b7ffdbd98]
這個有狀態的集合可以在minikube上正常工作,但是當我在kubernetes集群(我已經用2台機器創建)上部署它時,它給出了以下錯誤:
root@xen-727:/usr/local/bin# kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-cluster-0 0/1 Pending 0 13m
root@xen-727:/usr/local/bin# kubectl describe pod redis-cluster-0
Name: redis-cluster-0
Namespace: default
Node: /
Labels: app=redis-cluster
controller-revision-hash=redis-cluster-b5b75cc79
statefulset.kubernetes.io/pod-name=redis-cluster-0
Annotations: <none>
Status: Pending
IP:
Controllers: <none>
Containers:
redis-cluster:
Image: tiroshanm/kubernetes-redis-cluster:latest
Ports: 6379/TCP, 16379/TCP
Command:
/usr/local/bin/redis-server
Args:
/redis-conf/redis.conf
Liveness: exec [sh -c redis-cli -h $(hostname) ping] delay=20s timeout=1s period=3s #success=1 #failure=3
Readiness: exec [sh -c redis-cli -h $(hostname) ping] delay=15s timeout=5s period=10s #success=1 #failure=3
Environment: <none>
Mounts:
/data from data (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-h22jv (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: data-redis-cluster-0
ReadOnly: false
default-token-h22jv:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-h22jv
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready=:Exists:NoExecute for 300s
node.kubernetes.io/unreachable=:Exists:NoExecute for 300s
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
15m 14m 4 default-scheduler Warning FailedScheduling pod has unbound immediate PersistentVolumeClaims (repeated 2 times)
root@xen-727:/usr/local/bin# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
data-redis-cluster-0 Pending slow 15m
root@xen-727:/usr/local/bin# kubectl get pv
No resources found.
我創建了一個存儲類:
root@xen-727:/usr/local/bin# kubectl get sc
NAME TYPE
slow (default) kubernetes.io/gce-pd
但是經過大量搜索后,看來kubernetes沒有使用此存儲類來創建pv。
存儲類代碼:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: slow
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-standard
下面是我的完整代碼:
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: redis-cluster
labels:
app: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
template:
metadata:
labels:
app: redis-cluster
annotations:
spec:
containers:
- name: redis-cluster
image: tiroshanm/kubernetes-redis-cluster:latest
imagePullPolicy: Always
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
command: ["/usr/local/bin/redis-server"]
args: ["/redis-conf/redis.conf"]
readinessProbe:
exec:
command:
- sh
- -c
- "redis-cli -h $(hostname) ping"
initialDelaySeconds: 15
timeoutSeconds: 5
livenessProbe:
exec:
command:
- sh
- -c
- "redis-cli -h $(hostname) ping"
initialDelaySeconds: 20
periodSeconds: 3
volumeMounts:
- name: data
mountPath: /data
readOnly: false
volumeClaimTemplates:
- metadata:
name: data
labels:
name: redis-cluster
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 100Mi
預期的輸出:它應該創建6個節點,分別具有6個pvc和6個pv。
您需要使用PersistentVolumeClaim
創建要請求的存儲。
此處提供卷類型的示例。
PersistentVolume
(PV)是群集中由管理員配置的一部分存儲。 它是群集中的資源,就像節點是群集資源一樣。 PV是類似於Volumes的卷插件,但是其生命周期獨立於使用PV的任何單個容器。 此API對象捕獲NFS,iSCSI或特定於雲提供商的存儲系統的存儲實現的詳細信息。
PersistentVolumeClaim
(PVC)是用戶存儲請求。 它類似於吊艙。 容器消耗節點資源,PVC消耗PV資源。 Pod可以請求特定級別的資源(CPU和內存)。 聲明可以請求特定的大小和訪問模式(例如,可以一次讀取/寫入或多次只讀安裝)。
如果您使用的是GCE ,則可以使用gcePersistentDisk
gcePersistentDisk
卷將Google Compute Engine(GCE) 永久磁盤裝載到您的Pod中。 與emptyDir
不同,emptyDir
在除去Pod時將被擦除,它保留了PD的內容,而只是卸載了該卷。 這意味着可以在PD中預填充數據,並且可以在Pod之間“傳遞”數據。
您需要使用gcloud
命令在GCE內創建驅動器:
gcloud compute disks create --size=500GB --zone=us-central1-a my-data-disk
並在POD
使用它,如下例所示:
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: k8s.gcr.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
# This GCE PD must already exist.
gcePersistentDisk:
pdName: my-data-disk
fsType: ext4
如果願意,可以設置自己的nfs
服務器並在Kubernetes中使用它,有關如何設置它的示例,請參見此處 。
希望這足以幫助您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.