kubernetes部署jenkins

参考:kubernetes 部署 Jenkins jenkins kubernetes pipeline_mob64ca14116c53的技术博客_51CTO博客

第七篇:kubernetes部署jenkins-CSDN博客

1、当前kubernetes集群已部署nfs服务

showmount -e

创建jenkins目录

kubernetes部署jenkins_第1张图片

2、添加jenkins的pvc

kubectl create namespace jenkins-k8s

cd /opt/dockerfile/jenkins/

touch jenkins-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-k8s-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
   server: 192.168.1.247
   path: /opt/nfsdata/jenkins

touch jeckins-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-k8s-pvc
  namespace: jenkins-k8s
spec:
  resources:
    requests:
      storage: 10Gi
  accessModes:
    - ReadWriteMany

kubectl get pv -n jenkins-k8s

 创建一个sa账号,做rbac授权

kubectl create sa jenkins-k8s-sa -n jenkins-k8s

kubectl create clusterrolebinding jenkins-k8s-sa-cluster -n jenkins-k8s  --clusterrole=cluster-admin --serviceaccount=jenkins-k8s:jenkins-k8s-sa

2、部署 jenkins

kubectl apply -f jeckins-deploy.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: jenkins
  namespace: jenkins-k8s
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      serviceAccount: jenkins-k8s-sa
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        resources:
          limits:
            cpu: 1000m
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 512Mi
        livenessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        volumeMounts:
        - name: jenkins-volume
          subPath: jenkins-home
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-volume
        persistentVolumeClaim:
          claimName: jenkins-k8s-pvc

kubectl apply -f jeckins-deploy.yaml

kubectl describe pod jenkins-74bb6797d9-qd92c -n jenkins-k8s
 

kubectl logs pod jenkins-74bb6797d9-qd92c -c jenkins -n jenkins-k8s
没权限

chown -R 1000:1000 /opt/nfsdata/jenkins

kubectl delete -f jeckins-deploy.yaml

重装

kubectl apply -f jeckins-deploy.yaml

kubectl get pod -n jenkins-k8s  -owide

3、验证

kubectl get pod -n jenkins-k8s -owide

curl 10.100.27.19:8080

kubernetes部署jenkins_第2张图片

4、kubectl apply -f jenkins-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: jenkins-service
  namespace: jenkins-k8s
  labels:
    app: jenkins
spec:
  selector:
    app: jenkins
  type: NodePort
  ports:
  - name: web
    port: 8080
    targetPort: web
    nodePort: 30002
  - name: agent
    port: 50000
    targetPort: agent

kubectl get svc -n jenkins-k8s

kubernetes部署jenkins_第3张图片

cd /opt/nfsdata/jenkins/jenkins-home/secrets

kubernetes部署jenkins_第4张图片

若无法正常配置,可尝试http://192.168.1.12:30002/restart

安装推荐的插件:

kubernetes部署jenkins_第5张图片

创建用户名密码,搭建完成。

http://192.168.1.247:30002/


 

kubernetes部署jenkins_第6张图片

你可能感兴趣的:(kubernetes,jenkins,java)