jenkins k8s dynamic increase and decrease jenkins-salve (1) production and deployment of jenkins-master image

Keywords: jenkins Docker Ruby Attribute

By default, k8s is installed in this tutorial

**

I. Making jenkins-master

**

1. Pull jenkins image

docker pull jenkinsci/jenkins:lts

2. Run the jenkins image

docker run -tid -p 8080:8080 –name jenkins-master jenkinsci/jenkins:lts

3. Visit jenkins 127.0.0.1:8080

4. Get the initial jenkins key

docker exec -ti jenkins-master cat /var/jenkins_home/secrets/initialAdminPassword

5. Select Install suggested plugins

6. Setting Administrator User Name and Password

7. Install the Kubernetes plugin plug-in
System Management -> Management Plug-ins -> Optional Plug-ins -> Enter Kubernetes plugin -> Select Kubernetes plugin -> Direct Installation

8. Get the kubectl command of the linux system. If you can't download it here, you need to add double quotation marks to the links.

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl

9. Installing libltdl.so.7 library file into container without using docker-in-docker mode will result in error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory

docker exec -ti jenkins-master
apt-get update
apt-get install  libltdl7
apt-get clean

10. Copy the jenkins configuration file. If you use NFS to persist data, you need to put this directory in NFS and hang it in k8s. Here, the NFS service architecture is not stated too much.

docker cp jenkins-master:/var/jenkins_home .

11. Package container with Kubernetes plugin plug-in

docker commit jenkins-master jenkins-k8s-master:1.0

The following Dockerfile can also be used to install Kubernetes plugin plugins directly, but for those who are not familiar with the plug-in name and version, it is not as simple as the above method, and this method will not automatically install dependencies.

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl
echo Kubernetes plugin:1.1.3 >> plugins.txt
echo Variant Plugin:1.1 >> plugins.txt
cat<< EOF >Dockerfile
FROM jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
COPY kubectl /usr/bin/
RUN apt-get update && apt-get install libltdl7 && apt-get clean
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
EOF
docker build -t jenkins-k8s-master:1.0 .

II. Deployment of jenkins-master

cat jenkins-deploy.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  namespace: ci
  labels:
    app: jenkins
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      containers:
      - image: jenkins-k8s-master:1.0 //Here's the name of your own mirror.
        name: jenkins
        securityContext:
          privileged: true
        ports:
        - name: jenkins
          containerPort: 8080
        - name: agent
          containerPort: 50000
          protocol: TCP
        volumeMounts:
        - name: docker
          mountPath: /var/run/docker.sock //Here, docker in docker is used to hang the docker.sock command in image.
        - name: jenkinshome
          mountPath: /var/jenkins_home
        - name: kube-config
          mountPath: /root/.kube
        - name: docker-binary
          mountPath: /usr/bin/docker //Here, docker in docker is used to hang the docker command in image.
      volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: kube-config
        nfs:
          server: 10.10.14.216
          path: "/data/nfsshare/k8s/.kube" //Here, the cluster. kube file is mounted into the container by nfs
      - name: docker-binary
        hostPath:
          path: /usr/bin/docker
      - name: jenkinshome
        nfs:
          server: 10.10.14.216
          path: "/data/nfsshare/k8s/jenkins/home" //Here, hang the working directory of jenkins to NFS for persistence. If you don't need to delete it, please

cat jenkins-service-ingress.yaml

apiVersion: v1
kind: Service
metadata:
  name: jenkins-web-ui
  namespace: ci
  labels:
    app: jenkins
spec:
  ports:
    - port: 8080
      targetPort: 8080
      name: web-ui
    - port: 50000
      targetPort: 50000
      name: agent
  selector:
    app: jenkins
    tier: jenkins
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jenkins-web-ui
  namespace: ci
spec:
  rules:
  - host: jenkins.com
    http:
      paths:
      - backend:
          serviceName: jenkins-web-ui
          servicePort: 8080

Deployment of jenkins-master

kubectl apply -f jenkins-deploy.yaml && kubectl apply -f jenkins-service-ingress.yaml

After deployment, you can add x.x.x.x.x jenkins.com parsing to the local hosts file
Where x.x.x.x is the address of an ip in your cluster

Enter jenkins.com in your local browser and log in to jenkins.

Posted by shimano55 on Wed, 06 Feb 2019 02:33:17 -0800