首页 > 其他分享 >1.2. jenkins安装和部署-k8s版本

1.2. jenkins安装和部署-k8s版本

时间:2022-11-26 10:35:38浏览次数:43  
标签:kind name 1.2 kubesphere devops ws jenkins k8s

物料清单

- 组件 - 版本
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

标签:kind,name,1.2,kubesphere,devops,ws,jenkins,k8s
From: https://www.cnblogs.com/qingfengfumian/p/16913499.html

相关文章

  • 1.3. jenkins插件安装
    配置代理由于国外的升级站点网络不稳定,因此在安装插件前,我们首先要将其修改为中文社区提供的站点https://updates.jenkins-zh.cn/update-center.json.操作步骤点击......
  • Java.11.26
    一1..breakcontinue1.1.break在任何循环语句的主体部分,均可用break控制循环的流程。break用于强行退出循环,不执行循环中剩余的语句。(break语句也在switc......
  • centos8上使用kubeasz3.0.0项目ansible自动的二进制部署k8s高可用集群
    一、ansible的kubeasz3.0.0部署多master高可用kubernetes集群环境#二进制部署,ansible的kubeasz3.0.0部署多master高可用kubernetes集群环境1.#主机名设置类型服务器I......
  • Jenkinsfile 详解
    PipelinePipeline是Jenkins中最为灵活的job构建方式,可实现像流水线一样调度Jenkins任务,通过Jenkinsfile描述整个持续集成流程。Pipeline支持使用声明式语法编......
  • 每天一点基础K8S---kubeadm搭建master节点高可用K8S集群--version 1.25.3
    搭建条件centos-stream-8[root@localhost~]#cat/etc/os-releaseNAME="CentOSStream"|主机名|IP地址|role||master-worker-node-1|192.168.122.89/24|......
  • jenkins pipline 基本语法详解(第四周)
    pipline简介pipline运行在jenkins2.X版本的核心插件,Pipline就是一套运行于Jenkins上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成......
  • 11.25lc每日一题-809. 情感丰富的文字
    有时候人们会用重复写一些字母来表示额外的感受,比如"hello"->"heeellooo","hi"->"hiii"。我们将相邻字母都相同的一串字符定义为相同字母组,例如:"h","eee","ll","o......
  • 11.25.6
    #include<stdio.h>intmain(){ intn,i,j,sum=0; scanf("%d",&n); for(i=1;i<=n;i++) {for(j=1;j<i;j++) {if(i%j==0)sum+=j; } if(i==sum){printf("%ditsfacto......
  • 2022.11.21-27 训练小记
    2022/11/21-27训练小记CF1761D.CarryBit赛时感觉很不可做,对着题解想明白的qwq下文起用\(a_i,b_i\)表示其二进制表示下的第\(i\)位(1-indexed)。人类智慧地想到记......
  • GitlabRunner+K8S 实现自动化发布
    前置条件:一台Linux服务器,安装好Docker一个K8s集群环境一个Gitlab仓库,可以自己搭建或者直接使用官方仓库(中文版gitlab:https://jihulab.com/)一个镜像仓库,用于存储doc......