我有3个节点的kubernetes,主机名分别为host_1,host_2,host_3。
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
host_1 Ready master 134d v1.10.1
host_2 Ready <none> 134d v1.10.1
host_3 Ready <none> 134d v1.10.1
我定义了3个大小为100M的本地持久卷,它们映射到每个节点上的本地目录。我使用了以下描述符3次,其中<hostname>
是以下主机之一:host_1,host_2,host_3:
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-volume-<hostname>
spec:
capacity:
storage: 100M
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /opt/jnetx/volumes/test-volume
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- <hostname>
应用了三种此类Yaml后,我将得到以下信息:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
test-volume-host_1 100M RWO Delete Available local-storage 58m
test-volume-host_2 100M RWO Delete Available local-storage 58m
test-volume-host_3 100M RWO Delete Available local-storage 58m
现在,我有一个非常简单的容器来写入文件。该文件应位于本地永久卷上。我将其部署为具有1个副本的状态集,并通过statefulset的volumeClaimTemplates映射卷:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: filewriter
spec:
serviceName: filewriter
...
replicas: 1
template:
spec:
containers:
- name: filewriter
...
volumeMounts:
- mountPath: /test/data
name: fw-pv-claim
volumeClaimTemplates:
- metadata:
name: fw-pv-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 100M
批量声明似乎已经成功创建并绑定到第一台主机上的pv:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
test-volume-host_1 100M RWO Delete Bound default/fw-pv-claim-filewriter-0 local-storage 1m
test-volume-host_2 100M RWO Delete Available local-storage 1h
test-volume-host_3 100M RWO Delete Available local-storage 1h
但是,吊舱处于挂起状态:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
filewriter-0 0/1 Pending 0 4s
如果我们进行描述,我们会看到以下错误:
$ kubectl describe pod filewriter-0
Name: filewriter-0
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 2s (x8 over 1m) default-scheduler 0/3 nodes are available: 1 node(s) had taints that the pod didn't tolerate, 2 node(s) had volume node affinity conflict.
您能帮助我找出问题所在吗?为什么不能只创建吊舱?
答案 0 :(得分:1)
似乎PV可用的一个节点有一个污点,您的StatefulSet无法忍受。
答案 1 :(得分:0)
我的情况与上述情况非常相似,并观察到相同的症状(节点相似性冲突)。就我而言,问题是我有2个卷连接到2个不同的节点,但试图在1个容器中使用它们。
我通过使用kubectl describe pvc name-of-pvc
并注意到selected-node
注释检测到了这一点。一旦将Pod设置为使用同时在一个节点上的卷,就不再有问题了。