Giter VIP home page Giter VIP logo

jenkins-k8s-demo's Introduction

jenkins-k8s-demo

A. Install Jenkins in K8s cluster

  1. Create a kubernetes cluster

  2. In K8s cluster, we need to create and apply 4 yaml files a. for persistent volume to store Jenkins data b. for creating deployment of Jenkins c. for creating service to expose Jenkins to external world d. for creating cluster role so that your service account binds to cluster role - Here, a "ClusterRole" named "service reader" is created, and specific permissions (such as ["get", "watch", "list"] are assigned to specific resources.

  3. Run the following command to create Jenkins deployment on K8s - kubectl apply -f jenkins-k8s-volume.yaml kubectl apply -f jenkins-k8s-deployment.yaml kubectl apply -f jenkins-k8s-service.yaml kubectl apply -f jenkins-k8s-clusterbinding.yaml

  4. Run the following command to create a cluster role binding named "service reader pod".
    Its "clusterrole" is "service reader", and its name is "default:default". The first "default" is the namespace, the second "default" is the name of the service account, which will be referred to in the subsequent deployment configuration file. Here, because I didn't create a separate namespace for Jenkins, it uses the default namespace "default".

    kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=default:default

  5. Login to Jenkins Once you done with yaml execution, the external ip of one of the k8s node and node port 30000 need to put on browser such as http://:30000 and Jenkins login page will open and asking for initial password which can be retrieved from kubctl logs At the bottom you will find password with pattern like - adsubjsbvcdbhcvfnhhfjkjfk

B. Configure CLoud (Kubernetes) in Jenkins

  1. Now you are in Jenkins Dashboard, Go to manage Jenkins - Manage Nodes - Configure CLoud

  2. It will ask to install plugin for cloud template - go to manage plugin and install Kubernetes plugin.

  3. Once install go to configure cloud and configure k8s and its pod template. (Watch my Youtube video for configuration steps - https://www.youtube.com/watch?v=laAAzdw11dA)

C. Configure service account to authenticate Gcloud using Jenkins

  1. Create service account in gcloud with proper role permissions - (IAM -> Service account)

  2. create key in .json format and download it. gcloud iam service-accounts keys create --iam-account [email protected] key.json

  3. In Kubernetes, Import credentials as a Secret. Now that you have the service account key, you need a way to load it into your container. kubectl create secret generic registry-jenkins --from-file=key.json=PATH-TO-KEY-FILE.json

D. To run Jenkins job using Kubernetes pod agent - Please check JenkinsFile and also you can watch video on how to run job using Kubernetes slave agent - https://www.youtube.com/watch?v=laAAzdw11dA

jenkins-k8s-demo's People

Contributors

cooldsachin avatar

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.