Jenkins + Github Web Hook

Jenkins + Github Web Hook

  1. Jenkins
    1. k8s jenkins
    2. ngrok

Jenkins

k8s jenkins

  1. Find a jenkins pod w/ k8s pod, jenkins namespace
kubectl get pod -n jenkins

NAME                       READY   STATUS    RESTARTS      AGE
jenkins-6846f7864d-s92t8   1/1     Running   1 (22m ago)   41m
  1. Login to jenkins pod
kubectl -n jenkins exec -it jenkins-6846f7864d-s92t8 -- /bin/bash
  1. create a ssh key-pair (privae, public)
jenkins@jenkins-6846f7864d-s92t8:/$
jenkins@jenkins-6846f7864d-s92t8:/$ cd /var/jenkins_home
jenkins@jenkins-6846f7864d-s92t8:/$ mkdir .ssh
jenkins@jenkins-6846f7864d-s92t8:/$ cd .ssh
jenkins@jenkins-6846f7864d-s92t8:/$ ssh-keygen -t rsa -b 4096 -C test-key -f github_jenkins
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in github_jenkins
Your public key has been saved in github_jenkins.pub
The key fingerprint is:
SHA256:NJmTn59EOKF/7oLbcUqh1PCJUZ2f82tGL4t7bT8JEKg test-key
The key's randomart image is:
+---[RSA 4096]----+
|          +. .   |
|         B +o    |
|        % o o. . |
|       E @ *  +  |
|        S O +  o |
|       . . * o ..|
|        ..o = o.+|
|        .o.= .o*+|
|        ..o.+o+++|
+----[SHA256]-----+

