我是 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
创建您请求的存储。
可用的卷类型示例 here .
A
PersistentVolume
(PV) is a piece of storage in the cluster that has been provisioned by an administrator. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.A
PersistentVolumeClaim
(PVC) is a request for storage by a user. It is similar to a pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., can be mounted once read/write or many times read-only).
如果您在 GCE , 你可以使用 gcePersistentDisk
A
gcePersistentDisk
volume mounts a Google Compute Engine (GCE) Persistent Disk into your Pod. UnlikeemptyDir
, which is erased when a Pod is removed, the contents of a PD are preserved and the volume is merely unmounted. This means that a PD can be pre-populated with data, and that data can be “handed off” between Pods.
您需要使用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 中使用它,有关如何设置它的示例可用 here .
您还可以查看有关如何 use volumes on AWS 的文档.
希望这足以帮助到您。
关于java - Kubernetes statefulset 不使用存储类来创建持久卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54310252/