zoukankan      html  css  js  c++  java
  • k8s下安装jenkins master

    1、创建servicecount和并绑定ClusterRole

    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      labels:
        name: jenkins
      name: jenkins
      namespace: default
    
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: jenkins
      labels:
        name: jenkins
    subjects:
      - kind: ServiceAccount
        name: jenkins
        namespace: jenkins
    roleRef:
      kind: ClusterRole
      name: cluster-admin
      apiGroup: rbac.authorization.k8s.io

    2、创建jenkins-master使用的pv和pvc

    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: jenkins-master
    spec:
      persistentVolumeReclaimPolicy: Recycle
      capacity:
        storage: 5Gi
      accessModes:
        - ReadWriteMany
      nfs:
        server: 192.168.0.211
        path: /data/nfs/jenkins-master
    
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: jenkins-master
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 5Gi

    3、创建jenkins-master的deployment配置

    此处采用nfs挂载jenkins的数据目录

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: jenkins
      labels:
        name: jenkins
    spec:
      selector:
        matchLabels:
          name: jenkins
      replicas: 1
      template:
        metadata:
          labels:
            name: jenkins
        spec:
          serviceAccountName: jenkins
          containers:
          - name: jenkins
            image: 192.168.0.217:5000/library/jenkins:lts
            ports:
            - name: http
              containerPort: 8080
            - name: agent
              containerPort: 50000
            resources:
              limits:
                memory: 2Gi
                cpu: "1000m"
              requests:
                memory: 1Gi
                cpu: "500m"
            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
                     "
            volumeMounts:
            - name: jenkins-home
              mountPath: /var/jenkins_home
          volumes:
          - name: jenkins-home
            persistentVolumeClaim:
              claimName: jenkins-master

    4、创建jenkins-master的service配置

    此处采用两种方式:

    第一种:采用NodePort方式

    kind: Service
    apiVersion: v1
    metadata:
      labels:
        name: jenkins
      name: jenkins
      namespace: default
    spec:
      selector:
        name: jenkins
      type: NodePort
      ports:
        - name: http
          port: 8080
          targetPort: 8080
          nodePort: 30011
        - name: agent
          port: 50000
          targetPort: 50000
          nodePort: 30012

    第二种:采用ClusterIP方式,并使用ingress方式访问

    kind: Service
    apiVersion: v1
    metadata:
      labels:
        name: jenkins
      name: jenkins
      namespace: default
    spec:
      selector:
        name: jenkins
      ports:
        - name: http
          port: 8080
          targetPort: 8080
        - name: agent
          port: 50000
          targetPort: 50000

    ingress文件如下:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: ingress-myapp
      namespace: default
    spec:
      rules:
      - host: myapp.test.com
        http:
          paths:
          - path:
            backend:
              serviceName: jenkins
              servicePort: 8080

    在本地配置host后即可访问jenkins

  • 相关阅读:
    281. Zigzag Iterator
    298. Binary Tree Longest Consecutive Sequence
    482. License Key Formatting
    361. Bomb Enemy
    373. Find K Pairs with Smallest Sums
    304. Range Sum Query 2D
    308. Range Sum Query 2D
    307. Range Sum Query
    303. Range Sum Query
    247. Segment Tree Query II
  • 原文地址:https://www.cnblogs.com/deny/p/13880579.html
Copyright © 2011-2022 走看看