Get the App
SLTechnology News&Howtos  ›  Servers  › 

Kubernetes installation and configuration Jenkins

Shulou Source: shulou.com Published: 2022-06-03 05:16:44 11月16日 Update

First, Jenkins installation preparation condition # in the operation and maintenance host operation: 1. Prepare the image ~] # docker pull jenkins/jenkins:2.190.3~] # docker images | grep jenkins~] # docker tag 22b8b9a84dbe test-harbor.cedarhd.com/public/jenkins:v2.190.3~] # docker push test-harbor.cedarhd.com/public/jenkins:v2.190.32. Custom Dockerfile# images pulled from the official website need to be customized. Mkdir-p / data/dockerfile/jenkinscd / data/dockerfile/jenkinsvim DockerfileFROM test-harbor.cedarhd.com/public/jenkins:v2.190.3USER rootRUN / bin/cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime & &\ echo 'Asia/Shanghai' > / etc/timezoneADD id_rsa / root/.ssh/id_rsaADD config.json / root/.docker/config.jsonADD get-docker.sh / get-docker can be deployed (running on the OPS host) in the K8s cluster. ShRUN echo "StrictHostKeyChecking no" > > / etc/ssh/ssh_config & &\ / get-docker.sh# explain: >-set the container user to root >-set the time zone within the container >-add the ssh private key (used when using git to pull code The paired public key should be configured in gitlab) >-added the config file to log in to the self-built harbor repository >-modified the ssh client >-install a docker client >-if the construction fails due to network reasons, you can use the final "/ get-docker.sh-- mirror Aliyun" 3. Generate ssh key pair jenkins] # ssh-keygen-t rsa-b 2048-C "xxxxxxx@qq.com"-N "- f / root/.ssh/id_rsaGenerating public/private rsa key pair.Your identification has been saved in / root/.ssh/id_rsa.Your public key has been saved in / root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:bIajghsF/BqJouTeNvZXvQWvolAKWvhVSuZ3uVWoVXU 897307140@qq.comThe key's randomart image is:+--- [RSA 2048]-+ |. E | |. O. | |. O. O. | |.. + + oo +.. | | oroom.+ + ooS+..o | | = o* o.roomroom.o. O | | +. O. + | | .o. =.. . O | |.. o.o.... . | | +-[SHA256]-+ enkins] # cp / root/.ssh/id_rsa .4. | Prepare other documents jenkins] # cp / root/.docker/config.json .jenkins] # curl-fsSL get.docker.com-o get-docker.shjenkins] # chmod + x get-docker.shjenkins] # lltotal 28 RW-1 root root 160 Jan 28 23:41 config.json-rw-r--r-- 1 root root 355 Jan 28 23:38 Dockerfile-rwxr-xr-x 1 root root 13216 Jan 28 23:42 get-docker.sh-rw -1 root root 1675 Jan 28 23:38 id_rsa5, Log in to Harbor to create an infra private warehouse to create a project for infra Access level is Private6, generate jenkins image jenkins] # docker build-t harbor.phc-dow.com/infra/jenkins:v2.190.3 .jenkins] # docker push test-harbor.cedarhd.com/infra/jenkins:v2.190.37, prepare for shared storage yum install nfs-utils-y] # vim / etc/exports/data/nfs-volume 10.4.7.0 Unip 24 (rw No_root_squash) # start the NFS service ~] # mkdir-p / data/nfs-volume~] # systemctl start nfs~] # systemctl enable nfs II. Jenkins installation Resource configuration list mkdir / data/k8s-yaml/jenkins & & mkdir-p / data/nfs-volume/jenkins_home & & cd / data/k8s-yaml/jenkins~] # vi dp.yaml # is used to create and configure pod controllers and pod resources kind: DeploymentapiVersion: extensions/v1beta1metadata: name: jenkins namespace: infra labels: name: jenkinsspec: replicas: 1 selector: matchLabels: name: jenkins template: metadata: labels : app: jenkins name: jenkins spec: volumes:-name: data nfs: server: test-operator.cedarhd.com path: / data/nfs-volume/jenkins_home-name: docker hostPath: path: / run/docker.sock type:''containers:-name: jenkins image: test- Harbor.cedarhd.com/infra/jenkins:v2.190.3 imagePullPolicy: IfNotPresent ports:-containerPort: 8080 protocol: TCP env:-name: JAVA_OPTS value:-Xmx512m-Xms512m volumeMounts:-name: data mountPath: / var/jenkins_home-name: docker mountPath: / run/docker.sock imagePullSecrets: -name: harbor securityContext: runAsUser: 0 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 revisionHistoryLimit: 7 progressDeadlineSeconds: 600 Murray- -~] # vim service.yaml # to create cluster ip and port mapping kind: ServiceapiVersion: v1metadata: name: jenkins namespace: infraspec: ports:-protocol: TCP port: 80 targetPort: 8080 selector: app: jenkinsjenkins] # cat ingress.yaml # to create ingress forwarding rules kind: IngressapiVersion: extensions/v1beta1metadata: name: jenkins namespace: infraspec: rules: -host: test-jenkins.cedarhd.com http: paths:-path: / backend: serviceName: jenkins servicePort: 80Murmuri- -third, Create a resource kubectl apply-f http://k8s-yaml.cedarhd.com/jenkins/dp.yaml kubectl apply-f http://k8s-yaml.cedarhd.com/jenkins/service.yaml kubectl apply-f http://k8s-yaml.cedarhd.com/jenkins/ingress.yaml on one of the operation nodes

Tags: Prepare configure resource mirror host warehouse client container file generate code public key reason client key controller time zone condition list user Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Redmi Xiaomi Docker