是否可以在不挂载持久卷的情况下创建 k8s Stateful Set?

问题描述 投票:0回答:1

我尝试创建以下有状态集,但在尝试启动其唯一的 Pod 时,它在 10 秒内失败。

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dbss
spec:
  selector:
    matchLabels:
      app: db-pod
  replicas: 1
  template:
    metadata:
      labels:
        app: db-pod
    spec:
      containers:
      - name: db-cont
        image: mysql:5
        ports:
        - containerPort: 3306

我认为错误消息的描述性不够:

Events:
  Type     Reason     Age                   From               Message
  ----     ------     ----                  ----               -------
  Normal   Scheduled  5m9s                  default-scheduler  Successfully assigned dbss-0 to minikube
  Normal   Pulled     3m16s (x5 over 5m9s)  kubelet            Container image "mysql:5" already present on machine
  Normal   Created    3m16s (x5 over 5m9s)  kubelet            Created container db-cont
  Normal   Started    3m16s (x5 over 5m9s)  kubelet            Started container db-cont
  Warning  BackOff    2s (x21 over 4m55s)   kubelet            Back-off restarting failed container db-cont in pod dbss-0_k8s-overview(d7c03bf1-051e-47f8-bb72-6b1669584011)

是否是因为Stateful Set中没有挂载持久卷? 有没有办法查看更具描述性的错误消息以了解实际原因?

我从https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations知道以下限制:

局限性 给定 Pod 的存储必须由 PersistentVolume Provisioner 根据请求的存储类进行配置,或者由管理员预先配置。

但我不确定我是否正确理解了引用的限制。尤其是在查看了失败的 pod 事件之后。

kubernetes persistent-volumes kubernetes-statefulset
1个回答
0
投票

可以在没有持久化 Volume 的情况下创建 StatefulSet

apiVersion: v1
kind: Service
metadata:
 name: nginx-hellow-world
 labels:
   app: nginx-hello-world
spec:
 ports:
 - port: 80
   name: web
 clusterIP: None
 selector:
   app: nginx-hello-world
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
 name: nginx-hello-world
spec:
 selector:
   matchLabels:
     app: nginx-hello-world # has to match .spec.template.metadata.labels
 serviceName: "nginx-hello-world"
 template:
   metadata:
     labels:
       app: nginx-hello-world # has to match .spec.selector.matchLabels
   spec:
     terminationGracePeriodSeconds: 10
     containers:
     - name: nginx-hello-world
       image: dockerbogo/docker-nginx-hello-world
       ports:
       - containerPort: 80
         name: web

kubernetes 参考页面的示例中,他们使用的 nginx 镜像需要一个包含 nginx 视图的卷。这就是为什么在示例中他们安装了一个卷。

您为 pod 提供的终端响应已安排,但 pod 中的容器无法启动,kubernetes 尝试重新启动它们,这就是

Back-off restarting failed container
的含义,请参阅此文档

© www.soinside.com 2019 - 2024. All rights reserved.