街机捕鱼首页 | XML地图 | RSS订阅 | 站点导航 欢迎光临 街机捕鱼

当前位置:主页 > 视频 >

Gitlab+JenkinsPipeline+k8s在生产环境中的应用

时间:2020-06-07 | 来源:街机捕鱼 | 作者:街机捕鱼 | 阅读:6447次 |
系统环境说明GitLabCommunityEdition11.9.8Jenkinsver.2.190.3仓库使用阿里的镜像仓库Kubernetesv1.14.2

gitlab和jenkins-master可以选择自建或者部署到k8s中,当前场景是部署在k8s集群之外;

镜像仓库可以选择使用harbor或者阿里镜像仓库,当前场景使用的是阿里的镜像仓库;

编译发布流程

流程很简单,提交代码到不同的分支,触发通知到jenkins,jenkinspipeline会根据Jenkinsfile文件中定义k8s环境,动态生成一个jenkinsslave在不同k8s环境中构建镜像,推送镜像到仓库,然后在部署到对应k8s环境,部署结束后jenkinsslave会自动终止

集成配置过程

因为都是现有的环境,所以部署过程就省略了,直接开始做集成配置;如果你是全新安装的Jenkins,选择安装推荐插件+kubernetes插件;现在假如插件都已经安装完成了,jenkins登陆默认账户admin,密码查看/var/jenkins_home/secrets/initialAdminPassword文件,下面开始配置

点击左侧系统管理,打开系统配置,我们这里要实现部署发布到2个k8s环境,所以我们配置两个云,先新增一个云

名称:随便填,后面Jenkinfile会用到

Kuberneters地址:填写apiserver地址

Kuberneters服务证书key:需要拿k8s的crt和key做格式转换,下面会介绍

Kubernetes命名空间:填写jenkinsslave要生成的命名空间,这个自己看着填吧

凭据:需要拿k8s的crt和key做格式转换,然后生成jenkins全局凭据

Jenkins地址:填写jenkinsmaster地址,也就是当前jenkins地址

Jenkins通道:填写jenkinsmaster与jenkinsslave通信地址,jenkins通信端口默认是50000

配置第一个k8s相关信息,过程中会用到认证k8sapiserver的key和凭证,所以我们先获取下需要的key和凭证

$cat/root/.kube/configapiVersion:v1clusters:-cluster:certificate-authority-data:LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0Z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G5oZ1dDbHh1M0F4OWgKaVRELzAyczRCcWZKTFZjZXk0Q2VnWW8zUDVDYWVjTTZSaTg4TVFKYlZ1OWx6RVZPUzlBRGNKZ0VkWkdHUFUyVwpEcHBhZXdZNjhSVVg1MG9ObXN2S2h1RGNCSWxyeHJ4T2J4Wk1wYm5hYldUMlFaKzM4ampEaDNwVmxhcz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=server:https://192.168.0.54:6443name:kubernetescontexts:-context:cluster:kubernetesuser:kubernetes-adminname:kubernetes-admin@kubernetescurrent-context:kubernetes-admin@kuberneteskind:Configpreferences:{}users:-name:kubernetes-adminuser:client-certificate-data:LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJSzZSZWRVQ2NNS0V3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4T1RBMk1EWXhNREkyTURsYUZ3MHlNREEyTURVeE1ESTJNVEZhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTBrcW1jci9DNHBaSTgwUTAKTzBOaklRV1hPelQ0TmVPVFJQd0N1UW1CaDlZcUJ0QTBkZnJvVnRzT2JRTEdlWE5GUVlhRzM5V2ZsN292YURCNwp3Wm11WVo3alZKUm9BZmpldEg3d0lIN3pNYUdCbk1hN3RoTUNqWXBmdXRpQyszQm51cjFLRmFJR2FKcDNlK0NQCjAyVjdSVDJjUXFPbHVOVUtFSEl2UG15YTdKM0pHWUpLNFVBVEhQOVhIMVZNemVoc3N5ZjF5UTZZb1BxTTR1b08KVGVNN3g0NFcvS2hrWjBMWkhncnB5RDJQNlN2NGVoaGl6YTQrdUk1Si80OFh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