Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to install Jenkins in kubernetes

Shulou Source: shulou.com Published: 2022-06-02 10:13:59 09月30日 Update

This article shows you how to install Jenkins in kubernetes. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. K8s deploy Jenkins

1) build a Jenkins image. The Dockerfile of the construction image using Aliyun is as follows:

FROM jenkins/jenkins # this is an official image and must be built based on the official image, otherwise it will be updated after installation. Again, USER root# cleared the source of the basic image settings. Switch to Aliyun's jessie source RUN echo'> / etc/apt/sources.list.d/jessie-backports.list\ & & echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" > / etc/apt/sources.list\ & & echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" > > / etc/apt/sources.list\ & & echo "deb http://mirrors.aliyun.com/debian-security" Jessie/updates main contrib non-free "> > / etc/apt/sources.list# update the source and install the missing package RUN apt-get update & & apt-get install-y libltdl7ARG dockerGid=999RUN echo" docker:x:$ {dockerGid}: jenkins "> > / etc/group\ USER jenkins

2) deploy Jenkins image

Create a pv persistent storage volume, this time using a host file system

ApiVersion: "v1" kind: "PersistentVolume" metadata: name: jenkins-0spec: capacity: storage: "10Gi" accessModes:-"ReadWriteMany" hostPath: path: / tmp volumeName: jenkins

B. Create an account

Kubectl create-f service-account.yml

# In GKE need to get RBAC permissions first with# kubectl create clusterrolebinding cluster-admin-binding-- clusterrole=cluster-admin [--user= |-- group=]-- apiVersion: v1kind: ServiceAccountmetadata: name: jenkins namespace: default---kind: RoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: jenkins namespace: defaultrules:- 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/v1beta1kind: RoleBindingmetadata: name: jenkinsroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: jenkinssubjects:- kind: ServiceAccount name: jenkins namespace: default-kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: jenkinsClusterRole namespace: defaultrules:- 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/v1beta1kind: RoleBindingmetadata: name: jenkinsClusterRuleBindingroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jenkinsClusterRolesubjects:- kind: ServiceAccount name: jenkins namespace: default

C. Create a Jenkins service

Kubectl create-f jenkins.yml

# jenkins---apiVersion: apps/v1beta1kind: StatefulSetmetadata: name: jenkins namespace: default labels: name: jenkinsspec: serviceName: jenkins replicas: 1 updateStrategy: type: RollingUpdate template: metadata: name: jenkins labels: name: jenkinsspec: terminationGracePeriodSeconds: 10 serviceAccountName: jenkins imagePullSecrets:-name:-name: jenkins # image: jenkins/jenkins:lts -alpine # image: chadmoon/jenkins-docker-kubectl:latest h2kkan/jenkins-docker image: registry.cn-shanghai.aliyuncs.com/pml/jenkins:v1.0 imagePullPolicy: Always ports:-containerPort: 8080-containerPort: 50000 resources: limits: cpu: 1 memory: 1Gi requests: Cpu: 0.5 memory: 500Mi env:-name: LIMITS_MEMORY valueFrom: resourceFieldRef: resource: limits.memory divisor: 1Mi-name: JAVA_OPTS # value:-XX:+UnlockExperimentalVMOptions-XX:+UseCGroupMemoryLimitForHeap-XX:MaxRAMFraction=1-XshowSettings: Vm-Dhudson.slaves.NodeProvisioner.initialDelay=0-Dhudson.slaves.NodeProvisioner.MARGIN=50-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 value:-Xmx800m-XshowSettings:vm-Dhudson.slaves.NodeProvisioner.initialDelay=0-Dhudson.slaves.NodeProvisioner.MARGIN=50-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 volumeMounts:-name: jenkins-home mountPath: / var/jenkins_home-name: docker mountPath: / usr/bin/docker-name: docker-sock mountPath: / var/run/docker.sock securityContext: privileged: true volumes:-name: docker hostPath: path: / usr/bin/docker-name: docker-sock hostPath: path: / var/run/docker.sock volumeClaimTemplates:- Metadata: name: jenkins-home # annotations: # volume.beta.kubernetes.io/storage-class: anything spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 1Gi---apiVersion: v1kind: Servicemetadata: name: jenkins namespace: default annotations: # ensure the client ip is propagated to avoid the invalid crumb issue (k8s

Tags: Mirroring login content official skills knowledge ports storage updates services no concise concise warehouse code credentials picture bar basic host host Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Shulou Tech Info Shulou Technology MariaDB