在minikube上无法找到PVC



我正在练习用Minikube制作PV和PVC。但是我遇到了一个错误,我的InfluxDB部署找不到influxdb-pvc,我无法解决它。

我检查事件顶部的消息,我可以看到我的PVC找不到。因此,我检查了persistentvolumecclaim的状态。

据我所知,如果STATUSinfluxdb-pvinfluxdb-pvc的值,它通常是创建的,部署应该能够找到influxdb-pvc。我不知道发生了什么…请帮帮我😢

以下是Pod的描述:

> kubectl describe pod influxdb-5b769454b8-pksss
Name:         influxdb-5b769454b8-pksss
Namespace:    ft-services
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Thu, 25 Feb 2021 01:14:25 +0900
Labels:       app=influxdb
pod-template-hash=5b769454b8
Annotations:  <none>
Status:       Running
IP:           172.17.0.5
IPs:
IP:           172.17.0.5
Controlled By:  ReplicaSet/influxdb-5b769454b8
Containers:
influxdb:
Container ID:   docker://be2eec32cca22ea84f4a0034f42668c971fefe62e361f2a4d1a74d92bfbf4d78
Image:          service_influxdb
Image ID:       docker://sha256:50693dcc4dda172f82c0dcd5ff1db01d6d90268ad2b0bd424e616cb84da64c6b
Port:           8086/TCP
Host Port:      0/TCP
State:          Waiting
Reason:       CrashLoopBackOff
Last State:     Terminated
Reason:       Completed
Exit Code:    0
Started:      Thu, 25 Feb 2021 01:30:40 +0900
Finished:     Thu, 25 Feb 2021 01:30:40 +0900
Ready:          False
Restart Count:  8
Environment Variables from:
influxdb-secret  Secret  Optional: false
Environment:       <none>
Mounts:
/var/lib/influxdb from var-lib-influxdb (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lfzz9 (ro)
Conditions:
Type              Status
Initialized       True
Ready             False
ContainersReady   False
PodScheduled      True
Volumes:
var-lib-influxdb:
Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName:  influxdb-pvc
ReadOnly:   false
default-token-lfzz9:
Type:        Secret (a volume populated by a Secret)
SecretName:  default-token-lfzz9
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  20m (x2 over 20m)   default-scheduler  0/1 nodes are available: 1 persistentvolumeclaim "influxdb-pvc" not found.
Normal   Scheduled         20m                 default-scheduler  Successfully assigned ft-services/influxdb-5b769454b8-pksss to minikube
Normal   Pulled            19m (x5 over 20m)   kubelet            Container image "service_influxdb" already present on machine
Normal   Created           19m (x5 over 20m)   kubelet            Created container influxdb
Normal   Started           19m (x5 over 20m)   kubelet            Started container influxdb
Warning  BackOff           43s (x93 over 20m)  kubelet            Back-off restarting failed container

PV和PVC的状态信息如下:

> kubectl get pv,pvc
NAME                           CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                      STORAGECLASS   REASON   AGE
persistentvolume/influxdb-pv   10Gi       RWO            Recycle          Bound       ft-services/influxdb-pvc   influxdb                104m
NAME                                 STATUS   VOLUME        CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/influxdb-pvc   Bound    influxdb-pv   10Gi       RWO            influxdb       13m

我按照以下顺序进行设置。

  1. 创建命名空间
kubectl create namespace ft-services
kubectl config set-context --current --namespace=ft-services
  1. Apply my config files:influxdb-deployment.yaml,influxdb-secret.yaml,influxdb-service.yaml,influxdb-volume.yaml

influxdb-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: influxdb
labels:
app: influxdb
spec:
replicas: 1
selector:
matchLabels:
app: influxdb
template:
metadata:
labels:
app: influxdb
spec:
containers:
- name: influxdb
image: service_influxdb
imagePullPolicy: Never
ports:
- containerPort: 8086
envFrom:
- secretRef:
name: influxdb-secret
volumeMounts:
- mountPath: /var/lib/influxdb
name: var-lib-influxdb
volumes:
- name: var-lib-influxdb
persistentVolumeClaim:
claimName: influxdb-pvc

influxdb-volume.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
name: influxdb-pv
labels:
app: influxdb
spec:
storageClassName: influxdb
claimRef:
namespace: ft-services
name: influxdb-pvc
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
hostPath:
path: "/mnt/influxdb"
type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: influxdb-pvc
labels:
app: influxdb
spec:
storageClassName: influxdb
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
  1. 构建docker镜像:service_influxdb

Dockerfile:

FROM alpine:3.13.1
RUN apk update && apk upgrade --ignore busybox && 
apk add 
influxdb && 
sed -i "247s/  #/  /" /etc/influxdb.conf && 
sed -i "256s/  #/  /" /etc/influxdb.conf
EXPOSE 8086
ENTRYPOINT influxd & /bin/sh
  1. 检查我的minikube与仪表盘
> minikube dashboard
0/1 nodes are available: 1 persistentvolumeclaim "influxdb-pvc" not found.
Back-off restarting failed container

我已经在我的Minikube集群上测试了您的YAMLs。

你的配置是正确的,但是你漏掉了一个小细节。基于alpine的容器需要"做某事">在内部,否则容器在其主进程退出时退出。一旦容器完成了所有的预期/配置,pod将处于Completed状态。

你的pod正在崩溃,因为它启动后立即退出,因此Kubernetes重新启动,循环继续。更多详细信息请查看Pod Lifecycle Documentation。

高山的例子:

$ kubectl get po alipne-test -w
NAME          READY   STATUS      RESTARTS   AGE
alipne-test   0/1     Completed   2          36s
alipne-test   0/1     CrashLoopBackOff   2          36s
alipne-test   0/1     Completed          3          54s
alipne-test   0/1     CrashLoopBackOff   3          55s
alipne-test   0/1     Completed          4          101s
alipne-test   0/1     CrashLoopBackOff   4          113s

Nginx的例子:

$ kubectl get po nginx
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          5m23s

Nginx是一个基于webserver的容器,所以它不需要额外的sleep命令。

当前配置

您的pod已创建,无事可做并退出。

$ kubectl get po -w
NAME                       READY   STATUS             RESTARTS   AGE
influxdb-96bfd697d-wbkt7   0/1     CrashLoopBackOff   4          2m28s
influxdb-96bfd697d-wbkt7   0/1     Completed          5          3m8s
influxdb-96bfd697d-wbkt7   0/1     CrashLoopBackOff   5          3m19s
<<p>

解决方案/strong>您只需要添加例如sleep command来保持容器存活。对于测试,我使用sleep 60来保持容器存活60秒,使用以下配置:

spec:
containers:
- name: influxdb
image: service_influxdb
imagePullPolicy: Never
ports:
- containerPort: 8086
envFrom:
- secretRef:
name: influxdb-secret
volumeMounts:
- mountPath: /var/lib/influxdb
name: var-lib-influxdb
command: ["/bin/sh"]               # additional command
args: ["-c", "sleep 60"]           # args to use sleep 60 command

和下面的输出:

$ kubectl get po -w
NAME                        READY   STATUS    RESTARTS   AGE
influxdb-65dc56f8df-9v76p   1/1     Running   0          7s
influxdb-65dc56f8df-9v76p   0/1     Completed   0          62s
influxdb-65dc56f8df-9v76p   1/1     Running     1          63s

运行了60秒,因为sleep命令被设置为60。当容器完成了内部配置的所有命令后,它退出,状态变为Completed。如果您将使用命令来保持此容器存活,则不需要使用sleep

<<p>

PV问题/strong>作为最后一部分,您在Minikube Dashboard中提到了问题。我无法复制它,但它可能是您之前测试的一些残留物。

如果您还有问题,请告诉我。

相关内容

  • 没有找到相关文章

最新更新