gpt4 book ai didi

kubernetes - 部署在 minikube 上找不到 PVC

转载 作者:行者123 更新时间:2023-12-04 17:20:41 26 4
gpt4 key购买 nike

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

我查看事件顶部的消息,发现找不到我的 PVC。因此,我检查了 PersistentVolumeClaim 的状态。

据我所知,如果influxdb-pvinfluxdb-pvcSTATUSBound ,它通常被创建并且 Deployment 应该能够找到 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. 应用我的配置文件:influxdb-deployment.yamlinfluxdb-secret.yamlinfluxdb-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

Docker 文件:

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 集群上测试了您的 YAML。

您的配置是正确的,但是您遗漏了一个小细节。基于alpine的容器需要在内部“做点什么”,否则容器会在其主进程退出时退出。一旦容器完成所有预期/配置的操作,pod 将处于Completed 状态。

您的 pod 正在崩溃,因为它启动后立即退出,因此 Kubernetes 重新启动并继续循环。更多详情请查看Pod Lifecycle文档。

示例

Alpine 示例:

$ 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 是一个基于网络服务器的容器,因此它不需要额外的 sleep 命令。

您当前的配置

带有 influx 的 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

解决方案

你只需要添加例如 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

PV 问题

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

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

关于kubernetes - 部署在 minikube 上找不到 PVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66355331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com