好吧,我正试图在kubernetes'中设置一个Jenkins容器的本地版本。 minikube和我使用this guide作为模型。
我遇到的问题是hostPath似乎没有正确安装。
当我尝试安装主机路径而不使用" persistentVolumeClaim" 我的代码看起来像这样:
deployment_jenkins.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins
spec:
replicas: 1
template:
metadata:
labels:
app: master
spec:
containers:
- name: master
image: jenkins:2.7.2
ports:
- containerPort: 8080
- containerPort: 50000
readinessProbe:
httpGet:
path: /login
port: 8080
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 2
failureThreshold: 5
env:
- name: JENKINS_OPTS
valueFrom:
secretKeyRef:
name: jenkins
key: options
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkins-home
resources:
limits:
cpu: 500m
memory: 1500Mi
requests:
cpu: 500m
memory: 1500Mi
volumes:
- name: jenkins-home
hostPath:
path: /data
当我运行 kubectl apply -f deployment_jenkins.yaml 时出现此错误:
my-mac kubernetes $ kubectl apply -f deployment_jenkins.yaml
error: error validating "deployment_jenkins.yaml": error validating data:
found invalid field hostPath for v1.PodSpec; if you choose to ignore these
errors, turn validation off with --validate=false
然后当我尝试使用声明时,我明白了:
persistent_volume_claim_jenkins.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: jenkins-home-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumeName: jenkins-home
persistent_volume_jenkins.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: jenkins-home
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /data
deployment_jenkins.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins
spec:
replicas: 1
template:
metadata:
labels:
app: master
spec:
containers:
- name: master
image: jenkins:2.7.2
ports:
- containerPort: 8080
- containerPort: 50000
readinessProbe:
httpGet:
path: /login
port: 8080
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 2
failureThreshold: 5
env:
- name: JENKINS_OPTS
valueFrom:
secretKeyRef:
name: jenkins
key: options
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkins-home
resources:
limits:
cpu: 500m
memory: 1500Mi
requests:
cpu: 500m
memory: 1500Mi
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-home-claim
然后我运行命令:
my-mac kubernetes $ kubectl apply -f .
deployment "jenkins" configured
persistentvolumeclaim "jenkins-home-claim" configured
persistentvolume "jenkins-home" configured
我非常困惑,在弄清楚我做错了什么以及如何让它发挥作用方面的任何帮助都将非常感激。
答案 0 :(得分:1)
你的一些yaml错误缩进导致不同(破碎)的解释:
volumes:
- name: jenkins-home
hostPath:
path: /data
这是一个包含两个字段volumes
和hostPath
的对象。你想要的是:
volumes:
- name: jenkins-home
hostPath:
path: /data
此外,我建议您始终在yaml中引用(非阻止)字符串以避免意外:
volumes:
- name: 'jenkins-home'
hostPath:
path: '/data'