Coder Social home page Coder Social logo

jenkins-in-kubernetes's Introduction

Jenkins in Kubernetes

This repository has a Dockerfile and a helm chart for setting up a simple Jenkins master for running in Kubernetes.

This Jenkins has the required tools to work in and with Kubernetes

  • Jenkins application with pre-loaded plugins (see plugins.txt)
  • Skipped setup wizard
    • You can control admin user and password with --set adminUser=${USER},adminPassword=${PASSWORD}
    • You can add and remove plugins by editing the plugins.txt file
  • Docker for managing a Docker CI lifecycle
  • kubectl command line client for working with the Kubernetes API
  • helm for managing your helm charts CI/CD lifecycle

IMPORTANT: This example is for demo and testing. It should not be used a production environment!

Get the example Docker image

You can pull an already built version of this Jenkins image from bintray.com.

# Pull the image
docker pull eldada-docker-examples.bintray.io/jenkins:lts-k8s-20190827

Build the Jenkins Docker image

You can build the image yourself

export DOCKER_REG=SET_YOUR_DOCKER_REGISTRY_HERE

# Build the image
docker build -t ${DOCKER_REG}/jenkins:lts-k8s .

# Push the image
docker push ${DOCKER_REG}/jenkins:lts-k8s

Test your image

You can run your container locally, if you have Docker installed

  • Using the pre-built image
# Run the container you built before
docker run -d --name jenkins -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock eldada-docker-examples.bintray.io/jenkins:lts-k8s-20190827
  • Using your built image
# Run the container you built before
docker run -d --name jenkins -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_REG}/jenkins:lts-k8s

Deploy Jenkins helm chart to Kubernetes

If you are using the pre-built image eldada-docker-examples.bintray.io/jenkins:lts-k8s, you can install the helm chart with

# Init helm and tiller on your cluster
helm init

# Deploy the Jenkins helm chart
# (same command for install and upgrade)
helm upgrade --install jenkins ./helm/jenkins-k8s

NOTE: This helm chart deploys a pod with two containers. One for the Docker daemon and another for Jenkins. This is based on the suggestion in https://applatix.com/case-docker-docker-kubernetes-part-2/

If you are building your own version of Jenkins, you need your Kubernetes cluster to be able to pull the Docker image. You have to create a Docker registry secret and reference to it in your helm install command.

# Create a Docker registry secret
export DOCKER_REG=SET_YOUR_DOCKER_REGISTRY_HERE
export DOCKER_USR=SET_YOUR_DOCKER_USERNAME_HERE
export DOCKER_PWD=SET_YOUR_DOCKER_PASSWORD_HERE
export DOCKER_EML=SET_YOUR_DOCKER_EMAIL_HERE

kubectl create secret docker-registry docker-reg-secret \
        --docker-server=${DOCKER_REG} \
        --docker-username=${DOCKER_USR} \
        --docker-password=${DOCKER_PWD} \
        --docker-email=${DOCKER_EML}


# Deploy the Jenkins helm chart
# (same command for install and upgrade)
helm upgrade --install jenkins \
        --set imagePullSecrets=docker-reg-secret \
        --set image.repository=${DOCKER_REG}/jenkins \
        --set image.tag='lts-k8s' \
        ./helm/jenkins-k8s

Data persistence

By default, in Kubernetes, the Jenkins deployment uses a persistent volume claim that is mounted to /var/jenkins_home. This assures your data is saved across crashes, restarts and upgrades.

Vagrant

You can test your Docker image using Vagrant. The enclosed Vagrantfile will provision an Ubuntu VM with Docker.

  • Spin up the Vagrant VM then build and run the Docker image
# Spin up the Vagrant VM
vagrant up

# SSH into the VM
vagrant ssh

# Go to the mounted sources repository
cd /opt/provisioning

# Build and run your Jenkins container as shown above

jenkins-in-kubernetes's People

Contributors

eldada avatar zd-dalibor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jenkins-in-kubernetes's Issues

Run command in docker container not working

For example if you want to run tests in container.

This is the simple example:

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

you will get this error:

Jenkins seems to be running inside container f99772f7840e664d9095d48ddfdfa139e30fbf5cf9a98b5529c35b2e9ba9657d
but /var/jenkins_home/workspace/<jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2 could not be found among []
but /var/jenkins_home/workspace/jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2@tmp could not be found among []
...
sh: 1: cannot create /var/jenkins_home/workspace/<jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2@tmp/durable-3479ee34/jenkins-log.txt: Directory nonexistent
sh: 1: cannot create /var/jenkins_home/workspace/<jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2@tmp/durable-3479ee34/jenkins-result.txt.tmp: Directory nonexistent
mv: cannot stat '/var/jenkins_home/workspace/<jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2@tmp/durable-3479ee34/jenkins-result.txt.tmp': No such file or directory
process apparently never started in /var/jenkins_home/workspace/<jobname>_develop-W7GCLGJT2S2HKHL5KF3H7X7ZWQL4HBA4WDIAI5OALVZFBKPY76QA@2@tmp/durable-3479ee34

questions

Hello.

I am following your guide, but here's some questions.

If I need update jenkins or jenkins plugin version or add some plugin,
is it possible to have all job's history and log?
Please explain(add to readme file) this case.

and please consider more production env. friendly.
You can assume there's 3 servers, (I guess one is for jenkins master, others for jenkins agent)
how to use/set kubernetes and
how to build at agent server.
This is related https://github.com/eldada/jenkins-pipeline-kubernetes
I see below lines in Jenkinsfile.
// In this example, all is built and run from the master agent { node { label 'master' } }

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.