Jenkins k8s dynamically increases/decreases jenkins-salve and creates and deploys a jenkins-master image,

Source: Internet
Author: User
Tags docker cp k8s

Jenkins k8s dynamically increases/decreases jenkins-salve and creates and deploys a jenkins-master image,

In this tutorial, k8s is installed by default.

1. Create a jenkins-master

1. Pull the 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. Access jenkins 127.0.0.1: 8080

4. Get the jenkins initial key

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

5. Select Install suggested plugins

6. Set the administrator username and password

7. Install the Kubernetes plugin
System Management-> Management plug-in-> optional plug-in-> enter Kubernetes plugin-> select Kubernetes plugin-> directly install

8. Obtain the kubectl command in linux. If the command cannot be downloaded, double quotation marks must be added to the link.

9. go to the container to install libltdl. the so.7 library file is not followed by the docker-in-docker method, the error: error while loading shared libraries: libltdl will be reported. so.7: cannot open shared object file: No such file or directory

docker exec -ti jenkins-masterapt-get updateapt-get install  libltdl7apt-get clean

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

Docker cp jenkins-master:/var/jenkins_home.

11. Package the container containing the Kubernetes plugin

Docker commit jenkins-master jenkins-k8s-master: 1.0

You can also use the following Dockerfile to directly install the Kubernetes plugin plug-in. However, if you are not familiar with the plug-in name and plug-in version, it is not as simple as the above method, and this method does not automatically install dependencies.

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectlecho Kubernetes plugin:1.1.3 >> plugins.txtecho Variant Plugin:1.1 >> plugins.txtcat<< EOF >DockerfileFROM jenkinsCOPY plugins.txt /usr/share/jenkins/plugins.txtCOPY kubectl /usr/bin/RUN apt-get update && apt-get install libltdl7 && apt-get cleanRUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txtEOFdocker build -t jenkins-k8s-master:1.0 .
2. Deploy jenkins-master

Cat jenkins-deploy.yaml

ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: jenkins namespace: ci labels: app: jenkinsspec: strategy: type: Recreate template: metadata: labels: app: jenkins tier: jenkins spec: containers:-image: jenkins-k8s-master: 1.0 // replace the name of your own image here: 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 convert docker. the sock command is mounted to the image-name: jenkinshome mountPath:/var/jenkins_home-name: kube-config mountPath:/root /. kube-name: docker-binary mountPath:/usr/bin/docker // here we use the docker in docker method to mount the docker command to the image volumes:-name: docker hostPath: path:/var/run/docker. sock-name: kube-config nfs: server: 10.10.14.216 path: "/data/nfsshare/k8s /. kube "// set. the kube file is mounted to the container through nfs-name: docker-binary hostPath: path:/usr/bin/docker-name: jenkinshome nfs: server: 10.10.14.216 path: "/data/nfsshare/k8s/jenkins/home" // mount the working directory of jenkins to NFS for persistence. If not, delete it.

Cat jenkins-service-ingress.yaml

apiVersion: v1kind: Servicemetadata:  name: jenkins-web-ui  namespace: ci  labels:    app: jenkinsspec:  ports:    - port: 8080      targetPort: 8080      name: web-ui    - port: 50000      targetPort: 50000      name: agent  selector:    app: jenkins    tier: jenkins---apiVersion: extensions/v1beta1kind: Ingressmetadata:  name: jenkins-web-ui  namespace: cispec:  rules:  - host: jenkins.com    http:      paths:      - backend:          serviceName: jenkins-web-ui          servicePort: 8080

Deploy jenkins-master

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

After deployment, add x. x jenkins.com to the local hosts file.
X. x indicates the address of an ip address in your cluster.

Enter jenkins.com in the local browser to log on to jenkins.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.