物料清单

– 组件 – 版本
k8s 1.23.10
kubesphere v3.3.1
jenkins版本 2.361.4

部署

创建Namespace

  • 在kubesphere上工作台->企业空间->点击创建->填写名称wsdevops->点击创建企业空间的创建。
  • 点击创建好的wsdevops名称->选择左侧的项目->点击创建->输入名称ws-devops,完成NS的创建.
# 以下为kubesphere kubectl get ns  ws-devops -o yaml 输出内容
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubesphere.io/creator: admin
  finalizers:
  - finalizers.kubesphere.io/namespaces
  labels:
    kubernetes.io/metadata.name: ws-devops
    kubesphere.io/namespace: ws-devops
    kubesphere.io/workspace: wsdevops
  name: ws-devops
  ownerReferences:
  - apiVersion: tenant.kubesphere.io/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: Workspace
    name: wsdevops
    uid: aead3e2f-b203-4c4c-ac0a-14430cfc1477
  resourceVersion: "160501"
  uid: 1656558f-4d03-448d-aef9-81eea5f341cc
spec:
  finalizers:
  - kubernetes

创建用户角色

  • 执行命令kubectl apply -f account.yaml
  • account.yaml内容如下:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
  namespace: ws-devops

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
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/v1
kind: ClusterRoleBinding
metadata:
  name: jenkins
  namespace: ws-devops
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: jenkins
subjects:
  - kind: ServiceAccount
    name: jenkins
    namespace: ws-devops

创建PV、PVC

  • 执行命令kubectl apply -f pvpvc.yaml
  • pvpvc.yaml文件内容如下:
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-pv
spec:
  capacity:
    storage: 20Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Delete
  nfs:
    server: 172.16.50.100
    path: /data/kubernetes/jenkins

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-pv
  namespace: ws-devops
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Gi

部署jenkins deployment

  • 执行kubectl apply -f deployment.yaml
  • deployment.yaml内容如下
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: ws-devops
spec: 
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      terminationGracePeriodSeconds: 10
      serviceAccount: jenkins
      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: jenkinshome
          subPath: jenkins
          mountPath: /var/jenkins_home
      securityContext:
        fsGroup: 1000
      volumes:
      - name: jenkinshome
        persistentVolumeClaim:
          claimName: jenkins-pv

部署service

  • 执行命令kubectl apply -f serivce.yaml

  • service.yaml内容如下:

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

设置ingress

  • 可以从kubesphere 工作台->企业空间->点击wsdevops->点击左侧项目->点击ws-devops->点击左侧应用负载->应用路由->点击创建->按步骤添加完成

    add-ingress

    ingress-router-rule

  • 生成的配置如下

    piVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kubesphere.io/creator: admin
      creationTimestamp: "2022-11-19T08:18:17Z"
      generation: 3
      name: jenkins
      namespace: ws-devops
      resourceVersion: "473180"
      uid: e7ed6f46-f1c7-4f86-a089-a7f5632cbd1c
    spec:
      rules:
      - host: jenkins.wsdevops.com
        http:
          paths:
          - backend:
              service:
                name: jenkins
                port:
                  number: 8080
            path: /
            pathType: ImplementationSpecific
    status:
      loadBalancer:
        ingress:
        - ip: 172.16.50.156
    
    • 设置好后,可以本地host绑定在ingress填写的域名,如果域名已经备案,也可以直接在dns上进行解析。

      [pengyang@dev]$ cat /etc/hosts                     
      ##
      # Host Database
      #
      # localhost is used to configure the loopback interface
      # when the system is booting.  Do not change this entry.
      ##
      127.0.0.1	localhost
      255.255.255.255	broadcasthost
      ::1             localhost
      127.0.0.1 swscan.apple.com
      127.0.0.1 swcdn.apple.com
      127.0.0.1 swdist.apple.com
      # Added by Docker Desktop
      # To allow the same kube context to work on the host and the container:
      127.0.0.1 kubernetes.docker.internal
      
      # End of section
      ## 此处为jenkins的解析,IP为node节点的任意一个,可以写多条
      172.16.50.155 jenkins.wsdevops.com
      172.16.50.156 jenkins.wsdevops.com
      172.16.50.157 jenkins.wsdevops.com
      172.16.50.240 kubesphere.wsdevops.com
      

      jenkins配置

      • 等待容器状态准备就绪后,就可以进行访问了,可以直接点击kubesphere上的访问服务
        ingress-domain

原文地址:http://www.cnblogs.com/qingfengfumian/p/16913499.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性