它适用于我的 Mac k8s 实例,但不适用于我的 Raspberry Pi 实例。 本质上,我正在尝试建立 Pihole 的 k8s 云实现。 这样,我可以监控它,并将其保持容器化,而不是在应用程序范围之外运行。 理想情况下,我尝试将所有东西都容器化以保持清洁。
我正在 2 节点 Raspberry Pi 4、4G /ea 集群上运行。
在我的 mac 上运行以下文件时,它可以正确构建,但在名为:master-pi 的 Pi 上,它将失败:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 44m default-scheduler 0/2 nodes are available: 1 node(s) didn't find available persistent volumes to bind, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
Warning FailedScheduling 44m default-scheduler 0/2 nodes are available: 1 node(s) didn't find available persistent volumes to bind, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
我实现的 YAML 看起来非常简单:
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pihole-local-etc-volume
labels:
directory: etc
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local
local:
path: /home/pi/Documents/pihole/etc #Location where it will live.
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- master-pi #docker-desktop # Hosthome where lives.
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pihole-local-etc-claim
spec:
storageClassName: local
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi # Possibly update to 2Gi later.
selector:
matchLabels:
directory: etc
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pihole-local-dnsmasq-volume
labels:
directory: dnsmasq.d
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local
local:
path: /home/pi/Documents/pihole/dnsmasq #Location where it will live.
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- master-pi #docker-desktop # Hosthome where lives.
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pihole-local-dnsmasq-claim
spec:
storageClassName: local
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
selector:
matchLabels:
directory: dnsmasq.d
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pihole
labels:
app: pihole
spec:
replicas: 1
selector:
matchLabels:
app: pihole
template:
metadata:
labels:
app: pihole
name: pihole
spec:
containers:
- name: pihole
image: pihole/pihole:latest
imagePullPolicy: Always
env:
- name: TZ
value: "America/New_York"
- name: WEBPASSWORD
value: "secret"
volumeMounts:
- name: pihole-local-etc-volume
mountPath: "/etc/pihole"
- name: pihole-local-dnsmasq-volume
mountPath: "/etc/dnsmasq.d"
volumes:
- name: pihole-local-etc-volume
persistentVolumeClaim:
claimName: pihole-local-etc-claim
- name: pihole-local-dnsmasq-volume
persistentVolumeClaim:
claimName: pihole-local-dnsmasq-claim
---
apiVersion: v1
kind: Service
metadata:
name: pihole
spec:
selector:
app: pihole
ports:
- port: 8000
targetPort: 80
name: pihole-admin
- port: 53
targetPort: 53
protocol: TCP
name: dns-tcp
- port: 53
targetPort: 53
protocol: UDP
name: dns-udp
externalIPs:
- 192.168.10.75 #Static IP I need to assign for the network.
其他注意事项: 我确保之前创建了这些文件夹,并且它们都是 chmod 777。
df
产生:
pi@master-pi:~/Documents/pihole$ df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 383100 5772 377328 2% /run
/dev/mmcblk0p2 30450144 14283040 14832268 50% /
tmpfs 1915492 0 1915492 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 4096 0 4096 0% /sys/fs/cgroup
/dev/mmcblk0p1 258095 147696 110399 58% /boot/firmware
tmpfs 383096 116 382980 1% /run/user/1000
所以我相信该位置具有所需的大小(/home/pi/Documents/etc)只是 1G,但它看起来半满,所以 ~15G 可用。
这里有两件事需要学习。
主节点没有获得调度的 Pod。 他们有足够的事情要做,只是组织而已。 也就是说,A因为节点集群既是Master又是Slave,其中2个或以上,1个是Master,其余的是Slave。
在这种情况下为卷分配路径
/hello/world
时,它不会在主机上自动创建路径,这实际上非常烦人,因为如果你有 N 个 Pod,则需要所有节点都有该路径,以防万一它被安排到另一处。 master 决定事情在哪里,所以如果它将它传递给一个无法处理它的 Node,它将得到一个退避错误。 最好把路径放在所有节点上。
关键要点是集群(主集群或其他集群)应该自动创建节点路径,但事实并非如此。 人们可能会认为既然它有 sudo 它应该能够说“将其安装在这里”,但事实并非如此。 我需要手动配置每个节点以消耗路径,这会产生配置错误。
如果我需要临时启动更多节点,我需要确保它们都已相应配置,例如添加此特定路径。 您需要将其添加到您自己的设置例程中。
您可以在此处阅读有关卷的 hostPath 的更多信息:https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume
网站指出,hostPath 适用于单节点集群,但在处理生产或 >1 个节点时,您应该使用 NFS 或其他一些存储机制。
其他受益的方法是使用存储类进行自动配置,这就是我个人首先想要的原因:https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in -kubernetes/
它讨论了如何定义存储类别,以及如何请求例如 30gi 的存储大小。 这将与声明一起使用。 为时已晚,但我会尝试为基本问题写一个类似的例子。