應對敏捷開發的需求,對CI(持續集成))/CD(持續交付)的提出了更高的標準,今天來討論下,如何基於開源組件(gitlab/jenkins/harbor/kubernetes)使用CI/CD,賦能團隊的開發、運維。node
Jenkins Slave根據流水線(Pipeline)定義的步驟執行構建。git
__注__:github
_注_: 本文主要說明下jenkins的部署及配置,其餘組件若是你部署有問題,歡迎留言。segmentfault
_說明_:api
部署示例的depployment.yaml 的註解緩存
nodeName ipaddress
, ipaddress 請確認其爲一個有效的ip./var/jenkins_home
是直接掛載到host_path, 若是你有條件,建議替換爲共享存儲。jenkins/jenkins:lts-alpine
推送至本身的內網鏡像倉庫。部署示例的ingress.yaml 的註解網絡
jenkins.dev.hanker.net
, 改成有效的域名地址,或是你也能夠經過NodePort
的形式聲明 service,就能夠直接經過ip:port
的形式訪問jenkins了。apiVersion: v1 kind: Namespace metadata: name: devops # Deployment apiVersion: extensions/v1beta1 kind: Deployment metadata: name: jenkins namespace: devops spec: replicas: 1 revisionHistoryLimit: 3 template: metadata: labels: app: jenkins spec: nodeName: 1.1.1.1 serviceAccountName: jenkins-admin containers: - image: jenkins/jenkins:lts-alpine imagePullPolicy: IfNotPresent name: jenkins volumeMounts: - name: jenkins-volume mountPath: /var/jenkins_home - name: jenkins-localtime mountPath: /etc/localtime env: - name: JAVA_OPTS value: '-Xms256m -Xmx1024m -Duser.timezone=Asia/Shanghai' - name: TRY_UPGRADE_IF_NO_MARKER value: 'true' ports: - name: http containerPort: 8080 - name: agent containerPort: 50000 resources: requests: cpu: 1000m memory: 1Gi limits: cpu: 1200m memory: 2Gi volumes: - name: jenkins-localtime hostPath: path: /etc/localtime - name: jenkins-volume hostPath: path: /home/jenkins/jenkins_home
--- apiVersion: v1 kind: Service metadata: name: jenkins-service namespace: devops spec: ports: - name: http protocol: TCP port: 8080 targetPort: 8080 - port: 50000 targetPort: 50000 name: agent selector: app: jenkins
apiVersion: v1 kind: ServiceAccount metadata: labels: k8s-app: jenkins name: jenkins-admin namespace: devops --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole metadata: name: jenkins-rbac namespace: devops rules: - apiGroups: ["","extensions","app"] resources: ["pods","pods/exec","deployments","replicasets"] verbs: ["get","list","watch","create","update","patch","delete"] --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: jenkins-admin namespace: devops labels: k8s-app: jenkins subjects: - kind: ServiceAccount name: jenkins-admin namespace: devops roleRef: kind: ClusterRole name: jenkins-rbac apiGroup: rbac.authorization.k8s.io
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: jenkins-ingress namespace: devops spec: rules: - host: jenkins.dev.hanker.net http: paths: - backend: serviceName: jenkins-service servicePort: 8080 path: /
$ pwd $ /home/jenkins_deploy $ kubectl apply -f *.yaml
[root@node0 jenkins_deploy]# kubectl -n devops get deployment jenkins NAME READY UP-TO-DATE AVAILABLE AGE jenkins 1/1 1 1 51d [root@node0 jenkins_deploy]#
注: 步驟1 聲明的域名 jenkins.dev.hanker.net
已經解析至ingress,故可直接訪問; 若是你也想經過自定義域名訪問jenkins,麻請解析至正確的ingress服務節點,便可。app
1.確認你也已經安裝了kubernetes/ kubernetes cli 插件運維
_操做指引_: 【Manage Jenkins】 -> 【Manage Plugins】ide
你應該能夠經過相似的指令獲取jenkins-master的密碼
$ kubectl -n devops exec jenkins-pod-name cat /var/jenkins_home/secrets/initialAdminPassword
2.配置Kubernetes 插件
_操做指引_: 【Manage Jenkins】->【Configure System】
圖中標註:
圖中標註:
指定工做目錄;
設置目錄掛載