GithubHelp home page GithubHelp logo

arun-reddy-16 / jenkins-in-kubernetes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eldada/jenkins-in-kubernetes

0.0 0.0 0.0 14 KB

A Jenkins Docker image and helm chart for running in Kubernetes

Dockerfile 43.49% Smarty 21.00% Groovy 35.51%

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

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
  • 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

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.