jenkins@jenkins-6846f7864d-s92t8:~/.ssh$ ls
github_jenkins  github_jenkins.pub
  1. Register SSH key (public key) to Github Repositories

    • Goto github repositories (https://github.com/pushdown99/jenkins-test)
    • Settings > General/Security/Deploy keys => [Add deploy key]
    • Deploy keys/Add new => Title: github_jenkins, Key: (cat ithub_jenkins.pub) => [Add key]
  2. Register SSH key (private key) to Jenkins Credentials

    • Goto Jenkins dashboard (ex: http://127.0.0.1:4377)
    • Dashboard > + New Item => New Item / Name: github_jenkins Type: Freestyle project
    • Dashboard > Name: github_jenkins => Source code management => Git/Repository URL: git@github.com:pushdown99/jenkins-test.git, Credentials/ Add: Jenkins => Kind: SSH Username with private key, Username: github_jenkins, Private key/Enterdirectly: (cat ithub_jenkins) => [Add]
  3. Build Trigger

    • Build Trigger / [v] Github hook trigger for GITScm polling
  4. Plugin Installation

    • Jenkins Management > Plugins > Available plugins > GitHub Integration Plugin : Install
  5. Ngrok Installation (optional: localhost)

choco install ngrok
ngrok config add-authtoken 46WbJVNrQ1pdq1mkbHAxT_ (API secret)
ngrok http 4377

Forwarding  https://4895-220-76-193-80.ngrok-free.app -> http://localhost:4377            
  1. Setting for Github Repository Webhook

    • Goto github repositories (https://github.com/pushdown99/jenkins-test)
    • Settings > General/Code and automation/Webhooks => Payload URL: https://4895-220-76-193-80.ngrok-free.app/github-webhook/, Conntent type: application/json, [v] Just the push event, [v] Active => []Update webhook]

ngrok

k8s Quick-Start with Minikube

k8s Quick-Start with Minikube

  1. minikube
    1. Installation / Dashboard
  2. ArgoCD
    1. Installation / Dashboard
    2. Get password (User: admin)
  3. Harbor
    1. add repo
    2. fetch & unzip chart
    3. Installation
  4. MinIO deploying with ArgoCD
    1. git repositories
    2. MinIO Application creation with ArgoCD
    3. git repositories
    4. HOW-TO
  5. CI/CD with ArgoCD
    1. Sample Application with ArgoCD
  6. Jenkins
    1. Jenkins Installation with ArgoCD
  7. Nexus
    1. Nexus Installation with ArgoCD
  8. Top

minikube

Installation / Dashboard

minikube start
minikube dashboard

ArgoCD

Installation / Dashboard

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
minikube tunnel
minikube service argocd-server -n argocd

Get password (User: admin)

argocd admin initial-password -n argocd

Harbor

add repo

helm repo add harbor https://helm.goharbor.io
helm repo list

fetch & unzip chart

helm fetch harbor/harbor
tar zxvf harbor-x.x.x.tgz

Download: values.yaml

expose type to loadBalancer and tls disable

expose:
  type: loadBalancer
  ports:
    httpPort: 80
  tls:
    enabled: false # true

Installation

kubectl create ns hb
helm install harbor -f values.yaml . -n hb
minikube tunnel

browse to http://localhost
id: admin, password: Harbor12345


MinIO deploying with ArgoCD

git repositories

https://github.com/pushdown99/argo-minio.git

app/k8s-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
spec:
  replicas: 1
  selector:
    matchLabels:
      app: minio
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: minio
    spec:
      volumes:
      - name: storage
        hostPath:
          path: /data/minio
      containers:
      - name: minio
        image: minio/minio:latest
        args:
        - server
        - --console-address
        - ":9001"
        - "/storage"
        env:
        - name: MINIO_ROOT_USER
          value: "minio"
        - name: MINIO_ROOT_PASSWORD
          value: "minio123"
        - name: TZ
          value: Asia/Seoul
        - name: LANG
          value: ko_KR.utf8
        ports:
        - containerPort: 9000
          hostPort: 9000
        - containerPort: 9001
          hostPort: 9001
        volumeMounts:
        - name: storage
          mountPath: "/storage"
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  labels:
    run: minio
spec:
  type: NodePort
  ports:
  - port: 9000
    targetPort: 9000
    nodePort: 30333
    name: api
  - port: 9001
    targetPort: 9001
    nodePort: 30334
    name: ui
  selector:
    app: minio

MinIO Application creation with ArgoCD

git repositories

https://github.com/pushdown99/argo-minio.git

app/k8s-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myweb
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - name: myweb
        image: pushdown99/myweb:latest
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: myweb-service
spec:
  type: NodePort
  selector:
    app: myweb
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
    nodePort: 30000

HOW-TO

  1. Login to ArgoCD
  2. Applications > + New APP
  3. Fill-in

    • (GENERAL) Application Name: minio
    • (GENERAL) Project Name: default
    • (SOURCE) Repository URL: https://github.com/pushdown99/argo-minio.git
    • (SOURCE) Path: app
    • (DESTINATION) Cluster URL: https://kubernetes.default.svc
    • (DESTINATION) Namespace: default
  4. Create
  5. SYNC
  6. kubectl commands
kubectl get svc

NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                         AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP                         35m
minio        NodePort    10.98.171.143   <none>        9000:30333/TCP,9001:30334/TCP   64s

kubectl port-forward svc/minio 9000:9000 9001:9001
  1. browse to http://127.0.0.1:9000

    id: minio, password: minio123

CI/CD with ArgoCD

Sample Application with ArgoCD

https://github.com/pushdown99/cicd-node.git

app/k8s-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myweb
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - name: myweb
        image: pushdown99/myweb:latest
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: myweb-service
spec:
  type: NodePort
  selector:
    app: myweb
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
    nodePort: 30000

HOW-TO

  1. Login to ArgoCD
  2. Applications > + New APP
  3. Fill-in

    • (GENERAL) Application Name: myweb
    • (GENERAL) Project Name: default
    • (SOURCE) Repository URL: https://github.com/pushdown99/cicd-node.git
    • (SOURCE) Path: app
    • (DESTINATION) Cluster URL: https://kubernetes.default.svc
    • (DESTINATION) Namespace: default
  4. Create
  5. SYNC
  6. kubectl commands
kubectl get svc

NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                         AGE
kubernetes      ClusterIP   10.96.0.1        <none>        443/TCP                         54m
minio           NodePort    10.98.171.143    <none>        9000:30333/TCP,9001:30334/TCP   20m
myweb-service   NodePort    10.104.220.233   <none>        3000:30000/TCP                  14m

kubectl port-forward svc/myweb-service 3000:3000
  1. browse to http://127.0.0.1:3000

Jenkins

Jenkins Installation with ArgoCD

https://github.com/pushdown99/argo-jenkins.git

HOW-TO

  1. Login to ArgoCD
  2. Applications > + New APP
  3. Fill-in

    • (GENERAL) Application Name: jenkins
    • (GENERAL) Project Name: default
    • (SOURCE) Repository URL: https://github.com/pushdown99/argo-jenkins.git
    • (SOURCE) Path: app
    • (DESTINATION) Cluster URL: https://kubernetes.default.svc
    • (DESTINATION) Namespace: default
  4. Create
  5. SYNC
  6. kubectl commands
minikube service jenkins-service -n jenkins

|-----------|-----------------|-------------|---------------------------|
| NAMESPACE |      NAME       | TARGET PORT |            URL            |
|-----------|-----------------|-------------|---------------------------|
| jenkins   | jenkins-service |        8080 | http://192.168.49.2:32000 |
|-----------|-----------------|-------------|---------------------------|
πŸƒ  jenkins-service μ„œλΉ„μŠ€μ˜ 터널을 μ‹œμž‘ν•˜λŠ” 쀑
|-----------|-----------------|-------------|------------------------|
| NAMESPACE |      NAME       | TARGET PORT |          URL           |
|-----------|-----------------|-------------|------------------------|
| jenkins   | jenkins-service |             | http://127.0.0.1:44853 |
|-----------|-----------------|-------------|------------------------|
πŸŽ‰  Opening service jenkins/jenkins-service in default browser...
❗  windows μ—μ„œ Docker λ“œλΌμ΄λ²„λ₯Ό μ‚¬μš©ν•˜κ³  있기 λ•Œλ¬Έμ—, 터미널을 μ—΄μ–΄μ•Ό μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€

Find password for access page http://127.0.0.1:44853

kubectl get pod -n jenkins

NAME                       READY   STATUS    RESTARTS   AGE
jenkins-6846f7864d-957b8   1/1     Running   0          2m8s

kubectl -n jenkins exec -it jenkins-6846f7864d-957b8 -- /bin/bash

jenkins@jenkins-6846f7864d-957b8:/$ cat /var/jenkins_home/secrets/initialAdminPassword
  1. browse to http://127.0.0.1:44853

Nexus

Nexus Installation with ArgoCD

https://github.com/pushdown99/argo-nexus.git

HOW-TO

  1. Login to ArgoCD
  2. Applications > + New APP
  3. Fill-in

    • (GENERAL) Application Name: nexus
    • (GENERAL) Project Name: default
    • (SOURCE) Repository URL: https://github.com/pushdown99/argo-nexus.git
    • (SOURCE) Path: app
    • (DESTINATION) Cluster URL: https://kubernetes.default.svc
    • (DESTINATION) Namespace: default
  4. Create
  5. SYNC
  6. kubectl commands
minikube service nexus-service -n nexus

|-----------|---------------|-------------|---------------------------|
| NAMESPACE |     NAME      | TARGET PORT |            URL            |
|-----------|---------------|-------------|---------------------------|
| nexus     | nexus-service |        8081 | http://192.168.49.2:30100 |
|-----------|---------------|-------------|---------------------------|
πŸƒ  nexus-service μ„œλΉ„μŠ€μ˜ 터널을 μ‹œμž‘ν•˜λŠ” 쀑
|-----------|---------------|-------------|------------------------|
| NAMESPACE |     NAME      | TARGET PORT |          URL           |
|-----------|---------------|-------------|------------------------|
| nexus     | nexus-service |             | http://127.0.0.1:60009 |
|-----------|---------------|-------------|------------------------|
πŸŽ‰  Opening service nexus/nexus-service in default browser...
❗  windows μ—μ„œ Docker λ“œλΌμ΄λ²„λ₯Ό μ‚¬μš©ν•˜κ³  있기 λ•Œλ¬Έμ—, 터미널을 μ—΄μ–΄μ•Ό μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€

Find password for access page http://127.0.0.1:60009

kubectl get pod -n nexus

NAME                     READY   STATUS    RESTARTS   AGE
nexus-65b596bb55-rv47v   1/1     Running   0          5m34s

kubectl -n nexus exec -it nexus-65b596bb55-rv47v -- /bin/bash

bash-5.1$ cat /nexus-data/admin.password
  1. browse to http://127.0.0.1:60009

Top

kubectl top node

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

CI/CD with Minikube

CI/CD with Minikube

  1. CI/CD with Minikube
    1. ArgoCD Installation

CI/CD with Minikube


ArgoCD Installation

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl get svc -n argocd
kubectl port-forward svc/argocd-server -n argocd 8080:443

Login

User: admin
Password:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d

PWzPW5Oa8me81UBr
> netstat -ano | findstr 8080

  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       7588
  TCP    [::]:8080              [::]:0                 LISTENING       7588
  TCP    [::1]:8080             [::1]:64187            ESTABLISHED     7588
  TCP    [::1]:8080             [::1]:64188            ESTABLISHED     7588
  TCP    [::1]:64187            [::1]:8080             ESTABLISHED     15888
  TCP    [::1]:64188            [::1]:8080             ESTABLISHED     15888

> tasklist /FI "PID eq 7588"

이미지 이름                    PID μ„Έμ…˜ 이름              μ„Έμ…˜#  λ©”λͺ¨λ¦¬ μ‚¬μš©
========================= ======== ================ =========== ============
java.exe                      7588 Services                   0    385,468 K

Pagination


Β© 2018. All rights reserved.

Powered by Hydejack v8.4.0