容器化简易cicd(1):kubernetes安装jenkins master

  sre

共三页:

容器化简易cicd(1):kubernetes安装jenkins master

容器化简易cicd(2):jenkins slave安装

容器化简易cicd(3):jenkins+gitlab 自动发布

k8s操作

Namespace cicd

apiVersion: v1
kind: Namespace
metadata:
  name: cicd

rbac jenkins

apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
  namespace: cicd
---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: jenkins
rules:
  - apiGroups: ["extensions", "apps"]
    resources: ["deployments"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
  - apiGroups: [""]
    resources: ["services"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["create","delete","get","list","patch","update","watch"]
  - apiGroups: [""]
    resources: ["pods/exec"]
    verbs: ["create","delete","get","list","patch","update","watch"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get","list","watch"]
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get"]

---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins
  namespace: cicd
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: jenkins
subjects:
  - kind: ServiceAccount
    name: jenkins
    namespace: cicd

pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-master  
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "500Gi"
  volumeName: 
  storageClassName: nfs


jenkins Deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins-master         
spec:
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      terminationGracePeriodSeconds: 10     
      serviceAccount: jenkins            
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts              
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080               
          name: jenkins-web
          protocol: TCP
        - containerPort: 50000              
          name: jenkins-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: jenkinshome
          subPath: jenkins
          mountPath: /var/jenkins_home
        env:
        - name: LIMITS_MEMORY
          valueFrom:
            resourceFieldRef:
              resource: limits.memory
              divisor: 1Mi
        - name: JAVA_OPTS
          value: -Xmx$(LIMITS_MEMORY)m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai
      securityContext:
        fsGroup: 1000
      volumes:
      - name: jenkinshome
        persistentVolumeClaim:
          claimName: jenkins-master     

svc

apiVersion: v1
kind: Service
metadata:
  name: jenkins-master
  labels:
    app: jenkins
spec:
  selector:
    app: jenkins
  type: NodePort
  ports:
  - name: web
    port: 8080
    targetPort: 8080
    nodePort: 30085
  - name: agent
    port: 50000
    targetPort: 50000
    nodePort: 30086

配置jenkins

查看jenkins启动日志:
1.png
登录密码为9d7f441ba7ac44b4a142af1db360836f
登录jenkins:http://172.16.0.12:30085
填入以上密码
2.png
插件选推荐即可
3.png
插件安装,视网络情况而定
4.png
存在下载超时的情况不管,以后再单独安装:
7.png
6.png
5.png
安装完成后到jenkins主界面
8.png
9.png

2 thoughts on - 容器化简易cicd(1):kubernetes安装jenkins master

LEAVE A COMMENT

Captcha Code