首先将下面代码复制好保存到 jenkins.yaml 中:
# more jenkins.yaml
#-----Deployment----------------
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
labels:
app: jenkins
spec:
replicas: 1 #副本数为1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: docker.io/jenkins:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
---
#------service---------------
apiVersion: v1
kind: Service
metadata:
name: jenkins
labels:
name: jenkins
spec:
type: NodePort
ports:
- name: jenkins
port: 8080
targetPort: 8080
nodePort: 30009 #开启nodeport
- name: jenkins-agent
port: 50000
targetPort: 50000
nodePort: 30010
selector:
app: jenkins
其次执行下面命令:
1、kubectl apply -f jenkins.yaml //执行yaml文件安装Jenkins
2、kubectl delete -f jenkins.yaml //如果出现问题 可以删除后重新装 删除命令
3、kubectl describe pod jenkins //可以查看安装的Jenkins pod 详细信息
当出现Jenkins无法联网出现离线问题时:
1、docker exec -it 074acdfc3ab3 /bin/bash //进入到Jenkins的docker中
//关键在于要ping通才可以的
2、ping www.baidu.com
//可以查看docker的日志问题 074acdfc3ab3 为容器的id
3、docker logs 074acdfc3ab3