One place for hosting & domains

      Jenkins

      How To Install Jenkins on Kubernetes


      The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      Continuous Integration/Continuous Deployment (CI/CD) pipelines are one of the core components of the DevOps environment. They help streamline the workflow between multiple teams and increase productivity. Jenkins is a widely-used open source automation server that can set up CI/CD pipelines.

      In this tutorial, you will install Jenkins on Kubernetes. You will then access the Jenkins UI and run a sample pipeline.

      Prerequisites

      To follow this tutorial, you will need:

      Step 1 — Installing Jenkins on Kubernetes

      Kubernetes has a declarative API and you can convey the desired state using either a YAML or JSON file. For this tutorial, you will use a YAML file to deploy Jenkins. Make sure you have the kubectl command configured for the cluster.

      First, use kubectl to create the Jenkins namespace:

      • kubectl create namespace jenkins

      Next, create the YAML file that will deploy Jenkins.

      Create and open a new file called jenkins.yaml using nano or your preferred editor:

      Now add the following code to define the Jenkins image, its port, and several more configurations:

      jenkins.yaml

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: jenkins
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: jenkins
        template:
          metadata:
            labels:
              app: jenkins
          spec:
            containers:
            - name: jenkins
              image: jenkins/jenkins:lts
              ports:
                - name: http-port
                  containerPort: 8080
                - name: jnlp-port
                  containerPort: 50000
              volumeMounts:
                - name: jenkins-vol
                  mountPath: /var/jenkins_vol
            volumes:
              - name: jenkins-vol
                emptyDir: {}
      

      This YAML file creates a deployment using the Jenkins LTS image and also opens port 8080 and 50000. You use these ports to access Jenkins and accept connections from Jenkins workers respectively.

      Now create this deployment in the jenkins namespace:

      • kubectl create -f jenkins.yaml --namespace jenkins

      Give the cluster a few minutes to pull the Jenkins image and get the Jenkins pod running.

      Use kubectl to verify the pod’s state:

      • kubectl get pods -n jenkins

      You will receive an output like this:

      NAME                       READY   STATUS    RESTARTS   AGE
      jenkins-6fb994cfc5-twnvn   1/1     Running   0          95s
      

      Note that the pod name will be different in your environment.

      Once the pod is running, you need to expose it using a Service. You will use the NodePort Service type for this tutorial. Also, you will create a ClusterIP type service for workers to connect to Jenkins.

      Create and open a new file called jenkins-service.yaml:

      • nano jenkins-service.yaml

      Add the following code to define the NodePort Service:

      jenkins-service.yaml

      apiVersion: v1
      kind: Service
      metadata:
        name: jenkins
      spec:
        type: NodePort
        ports:
          - port: 8080
            targetPort: 8080
            nodePort: 30000
        selector:
          app: jenkins
      
      ---
      
      apiVersion: v1
      kind: Service
      metadata:
        name: jenkins-jnlp
      spec:
        type: ClusterIP
        ports:
          - port: 50000
            targetPort: 50000
        selector:
          app: jenkins
      

      In the above YAML file, you define your NodePort Service and then expose port 8080 of the Jenkins pod to port 30000.

      Now create the Service in the same namespace:

      • kubectl create -f jenkins-service.yaml --namespace jenkins

      Check that the Service is running:

      • kubectl get services --namespace jenkins

      You will receive an output like this:

      Output

      NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE jenkins NodePort your_cluster_ip <none> 8080:30000/TCP 15d

      With NodePort and Jenkins operational, you are ready to access the Jenkins UI and begin exploring it.

      Step 2 — Accessing the Jenkins UI

      In this step, you will access and explore the Jenkins UI. Your NodePort service is accessible on port 30000 across the cluster nodes. You need to retrieve a node IP to access the Jenkins UI.

      Use kubectl to retrieve your node IPs:

      • kubectl get nodes -o wide

      kubectl will produce an output with your external IPs:

      Output

      NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME your_node Ready <none> 16d v1.18.8 your_internal_ip your_external_ip Debian GNU/Linux 10 (buster) 4.19.0-10-cloud-amd64 docker://18.9.9 your_node Ready <none> 16d v1.18.8 your_internal_ip your_external_ip Debian GNU/Linux 10 (buster) 4.19.0-10-cloud-amd64 docker://18.9.9 your_node Ready <none> 16d v1.18.8 your_internal_ip your_external_ip Debian GNU/Linux 10 (buster) 4.19.0-10-cloud-amd64 docker://18.9.9

      Copy one of the your_external_ip values.

      Now open a web browser and navigate to http://your_external_ip:30000.

      A page will appear asking for an administrator password and instructions on retrieving this password from the Jenkins Pod logs.

      Let’s use kubectl to pull the password from those logs.

      First, return to your terminal and retrieve your Pod name:

      • kubectl get pods -n jenkins

      You will receive an output like this:

      NAME                       READY   STATUS    RESTARTS   AGE
      jenkins-6fb994cfc5-twnvn   1/1     Running   0          9m54s
      

      Next, check the Pod’s logs for the admin password. Replace the highlighted section with your pod name:

      • kubectl logs jenkins-6fb994cfc5-twnvn -n jenkins

      You might need to scroll up or down to find the password:

      Running from: /usr/share/jenkins/jenkins.war
      webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
      . . .
      
      Jenkins initial setup is required. An admin user has been created and a password generated.
      Please use the following password to proceed to installation:
      
      your_jenkins_password
      
      This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
      . . .
      

      Copy your_jenkins_password. Now return to your browser and paste it into the Jenkins UI.

      Once you enter the password, Jenkins will prompt you to install plugins. Because you are not doing anything unusual, select Install suggested plugins.

      After installation, Jenkins will load a new page and ask you to create an admin user. Fill out the fields, or skip this step by pressing the skip and continue as admin link. This will leave your username as admin and your password as your_jenkins_password.

      Another screen will appear asking about instance configuration. Click the Not now link and continue.

      After this, Jenkins will create a summary of your choices and print Jenkins is ready! Click on start using Jenkins and the Jenkins home page will appear.

      jenkins wizard

      Now that you have installed and configured Jenkins on your cluster let’s demonstrate its capabilities and run a sample pipeline.

      Step 3 — Running a Sample Pipeline

      Jenkins excels at creating pipelines and managing CI/CD workflows. In this step we will build one of Jenkins’ sample pipelines.

      From the Jenkins home page, click on the New item link on the left-hand menu.

      A new page will appear. Choose Pipeline and press OK.

      jenkins wizard

      Jenkins will redirect you to the pipeline’s configuration. Find the Pipeline section and select Hello World from the try sample pipeline dropdown menu. This menu appears on the right-hand side. After selecting Hello World, click the Save button.

      jenkins wizard

      Jenkins will redirect you to the pipeline home page. Click on build now from the left-hand menu and watch the pipeline begin to run. The #1 signifies that this is the first build. Once the task completes, you will see some stats about the build.

      jenkins wizard

      You can also check the console output to see what happened while the pipeline was running. Hover over #1 and a dropdown menu will appear. Choose console output to view the build’s details.

      Your Hello World pipeline is not very sophisticated, but it does demonstrate just how well Jenkins can create and manage CI/CD workflows.

      Conclusion

      In this tutorial, you installed and configured Jenkins on a Kubernetes cluster and then you ran a sample pipeline. Jenkins has a large repository of plugins that can help you perform very complex operations. You can also add your GitHub repositories, multiple types of worker instances, and more. To learn more about using Jenkins, explore the official Jenkins documentation.



      Source link

      Create Your First CI/CD Pipeline on Kubernetes With Jenkins


      How to Join

      This Tech Talk is free and open to everyone. Register below to get a link to join the live event.

      FormatDateRSVP
      Presentation and Q&ASeptember 8, 2020, 11:00–12:00 p.m. ET

      If you can’t join us live, the video recording will be published here as soon as it’s available.

      About the Talk

      Setting up a Kubernetes cluster is easy, but what do you do after that? Setting up a CI/CD pipeline is one of the core concepts of DevOps. This talk will help you set up that first pipeline via Jenkins on top of a Kubernetes cluster.

      What You’ll Learn

      • Why CI/CD pipelines are important
      • How to use Jenkins Pipeline with Kubernetes

      This Talk is Designed For

      Developers and system administrators that are new to Kubernetes.

      Prerequisites

      Basic knowledge of Jenkins and Kubernetes.

      About the Presenter

      Peeyush Gupta is currently a Senior Developer Advocate at DigitalOcean. He loves developing cloud platforms, helping developers migrate legacy applications to the cloud, and serving communities through speaking at meetups and contributing to the Kubernetes Contributor Experience Group.

      To join the live Tech Talk, register here for the session of your choice.



      Source link

      Installieren von Jenkins unter Ubuntu 20.04


      Einführung

      Wenn es um die Bewältigung sich wiederholender technischer Aufgaben geht, ist es nicht immer einfach, gute Automatisierungslösungen zu finden. Mit Jenkins, einem Open-Source-basierten Automatisierungsserver, können Sie Aufgaben von der Erstellung bis zur Bereitstellung von Software effizient verwalten. Jenkins ist Java-basiert und wird aus Ubuntu-Paketen bzw. durch Herunterladen und Ausführen der entsprechenden WAR-Datei (Web Application Archive) installiert: Dabei handelt es sich um eine Sammlung von Dateien, die eine vollständige Webanwendung ergeben, die sich auf einem Server ausführen lässt.

      In diesem Tutorial installieren wir Jenkins unter Ubuntu 20.04, starten den Entwicklungsserver und erstellen einen Administratorbenutzer, sodass Sie damit beginnen können, die Möglichkeiten von Jenkins zu erkunden. Zwar verfügen Sie nach Abschluss dieses Tutorials über einen einsatzbereiten Entwicklungsserver, doch sollten Sie ihn für die Produktion noch sichern. Folgen Sie dazu dem Tutorial Konfigurieren von Jenkins mit SSL unter Verwendung eines Nginx-Reverseproxy unter Ubuntu 18.04.

      Voraussetzungen

      Um dieser Anleitung zu folgen, benötigen Sie:

      Schritt 1 — Installieren von Jenkins

      Die Version von Jenkins, die in den standardmäßigen Ubuntu-Paketen enthalten ist, ist oft älter als die neueste verfügbare Version des Projekts selbst. Um sicherzustellen, dass Sie über die neuesten Korrekturen und Funktionen verfügen, verwenden Sie die vom Projekt gepflegten Pakete zur Installation von Jenkins.

      Fügen Sie zunächst den Repository-Schlüssel zum System hinzu:

      • wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

      Nach dem Hinzufügen des Schlüssels gibt das System OK zurück.

      Als Nächstes fügen wir die Adresse für das Debian-Paket-Repository in die sources.list des Servers ein:

      • sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

      Nach Eingabe beider Befehle werden wir update ausführen, damit apt das neue Repository nutzt.

      Schließlich installieren wir Jenkins und seine Abhängigkeiten.

      Nachdem Jenkins und seine Abhängigkeiten vorhanden sind, starten wir nun den Jenkins-Server.

      Schritt 2 — Starten von Jenkins

      Starten wir Jenkins durch Verwendung von systemctl:

      sudo systemctl start jenkins
      

      Da systemctl keine Statusausgabe anzeigt, nutzen wir den status-Befehl zum Überprüfen, ob Jenkins erfolgreich gestartet wurde:

      • sudo systemctl status jenkins

      Wenn alles geklappt hat, zeigt der Anfang der Statusausgabe an, dass der Dienst aktiv und so konfiguriert ist, dass er beim Booten gestartet wird:

      Output

      ● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated) Active: active (exited) since Fri 2020-06-05 21:21:46 UTC; 45s ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 1137) CGroup: /system.slice/jenkins.service

      Nachdem Jenkins ausgeführt wird, sollten wir nun unsere Firewall-Regeln so anpassen, dass wir den Server über einen Webbrowser erreichen können. Damit ist die Ersteinrichtung abgeschlossen.

      Schritt 3 — Öffnen der Firewall

      Um eine UFW-Firewall einzurichten, konsultieren Sie Ersteinrichtung des Servers mit Ubuntu 20.04, Schritt 4 — Einrichten einer einfachen Firewall. Standardmäßig wird Jenkins an Port 8080 ausgeführt. Wir öffnen diesen Port mit ufw:

      Anmerkung: Wenn die Firewall inaktiv ist, können Sie mit folgenden Befehlen OpenSSH zulassen und die Firewall aktivieren:

      • sudo ufw allow OpenSSH
      • sudo ufw enable

      Überprüfen Sie zum Bestätigen der neuen Regeln den Status von ufw:

      Sie werden feststellen, dass Datenverkehr an Port 8080 von überall zugelassen ist:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 8080 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 8080 (v6) ALLOW Anywhere (v6)

      Nach der Installation von Jenkins und der Konfiguration unserer Firewall können wir die Installationsphase abschließen und mit der Einrichtung von Jenkins beginnen.

      Schritt 4 — Einrichten von Jenkins

      Um Ihre Installation einzurichten, rufen Sie Jenkins an seinem Standardport 8080 auf, indem Sie den Domänennamen oder die IP-Adresse Ihres Servers verwenden: http://your_server_ip_or_domain:8080

      Sie sollten den Bildschirm Unlock Jenkins (Jenkins entsperren) erhalten, in dem der Speicherort des ersten Passworts angezeigt wird:

      Bildschirm „Unlock Jenkins“ (Jenkins entsperren)

      Verwenden Sie im Terminalfenster den Befehl cat zum Anzeigen des Passworts:

      • sudo cat /var/lib/jenkins/secrets/initialAdminPassword

      Kopieren Sie das 32 Zeichen lange alphanumerische Passwort aus dem Terminal und fügen Sie es in das Feld Administrator password (Administratorkennwort) ein. Klicken Sie dann auf Continue (Weiter).

      Im nächsten Bildschirm wird die Option zum Installieren empfohlener Plugins oder Auszuwählen spezifischer Plugins angezeigt:

      Bildschirm „Customize Jenkins“ (Jenkins anpassen)

      Wir klicken auf die Option Install suggested plugins (Empfohlene Plugins installieren), woraufhin der Installationsprozess unmittelbar beginnt.

      Bildschirm „Jenkins Getting Started Install Plugins“ (Erste Schritte mit Jenkins — Plugins installieren)

      Nach Abschluss der Installation werden Sie aufgefordert, den ersten Administratorbenutzer einzurichten. Es ist möglich, diesen Schritt überspringen und als admin mit dem oben verwendeten ursprünglichen Passwort fortzufahren, aber wir werden uns einen Moment Zeit nehmen, um den Benutzer zu erstellen.

      Anmerkung: Der standardmäßige Jenkins-Server ist NICHT verschlüsselt, sodass die mit diesem Formular übermittelten Daten nicht geschützt sind. Siehe Konfigurieren von Jenkins mit SSL unter Verwendung eines Nginx-Reverseproxy unter Ubuntu 20.04, um Anmeldedaten von Benutzern und Informationen über Builds, die über die Weboberfläche übertragen werden, zu schützen.

      Bildschirm „Jenkins Create First Admin User“ (Erstellen des ersten Administratorbenutzers in Jenkins)

      Geben Sie den Namen und das Passwort für Ihren Benutzer ein:

      Jenkins Create User (Jenkins: Benutzer erstellen)

      Sie sehen eine Seite zur Instance Configuration (Instanzkonfiguration), auf der Sie dazu aufgefordert werden, die bevorzugte URL für Ihre Jenkins-Instanz zu bestätigen. Bestätigen Sie entweder den Domänennamen für Ihren Server bzw. die IP-Adresse Ihres Servers:

      Jenkins Instance Configuration (Jenkins: Instanzkonfiguration)

      Nach der Bestätigung der entsprechenden Daten klicken Sie auf Save and Finish (Speichern und Fertigstellen). Sie erhalten eine Seite mit der Bestätigung, dass „Jenkins is Ready!“ (Jenkins bereit ist):

      Bildschirm „Jenkins is ready“ (Jenkins ist bereit)

      Klicken Sie auf Start using Jenkins (Mit Verwendung von Jenkins beginnen), um das Haupt-Dashboard von Jenkins aufzurufen:

      Bildschirm „Welcome to Jenkins“ (Willkommen bei Jenkins)

      Jetzt haben Sie die Installation von Jenkins erfolgreich abgeschlossen.

      Zusammenfassung

      In diesem Tutorial haben Sie Jenkins mit den vom Projekt bereitgestellten Paketen installiert, den Server gestartet, die Firewall geöffnet und einen Administratorbenutzer erstellt. Nun können Sie mit der Erkundung von Jenkins beginnen.

      Folgen Sie danach Abschluss dem Leitfaden Konfigurieren von Jenkins mit SSL unter Verwendung eines Nginx-Reverseproxy unter Ubuntu 20.04, um Ihre Passwörter sowie sensible System- oder Produktdaten, die zwischen dem Computer und dem Server in Klartext übertragen werden, zu schützen. Anschließend können Sie Jenkins weiter nutzen.

      Um mehr über die Funktionen von Jenkins zu erfahren, lesen Sie weitere Tutorials zu dem Thema:



      Source link