iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 27
2
Kubernetes

15 分鐘學習系列 - 第一次學 Kubernetes 就上手系列 第 27

Day 27 - 安裝 Jenkins

Jenkins 這老紳士是一個軟體開發的持續整合服務的開源套件, 本篇筆記將介紹如何安裝一個本地端的 pod 運行的 Jenkins.

安裝 Jenkins

  1. 首先使用命令 Git clone https://github.com/eldada/jenkins-in-kuberneteshttps://github.com/eldada/jenkins-in-kubernetes 複製到本地端
  2. 使用命令 docker pull eldada-docker-examples.bintray.io/jenkins:lts-k8s 將預先編譯好的 Jenkins image 拉到本地端
PS C:\k8s\jaeger-kubernetes> docker pull eldada-docker-examples.bintray.io/jenkins:lts-k8s
lts-k8s: Pulling from jenkins
  1. 使用命令 docker images 確認 image 狀況
PS C:\k8s\jaeger-kubernetes> docker images
REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
<略...>
eldada-docker-examples.bintray.io/jenkins   lts-k8s             e6af33a2fa99        8 months ago        1.27GB
<略...>
  1. 編輯 \helm\jenkins-k8s\values.yaml
    其中 repository: eldada-docker-examples.bintray.io/jenkins 設定為剛剛拉下來的 docker image
# values.yaml
initContainerImage: "alpine:3.6"
replicaCount: 1
imagePullSecrets:
image:
repository: eldada-docker-examples.bintray.io/jenkins  # Change to your local image tag
tag: lts-k8s
pullPolicy: Always
did:
image:
repository: docker
tag: 18.02.0-dind
## Set the admin user
adminUser: admin
## Make sure to replace the default password
adminPassword: password
service:
name: jenkins-k8s
type: LoadBalancer
## Whitelist the IPs that can access Jenkins
loadBalancerSourceRanges:
- 0.0.0.0/0
externalPort: 8080
internalPort: 8080
## Make sure the javaOps and resources are aligned to avoid conflicts
javaOpts: "-Xms512m -Xmx2g"
resources:
requests:
cpu: 100m
memory: 512Mi
limits:
cpu: 300m
memory: 2Gi
storage:
persistence:
enabled: true
accessMode: ReadWriteOnce
capacity: 50Gi
  1. 因為會使用到 Persistent Volume, 因此要在 docker for windows 設定中將 Drive c 分享出來.
    https://ithelp.ithome.com.tw/upload/images/20181105/20111871seJqMKsY40.png
  2. 使用命令 helm upgrade --install jenkins ./helm/jenkins-k8s 部署 Jenkins
PS C:\k8s\jenkins-in-kubernetes> helm upgrade --install jenkins ./helm/jenkins-k8s
Release "jenkins" does not exist. Installing it now.
NAME:   jenkins
LAST DEPLOYED: Sun Nov  4 22:59:05 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/Service
NAME                 TYPE          CLUSTER-IP      EXTERNAL-IP  PORT(S)         AGE
jenkins-jenkins-k8s  LoadBalancer  10.103.194.182  localhost    8080:31185/TCP  1s

==> v1beta1/Deployment

NAME                 DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
jenkins-jenkins-k8s  1        1        1           0          1s

==> v1/Pod(related)

NAME                                  AGE
jenkins-jenkins-k8s-5467598855-fm986  1s
jenkins-jenkins-k8s-657cb4c76d-9d2pf  4m55s

==> v1/Secret

NAME                 TYPE    DATA  AGE
jenkins-jenkins-k8s  Opaque  2     1s

==> v1/PersistentVolumeClaim

NAME         STATUS   VOLUME                                    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
jenkins-k8s  Pending  pvc-2cc4ace8-e042-11e8-8dfc-00155d54101d  0         hostpath      1s

NOTES:
Jenkins for Kubernetes deployed!

Get the Jenkins URL
===================
export SERVICE_IP=$(kubectl get svc --namespace default jenkins-jenkins-k8s -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://${SERVICE_IP}:8080/
  1. 開啟瀏覽器連線到 **http://localhost:8080**
    https://ithelp.ithome.com.tw/upload/images/20181105/201118712nOOs2Qsnt.png
    看見 Jenkins 的登入畫面, 我們已經完成了 Jenkins 的部署了 (點選登入連結, 預設使用者帳號密碼為 admin/password)

參考資料:


上一篇
Day 26 - 安裝使用分散式跟蹤系統 - Jaeger
下一篇
Day 28 - 整合 AKS 使用 Jenkins 建立 CI/CD pipeline
系列文
15 分鐘學習系列 - 第一次學 Kubernetes 就上手30

尚未有邦友留言

立即登入留言