K8s下配置Jenkins

1.从Docker源pull最新的镜像

docker pull jenkins

2.官方启动Jenkins的命令(不执行)

docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins

3.在K8s环境中配置yaml文件

apiVersion: v1
kind: Service
metadata:
  name: epic-jenkins
  labels:
    app: jenkins
spec:
  ports:
    - port: 8080         #jenkins的内部监听端口
      targetPort: 8080
      protocol: TCP
      nodePort: 30601     #页面访问的端口入口,不与其他应用重复,且在k8s要求的端口范围内
  type: NodePort
  selector:
    app: jenkins
    tier: jenkins
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: epic-jenkins
  labels:
    app: jenkins
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      containers:
      - image: docker.io/jenkins:latest     #镜像库和版本
        name: epic-jenkins
        ports:
        - containerPort: 8080      #jenkins的内部监听端口
          name: epic-jenkins
#        volumeMounts:                     #以下部分为配置Nginx时使用
#        - mountPath: "/etc/nginx/conf.d"
#          name: nginx-config
#      volumes:
#      - name: nginx-config
#        hostPath:
#          path: "/home/test"

4.启动

kubectl create -f /opt/install/kubernetes/jenkins.yaml

5.打开Jenkins页面

打开机器IP:30601
admin password 从日志中获取
kubectl logs -f epic-jenkins-1932447262-tm740


K8s下配置Jenkins_第1张图片
admin password
K8s下配置Jenkins_第2张图片
jenkins界面

你可能感兴趣的:(K8s下配置Jenkins)