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。