Construcción del entorno de recursos de la aplicación K8s-Jenkins

K8s-Jenkins

createBy lln
createTime 2023-04-10
k8s version 1.20.0
kuboard version 3.5.2.1

注意事项1
	安装后的默认认证密码需要查看日志获取,或者查看本地卷文件
	vim  ${jenkinsHome}/secrets/initialAdminPassword
注意事项2
	安装完成后需要修改两个配置文件,目的修改Jenkins插件默认安装地址为国内镜像。分别为:
	1、default.json。位于目录(默认为/var/jenkins_home)下的 /updates/default.json 
	2、hudson.model.UpdateCenter.xml 。如果 default.json 文件不存在的话,就会从 {Jenkins工作目录}/hudson.model.UpdateCenter.xml 文件中读取插件配置文件的地址。
	参考博客1链接: [link](https://blog.csdn.net/qq_45537574/article/details/108164992/)
	参考博客2链接 [link](https://blog.csdn.net/aiwangtingyun/article/details/123534884?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168137239816800182146731%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=168137239816800182146731&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-3-123534884-null-null.142^v83^insert_down38,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=jenkins%20%E9%85%8D%E7%BD%AE%E5%8A%A0%E9%80%9F)
注意事项3
	脚本中的Nfs和Pvc需根据实际情况修改,建议使用可视化工具如kuboard进行资源的流水线导入,分步安装,而不是直接执行。

Registros de contenido de configuración XML

<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>
</sites>

Json modificar registro de comando

sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json
sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json

Archivo Jenkins Yaml

apiVersion: v1
kind: Namespace
metadata:
  name: jenkins
  
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-pvc
  namespace: jenkins
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
      
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins-sa
  namespace: jenkins
  
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: jenkins-cr
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-crd
roleRef:
  kind: ClusterRole
  name: jenkins-cr
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: jenkins-sa
  namespace: jenkins
  
---  
apiVersion: apps/v1  
kind: Deployment
metadata:
  name: jenkins
  namespace: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 8.8.8.8
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        imagePullPolicy: IfNotPresent
        env:
        - name: JAVA_OPTS
          value: -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        resources:
          limits:
            cpu: 2000m
            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
          mountPath: /var/jenkins_home
      securityContext:
        fsGroup: 1000
      volumes:
      - name: jenkinshome
        persistentVolumeClaim:
          claimName: jenkins-pvc
          
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
  labels:
    app: jenkins
spec:
  selector:
    app: jenkins
  type: NodePort
  ports:
  - name: web
    port: 8080
    targetPort: web
    nodePort: 30002
  - name: agent
    port: 50000
    targetPort: agent

Supongo que te gusta

Origin blog.csdn.net/weixin_42559985/article/details/130132254
Recomendado
Clasificación