Jenkins流水線發布實現CICD到Kubernetes
第一步 本地安裝好Kubernetes
第二步— Install Jenkins
a) Install Java
sudo apt update
sudo apt install openjdk-8-jdk
b) Add Jenkins Repository & append package repository address to the server’s source.list
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
c) Install Jenkins
sudo apt update
sudo apt install jenkins
d) check Jenkins status
e) Configure Jenkins with necessary credentials and login to Jenkins
f) Add Jenkins to the docker group “sudo usermod -aG docker jenkins”
g) Install the following plugins for Jenkins
Docker Pipeline
Kubernetes
Kubernetes Continuous Deploy
h) The final step is to use ngrok to expose localhost Jenkins URL as public URL.
Download ngrok and execute it as shown in the image, http://a0ecbd0426f6.ngrok.io/ is the new URL to login to Jenkins and accessible over the internet.
使用ngrok 內網穿透實現本地jenkins互聯網能夠訪問到
第三步: 配置Jenkins Configure Jenkins
a) 選擇 流水線項目Select Demo1 as New Pipeline Project
b) 填入 the GitHub link的倉庫地址
c) Mention the build trigger配置構建觸發器
d) 在流水線中配置GIT地址 In the Pipeline mention the git links and the branch it has to operate upon
e) 配置dockerhub密鑰 Configure docker hub credentials
f) Update Jenkinsfile -Its a declarative pipeline which is used as a code. It helps the pipeline code easier to read and write. This code is written in a Jenkinsfile.
當代碼提交到github時,Jenkins會收到一個webhook已配置於Github, 整個階段流程如下:
In this implementation, the moment code is checked-in, Jenkins will have a notification through a webhook configured in Github. it follows the following stages below
i) Check out the source
ii)Build the new image
iii) Push it to the new repository
iv) Deploy the app on Kube
pipeline {
agent any
stages {
stage('Checkout Source') {
steps {
git url:'https://github.com/vamsijakkula/hellowhale.git', branch:'master'
}
}
stage("Build image") {
steps {
script {
myapp = docker.build("vamsijakkula/hellowhale:${env.BUILD_ID}")
}
}
}
stage("Push image") {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
myapp.push("latest")
myapp.push("${env.BUILD_ID}")
}
}
}
}
stage('Deploy App') {
steps {
script {
kubernetesDeploy(configs: "hellowhale.yml", kubeconfigId: "mykubeconfig")
}
}
}
}
}
g) Have the configuration of mykubeconfig in Jenkins defined
h) Also have the connection between Jenkins and Kubernetes in place
i) Mention the Jenkins URL
j)Update the pod template.
k) Configure the webhook in Github
第4步 — Develop application deployment manifest. In this tutorial, we are deploying a simple hellowhale app exposed as NodePort.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-blue-whale
spec:
replicas: 3
selector:
matchLabels:
app: hello-whale-app
version: blue
template:
metadata:
name: hello-blue-whale-pod
labels:
app: hello-whale-app
version: blue
spec:
containers:
- name: hello-whale-container
image: vamsijakkula/hellowhale:latest
imagePullPolicy: Always
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: hello-whale-svc
labels:
app: hello-whale-app
spec:
selector:
app: hello-whale-app
version: blue
type: NodePort
ports:
- nodePort: 31113
port: 80
targetPort: 80
第5步: Check-in the application manifest in GitHub and we can see the deployment starting in Jenkins
第6步 Once the deployment is completed, we can see the following pods(3) are in place and exposed as NodePort(31113)
Access the deployment on NodePort.
第7步: 通過deployment調整實例從3個到5個,如下在kube可以看到。 Update the deployment by changing the replica’s from 3 to 5 and we can see 5 pods are deployed on Kube.
GIT示例倉庫 https://github.com/vamsijakkula/hellowhale
總結
此示例以本地環境部署Kubernetes的2個簡單結點,內網穿透暴露於互聯網, 基於nginx的前端程序構建docker,通過jenkins的pipeline流水線發布到Kubernetes.
實現CI CD過程,示例代碼於公網。 對雲原生技術CI CD是關鍵的DevOps基礎過程,需要今天廣大開發工程師了解。
今天先到這兒,希望對雲原生,技術領導力, 企業管理,系統架構設計與評估,團隊管理, 項目管理, 產品管管,團隊建設 有參考作用 , 您可能感興趣的文章:
領導人怎樣帶領好團隊
構建創業公司突擊小團隊
國際化環境下系統架構演化
微服務架構設計
視頻直播平台的系統架構演化
微服務與Docker介紹
Docker與CI持續集成/CD
互聯網電商購物車架構演變案例
互聯網業務場景下消息隊列架構
互聯網高效研發團隊管理演進之一
消息系統架構設計演進
互聯網電商搜索架構演化之一
企業信息化與軟件工程的迷思
企業項目化管理介紹
軟件項目成功之要素
人際溝通風格介紹一
精益IT組織與分享式領導
學習型組織與企業
企業創新文化與等級觀念
組織目標與個人目標
初創公司人才招聘與管理
人才公司環境與企業文化
企業文化、團隊文化與知識共享
高效能的團隊建設
項目管理溝通計划
構建高效的研發與自動化運維
某大型電商雲平台實踐
互聯網數據庫架構設計思路
IT基礎架構規划方案一(網絡系統規划)
餐飲行業解決方案之客戶分析流程
餐飲行業解決方案之采購戰略制定與實施流程
餐飲行業解決方案之業務設計流程
供應鏈需求調研CheckList
企業應用之性能實時度量系統演變
如有想了解更多軟件設計與架構, 系統IT,企業信息化, 團隊管理 資訊,請關注我的微信訂閱號:
作者:Petter Liu
出處:http://www.cnblogs.com/wintersun/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。 該文章也同時發布在我的獨立博客中-Petter Liu Blog。