/* 쿠버네티스에 젠킨스 설치시 영구 저장을 위해서 스토리지를 생성한다. */
참고 : https://kubernetes.io/ko/docs/concepts/storage/storage-classes/#nfs
1. StorageClass 생성
vi storageClass-local-storage.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
1) 스토리지 클래스 생성
root@master:~/jenkins# kubectl apply -f ./storageClass-local-storage.yaml
storageclass.storage.k8s.io/local-storage created
2) Persistent Volume 생성
root@node1:~# mkdir -p /kubernetes/data/pv/jenkins
root@node1:~# chmod 777 /kubernetes/data/pv/jenkins
3) pv 생성
vi pv-jenkins.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-jenkins
spec:
capacity:
storage: 30Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /kubernetes/data/pv/jenkins
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1
30GB 의 용량으로 설정하고 하나의 pod 만 접근하기 때문에 ReadWriteOnce, pod 가 삭제되더라도 데이터 보존을 위해 Retain 전략으로 설정합니다. NodeAffinity 설정을 통해 node1 에 pv 를 생성하도록 합니다. 즉, Jenkins pv 는 node1 노드에 만들어지고 Jenkins pod 역시 node1노드에 생성되게 됩니다.
4) jenkins 네임스페이스 생성
$ kubectl create namespace jenkins
$ kubectl apply -f ./pv-jenkins.yaml -n jenkins
persistentvolume/pv-jenkins created
5) Persistnet Volume Claim 생성
$ vi pvc-jenkins.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-jenkins
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 30Gi
위에서 생성한 local-storage 타입으로 30기가 용량의 pvc를 생성합니다.
root@master:~/jenkins# kubectl apply -f ./pvc-jenkins.yaml -n jenkins
persistentvolumeclaim/pvc-jenkins created
6) pv 상태 조회
$ kubectl get pv
root@master:~/jenkins# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE
pv-jenkins 30Gi RWO Retain Available local-storage <unset> 5m24s
/* VolumeBindingMode 를 WaitForFirstConsumer로 설정했기 때문에 Status 가 아직 Available 인 점을 확인할 수 있습니다. */
7) pvc 상태 조회
$ kubectl get pvc pvc-jenkins -n jenkins
root@master:~/jenkins# kubectl get pvc pvc-jenkins -n jenkins
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
pvc-jenkins Pending local-storage <unset> 3m33s
/* 상태가 pending 입니다. */
2. Jenkins 설치
1) Deployment 생성
$ vi deployment-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
imagePullPolicy: "IfNotPresent"
securityContext:
#root 권한
runAsUser: 0
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 50000
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
- name: docker-socket
mountPath: /var/run/docker.sock
- name: docker-binary
mountPath: /usr/bin/docker
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: pvc-jenkins
- name: docker-socket
hostPath:
path: /var/run/docker.sock
- name: docker-binary
hostPath:
path: /usr/bin/docker
$ kubectl apply -f ./deployment-jenkins.yaml -n jenkins
2) pod 상태 확인
root@master:~/jenkins# kubectl get pods -n jenkins -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
jenkins-8d76965bc-wbw28 1/1 Running 0 107s 10.1.166.142 node1 <none> <none>
3) node1에만 생성되는지 삭제 테스트
kubectl delete pods jenkins-8d76965bc-wbw28 -n jenkins
4) 젠킨스를 외부에 노출하기 위한 서비스 NodePort 생성
vi service-jenkins.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: NodePort
ports:
- port: 50000
targetPort: 50000
nodePort: 30001
selector:
app: jenkins
5) 서비스 생성
kubectl apply -f ./service-jenkins.yaml -n jenkins
6) 서비스 기동 확인
root@master:~/jenkins# kubectl get services -n jenkins
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins NodePort 10.106.63.3 <none> 8080:30000/TCP 19s
jenkins-jnlp NodePort 10.105.220.170 <none> 50000:30001/TCP 18s
7) 포드 네임 확인후 로그에서 관리자 패스워드 확인
root@master:~/jenkins# kubectl get pods -n jenkins
NAME READY STATUS RESTARTS AGE
jenkins-97fb8547b-tvnnh 1/1 Running 0 5m51s
/* 로그에서 관리자 패스워드 확인 */
root@master:~/jenkins# kubectl logs jenkins-97fb8547b-tvnnh -n jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: /var/jenkins_home/war
2024-01-08 23:47:41.719+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2024-01-08 23:47:43.414+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2024-01-08 23:47:43.476+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-10.0.18; built: 2023-10-27T01:59:58.245Z; git: 8545fd9bf4cd0d0838f626b405fd4963441546b7; jvm 17.0.9+9
2024-01-08 23:47:43.802+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2024-01-08 23:47:43.850+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: Session workerName=node0
2024-01-08 23:47:44.392+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-01-08 23:47:44.500+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@6778aea6{Jenkins v2.426.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2024-01-08 23:47:44.510+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@6955cb39{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-01-08 23:47:44.521+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started Server@7c098bb3{STARTING}[10.0.18,sto=0] @3529ms
2024-01-08 23:47:44.543+0000 [id=25] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2024-01-08 23:47:44.756+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2024-01-08 23:47:44.765+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2024-01-08 23:47:45.655+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2024-01-08 23:47:45.658+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2024-01-08 23:47:45.665+0000 [id=35] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2024-01-08 23:47:46.171+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2024-01-08 23:47:46.172+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-01-08 23:47:46.172+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-01-08 23:47:46.174+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-01-08 23:47:46.218+0000 [id=49] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2024-01-08 23:47:46.599+0000 [id=34] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
4adb6c4d31034b9382ff8d514071bc80
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2024-01-08 23:48:04.365+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-01-08 23:48:04.380+0000 [id=24] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2024-01-08 23:48:05.423+0000 [id=49] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2024-01-08 23:48:05.423+0000 [id=49] INFO hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
8) 젠킨스 내부 접속 아이피 확인
kubectl get nodes -o wide
root@master:~/jenkins# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master Ready control-plane 3d1h v1.29.0 10.0.100.2 <none> Ubuntu 22.04.3 LTS 5.15.0-91-generic containerd://1.7.2
node1 Ready <none> 3d v1.29.0 10.0.100.3 <none> Ubuntu 22.04.3 LTS 5.15.0-91-generic containerd://1.7.2
node2 Ready <none> 3d v1.29.0 10.0.100.4 <none> Ubuntu 22.04.3 LTS 5.15.0-91-generic containerd://1.7.2
node3 Ready <none> 3d v1.29.0 10.0.100.5 <none> Ubuntu 22.04.3 LTS 5.15.0-91-generic containerd://1.7.2
/* 마스터 또는 노드 아이피로 젠킨스 서버에 접속 되는지 확인 */
/* 외부 접속 노드 포트 확인 */
root@master:~/jenkins# kubectl get service -n jenkins
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins NodePort 10.104.2.121 <none> 8080:30000/TCP 8m27s
jenkins-jnlp ClusterIP 10.106.228.75 <none> 50000/TCP 8m27s
/* 외부 접속 노드 포트 : 30000 */
/* 내부 접속 확인 */
$ curl http://10.0.100.2:30000
root@master:~/jenkins# curl http://10.0.100.2:30000
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
-->
</body></html> root@master:~/jenkins# curl http://10.0.100.3:30000
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
-->
</body></html> root@master:~/jenkins# curl http://10.0.100.4:30000
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
-->
</body></html> root@master:~/jenkins# curl http://10.0.100.5:30000
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
-->
</body></html> root@master:~/jenkins#
/* 모든 노드 접속 확인 이상없으면 외부 포트 포트 포워딩하여 접속할수 있게 vm 포트 포워딩 추가 */
9) vm 포트 포워딩 추가
10) 브라우저에서 접속되는지 확인
http://192.168.2.50:30000
11) 샘플 파이프 라인 테스트
저장 버튼을 클릭하고 저장한다.
'시스템 > 쿠버네티스' 카테고리의 다른 글
[쿠버네티스] 아르고(Argo) cd 설치 (0) | 2024.01.09 |
---|---|
[쿠버네티스] 젠킨스 CI 구성 (0) | 2024.01.09 |
쿠버네티스 대시보드 설치 (0) | 2024.01.08 |
쿠버네티스 환경 설정 (0) | 2024.01.04 |
우분투 22.04 버추얼 머신 설치하기 (1) | 2024.01.04 |
댓글