我正在数字海洋上试用Kubernetes。 作为测试用例,我正在尝试将Jenkins实例部署到具有持久卷的群集中。
我的部署Yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
labels:
app: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- containerPort: 8080
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-pvc
我的PV索赔
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: do-block-storage
resources:
requests:
storage: 30Gi
出于某种原因,广告连播始终以CrashLoopBackOff
状态结束。
kubectl describe pod <podname>
给了我
Name: jenkins-deployment-bb5857d76-j2f2w
Namespace: default
Priority: 0
Node: cc-pool-bg6c/10.138.123.186
Start Time: Sun, 15 Sep 2019 22:18:56 +0200
Labels: app=jenkins
pod-template-hash=bb5857d76
Annotations: <none>
Status: Running
IP: 10.244.0.166
Controlled By: ReplicaSet/jenkins-deployment-bb5857d76
Containers:
jenkins:
Container ID: docker://4eaadebb917001d8d3eaaa3b043e1b58b6269f929b9e95c4b08d88b0098d29d6
Image: jenkins/jenkins:lts
Image ID: docker-pullable://jenkins/jenkins@sha256:7cfe34701992434cc08bfd40e80e04ab406522214cf9bbefa57a5432a123b340
Port: 8080/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Sun, 15 Sep 2019 22:35:14 +0200
Finished: Sun, 15 Sep 2019 22:35:14 +0200
Ready: False
Restart Count: 8
Environment: <none>
Mounts:
/var/jenkins_home from jenkins-home (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-wd6p7 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
jenkins-home:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: jenkins-pvc
ReadOnly: false
default-token-wd6p7:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-wd6p7
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 19m default-scheduler Successfully assigned default/jenkins-deployment-bb5857d76-j2f2w to cc-pool-bg6c
Normal SuccessfulAttachVolume 19m attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-cb772fdb-492b-4ef5-a63e-4e483b8798fd"
Normal Pulled 17m (x5 over 19m) kubelet, cc-pool-bg6c Container image "jenkins/jenkins:lts" already present on machine
Normal Created 17m (x5 over 19m) kubelet, cc-pool-bg6c Created container jenkins
Normal Started 17m (x5 over 19m) kubelet, cc-pool-bg6c Started container jenkins
Warning BackOff 4m8s (x72 over 19m) kubelet, cc-pool-bg6c Back-off restarting failed container
有人可以帮助我指出这里的问题是什么,或在哪里寻找该问题?
非常感谢。
答案 0 :(得分:1)
好像您没有写该卷的权限。 尝试使用安全上下文以超级用户身份运行容器:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
labels:
app: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
securityContext:
fsGroup: 1000
runAsUser: 0
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- containerPort: 8080
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-pvc
答案 1 :(得分:0)
我无法添加评论(信誉不足:D)
查看广告连播日志可能会给您一些想法kubectl logs <podname>
PVC似乎可以毫无问题地分配和连接。不久前,我在部署nginx
容器时遇到类似的问题,问题是nginx
容器要求主机上具有特定的UID才能工作。检查jenkins
容器是否需要特定的UID。
此外,您可能需要在卷上设置所需的权限(取决于jenkins的要求)。