Tel*_*uar 8 kubernetes kubernetes-statefulset
正如文档所述:
对于 StatefulSet 中定义的每个 VolumeClaimTemplate 条目,每个 Pod 都会收到一个 PersistentVolumeClaim。在上面的 nginx 示例中,每个 Pod 都会收到一个具有 my-storage-class 的 StorageClass 和 1 Gib 预配置存储的 PersistentVolume。如果未指定 StorageClass,则将使用默认 StorageClass。当 Pod 被(重新)调度到节点上时,其 volumeMount 会挂载与其 PersistentVolume Claims 关联的 PersistentVolume。请注意,删除 Pod 或 StatefulSet 时,与 Pod 的 PersistentVolume Claim 关联的 PersistentVolume 不会被删除。这必须手动完成。
我感兴趣的部分是:If no StorageClassis specified, then the default StorageClass will be used
我创建了一个 StatefulSet,如下所示:
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: ches
name: ches
spec:
serviceName: ches
replicas: 1
selector:
matchLabels:
app: ches
template:
metadata:
labels:
app: ches
spec:
serviceAccountName: ches-serviceaccount
nodeSelector:
ches-worker: "true"
volumes:
- name: data
hostPath:
path: /data/test
containers:
- name: ches
image: [here I have the repo]
imagePullPolicy: Always
securityContext:
privileged: true
args:
- server
- --console-address
- :9011
- /data
env:
- name: MINIO_ACCESS_KEY
valueFrom:
secretKeyRef:
name: ches-keys
key: access-key
- name: MINIO_SECRET_KEY
valueFrom:
secretKeyRef:
name: ches-keys
key: secret-key
ports:
- containerPort: 9000
hostPort: 9011
resources:
limits:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: data
mountPath: /data
imagePullSecrets:
- name: edge-storage-token
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Run Code Online (Sandbox Code Playgroud)
当然,我已经创建了秘密、imagePullSecrets 等,并且我已将该节点标记为 ches-worker。
当我应用 yaml 文件时,pod 处于 Pending 状态并kubectl describe pod ches-0 -n ches给出以下错误:
警告 FailedScheduling 6 个默认调度程序 0/1 节点可用:1 个 Pod 具有未绑定的即时 PersistentVolumeClaims。抢占:0/1 可用节点:1 抢占对调度没有帮助
我在这里错过了什么吗?
您需要创建一个 PV 才能绑定 PVC。如果您希望根据 PVC 声明自动创建 PV,则需要在集群中安装 Provisioner。
首先创建一个至少具有 PVC 所需空间量的 PV。然后您可以应用包含 PVC 声明的部署 yaml。
K3s 安装后还会下载一个存储类,使其成为默认存储类。
检查kubectl get storageclass:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE local-path rancher.io/local-path 删除 WaitForFirstConsumer false 8s
另一方面,K8s 集群也不下载默认存储类别。
为了解决这个问题:
下载 rancher.io/local-path 存储类:
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
检查与kubectl get storageclass
将此存储类(本地路径)设置为默认存储类:
kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
| 归档时间: |
|
| 查看次数: |
45454 次 |
| 最近记录: |