Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD

这篇具有很好参考价值的文章主要介绍了Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、资源清单

机器名称 IP地址 角色
k8s+rancher高可用部署: https://blog.csdn.net/qq_41594280/article/details/135312148
rancher 10.211.55.200 管理K8S集群
k8svip 10.211.55.199 K8S VIP
master01 10.211.55.201 K8S集群主节点
master02 10.211.55.202 K8S集群主节点
master03 10.211.55.203 K8S集群主节点
node01 10.211.55.211 K8S集群从节点
node02 10.211.55.212 K8S集群从节点
Harbor容器私服安装部署: https://blog.csdn.net/qq_41594280/article/details/135447118
harbor 10.211.55.20 docker容器私服
Gitlab代码仓库安装部署: https://blog.csdn.net/qq_41594280/article/details/135491802
gitlab 10.211.55.33 代码仓库
Jenkins安装部署: https://blog.csdn.net/qq_41594280/article/details/135442317
jenkins 10.211.55.34 持续集成工具

二、Jenkins与GitLab集成实现自动构建(可忽略)

2.0 安装Git和Maven

# 安装Git
[root@jenkins ~]# yum install -y git
[root@jenkins ~]# git --version
git version 1.8.3.1

# 安装maven,地址: https://archive.apache.org/dist/maven
wget https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
mkdir /opt/maven
tar xzvf apache-maven-3.8.6-bin.tar.gz -C /opt/maven

vim ~/.bash_profile
# 内容 BEGIN
export M2_HOME=/opt/maven/apache-maven-3.8.6
export PATH=$M2_HOME/bin:$PATH
# 内容 END
source ~/.bash_profile

[root@jenkins ~]# mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /opt/maven/apache-maven-3.8.6
Java version: 11.0.21, vendor: Oracle Corporation, runtime: /opt/java/jdk-11.0.21
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "5.11.12-300.el7.aarch64", arch: "aarch64", family: "unix"

vim /opt/maven/apache-maven-3.8.6/conf/settings.xml
<localRepository>/opt/maven/repo</localRepository>

<mirrors>
	<!--<mirror>
	      <id>maven-default-http-blocker</id>
	      <mirrorOf>external:http:*</mirrorOf>
	      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>-->
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

2.1 下载安装Pipeline插件

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

2.2 Jenkins 安装插件 GitLab Plugin、Maven Integration Plugin

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

2.3 服务器编写测试脚本

[root@jenkins ~]# echo "echo "hello world"" >demo.sh
[root@jenkins ~]# chmod +x demo.sh
[root@jenkins ~]# ll demo.sh
-rwxr-xr-x. 1 root root 16 113 16:28 demo.sh

2.4 Jenkins创建自由风格项目并填写构建脚本

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

2.5 配置钩子脚本

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

# 服务器执行安装openssl
yum install -y openssl
# 生成ssl令牌 -> d22f1292ecf0a36007ab
openssl rand -hex 10

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

2.6 GitLab创建项目添加钩子脚本

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
保存报错
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
解决:Settings → Network → Outbound requests
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
再次添加hooks
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
报错
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
解决
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
还不行,去掉Jenkins系统设置里的 Enable authentication for ‘/project’ end-point
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
自动构建成功
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

三、基于Jenkins、Harbor、GitLab自动部署SpringBoot项目到K8S

3.1 创建项目

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

3.2 配置Jenkins

参考2.4~2.6配置即可,最终验证钩子返回200 OK
Manage Jenkins → Tools
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

3.3 配置Harbor

添加用户Jenkins
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
添加项目
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

项目添加成员
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

3.4 Jenkins和K8S Master做免密

# jenkins, 若有可不执行
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa

[root@jenkins ~]# cat ~/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAwfUH1Oa1e3eAmV8yK84w7BaKYv5d82qXhi1Jmhy0St8YkKOe
OcrjPAGtkEQZCcr8Ee/GY7mjG5YT6eK/mWyJqMlqImxjC63CjNL/zhR8x0BV7c3r
tZ4iyg/61QO8cwguN0u7wwCHT9i9xQ9hBUrz1a80MmlwjUCobLu1U0kCw32YEerm
Ux6xPkP3Wyin9qQqxNcaHlnWkw4I7QyQQgItElOFnGxy9wj8PG5n7xPEGZw+jJFX
J9v1pa7t92z/HpxxMrVRpuRpUCqeXRCmter7AeHh+ClPxTjEcnq7McZAFHJ/32d/
k0JXL50d/FP4gxDEsnTOZoUXKHhPfT+QGieTKwIDAQABAoIBABXynEhDMxYdl7fD
RfIfCvosMsyw7AC3dx3/0exWgzBVvnnfifAQPVZ0+ibxDcRF6/A7qb9vKj3c5bP5
rKS323v2DsSGb07LAtDcr4WqW9RQO2kFfD64/kbPOBsSqSh7LH+lWkHetXEbnZ3G
97uZl63+fXGW7N2PC4ACXapnAKEOSqi+gBRTS9kaMUrnCkDTF60HVXgCJSQ7z5jI
5OVhD5Mbld6ey/FtZWIuNHRfdN1eQWDnPB5Twia/w6l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"/root/.ssh/id_rsa.pub"
The authenticity of host '10.211.55.201 (10.211.55.201)' can't be established.
ECDSA key fingerprint is SHA256:ZAzP64mdrYfOM1o3bwXlqY1JFOiNsbAbiHnWKv1ogLo.
ECDSA key fingerprint is MD5:d9:12:05:84:0e:79:7c:5f:6b:13:a2:97:6f:cb:a7:72.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.211.55.201's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '10.211.55.201'"
and check to make sure that only the key(s) you wanted were added.

# 验证
[root@jenkins ~]# ssh root@10.211.55.201
Last login: Sun Jan  7 13:03:41 2024 from 10.211.55.2
[root@master01 ~]#

3.5 Jenkins登录Harbor

# 修改docker配置文件,添加Harbor地址
vim /etc/docker/daemon.json

# 内容BEGIN
#insecure-registries表示后面的registry地址为非安全的.在master和node都要加,不然拉取不了镜像
"insecure-registries":["10.211.55.20"]
# 内容END

sudo systemctl daemon-reload && sudo systemctl restart docker

# 测试登录, harbor关闭防火墙 systemctl stop firewalld && systemctl disable firewalld
docker login harbor.zhinian.com -u jenkins -p Harbor@123456

遇到问题
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
解决

[root@jenkins ~]# docker login harbor.zhinian.com -u jenkins -p Harbor@123456
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

3.6 Jnekins配置-继续

问题:控制台输出报错

Started by GitLab push by 王小虎
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/springboot-demo
[springboot-demo] $ /bin/sh -xe /tmp/jenkins7820913899171498991.sh
+ pwd
/var/lib/jenkins/workspace/springboot-demo
+ ls
+ mvn clean package -Dmaven.test.skip=true
/tmp/jenkins7820913899171498991.sh:行4: mvn: 未找到命令
Build step 'Execute shell' marked build as failure
Finished: FAILURE

解决:

ln -s /opt/maven/apache-maven-3.8.6/bin/mvn /usr/bin/mvn

Build Steps

pwd
ls
git --version
rm -rf springboot-demo && git clone git@gitlab.zhinian.com:opit/springboot-demo.git
cd springboot-demo && mvn clean package -Dmaven.test.skip=true
docker login harbor.zhinian.com -u jenkins -p Harbor@123456
docker build -t springboot-demo:latest .
docker tag springboot-demo:latest harbor.zhinian.com/opit/springboot-demo:latest
docker push harbor.zhinian.com/opit/springboot-demo:latest && docker rmi springboot-demo:latest && docker rmi harbor.zhinian.com/opit/springboot-demo:latest
scp -r script/springboot-demo.yaml root@10.211.55.201:~/kube-conf/
ssh 10.211.55.201 'kubectl apply -f /root/kube-conf/springboot-demo.yaml'
ssh 10.211.55.201 'kubectl get pod -n prod'

3.7 提交代码进行测试

# 提交并Push到仓库
git commit && git push ... after

# 自动构建部署
1.jenkins auto build
2.maven build success
3.docker build success
4.docker push harbor success
5.kubectl apply success

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

[root@master01 kube-conf]# kubectl get po springboot-demo-deploy-c4c5cf4d8-bs6k7 -n prod
NAME                                     READY   STATUS    RESTARTS   AGE
springboot-demo-deploy-c4c5cf4d8-bs6k7   1/1     Running   1          6m7s

Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes
Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD,macos,rancher,kubernetes

四、基于GitLab的CICD自动构建部署

Waiting…文章来源地址https://www.toymoban.com/news/detail-805550.html


  • https://cloud.tencent.com/developer/article/1444269
  • https://zhuanlan.zhihu.com/p/583345352
  • https://blog.csdn.net/littlehaes/article/details/104694375
# https://hub.docker.com/_/openjdk/tags?page=6
docker pull openjdk:22-ea-jdk-oraclelinux8
docker tag openjdk:22-ea-jdk-oraclelinux8 java:8

到了这里,关于Mac M1 Parallels CentOS7.9 Rancher + K8S + Gitlab + Jenkins +Harbor CICD的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Centos7安装K8S

    根据以前一些博主写的博客,在小阳翻了不下几十篇博客之后,我果断是放弃了,于是找到了官网地址,然后也有 坑 1. 关闭防火墙 systemctl stop firewalld systemctl disable firewalld 2. 关闭 selinux(2,3根据自己情况选择哈) sed -i \\\'s/enforcing/disabled/\\\' /etc/selinux/config 这个是永久关闭 setenfor

    2024年01月16日
    浏览(46)
  • centos7安装k8s集群

    安装kubeadm、kubelet、kubectl 初始化成功,获得一下命令: 执行一下命令: 打开网络插件kube-flannel.yml文件,修改网络: 执行 kubectl apply -f kube-flannel.yml kubectl get all -A kubectl taint nodes k8s-master node-role.kubernetes.io/master- 1.克隆k8s-node1虚机,作为node节点 2.修改克隆的虚机的ip 和  hos

    2024年04月27日
    浏览(44)
  • CentOS7使用Yum安装k8s

    注意:这里安装测试的k8s版本比较低 k8s核心功能 自我修复 服务发现和负载均衡 自动部署和回滚 弹性伸缩 服务器环境准备 参考 k8s 安装部署 1 - 环境准备 准备3台服务器 Linux修改配置 配置Docker安装源 配置kubernetes安装源 安装etcd 在master节点安装配置etcd 安装k8s master 在master节

    2023年04月16日
    浏览(44)
  • Centos7部署单机版K8S

    2024年02月04日
    浏览(51)
  • VMWare中Centos7部署K8S集群

    关于我们要搭建的K8S: Docker版本:docker-ce-19.03.9; K8S版本:1.20.2; 三个节点:master、node1、node2(固定IP); 容器运行时:仍然使用Docker而非Containerd; Pod网络:用Calico替换Flannel实现 Pod 互通,支持更大规模的集群; 集群构建工具:Kubeadm(这个没啥好说的吧); 关于网络配

    2024年02月15日
    浏览(44)
  • Mac Parallels19.1.0 Install CentOS7.9

    0、资源准备 1、打开PD 2、选择镜像进行安装 指定镜像名称 创建 进行密码设置 安装目的地点开后直接点击完成 网络和主机名称 开始安装 安装成功!

    2024年01月23日
    浏览(83)
  • centos7搭建k8s环境并部署springboot项目

    之前看了很多文章,都是部署后一直报错,百度解决后下次又忘了,这次决定把从头到尾的过程记录下来方便下次再看 ,部署参考文章尚硅谷Kubernetes(k8s)视频学习笔记_尚硅谷k8s笔记_溯光旅者的博客-CSDN博客 1、先去下载vmware虚拟机安装,我安装的是这个版本VMware Workstati

    2024年02月03日
    浏览(43)
  • Centos7 安装部署 Kubernetes(k8s) 高可用集群

    宿主机系统 集群角色 服务器IP 主机名称 容器 centos7.6 master 192.168.2.150 ks-m1 docker centos7.6 master 192.168.2.151 ks-n1 docker centos7.6 master 192.168.2.152 ks-n2 docker 1.1 服务器初始化及网络配置 VMware安装Centos7并初始化网络使外部可以访问** 注意事项:请一定要看完上面这篇文章再执行下面的操

    2024年02月03日
    浏览(56)
  • k8s 安装 kubernetes安装教程 虚拟机安装k8s centos7安装k8s kuberadmin安装k8s k8s工具安装 k8s安装前配置参数

    k8s采用master, node1, node2 。三台虚拟机安装的一主两从,机器已提前安装好docker。下面是机器配置,k8s安装过程,以及出现的问题与解决方法   虚拟机全部采用静态ip, master 30机器, node1 31机器, node2 32机器                                        机器ip 192.168.

    2024年02月11日
    浏览(50)
  • CentOS7使用kubeadm部署k8s-1.28集群

    参考资料:生产环境 记录使用CentOS7.9进行k8s-1.28版本部署,运行时环境使用containerd,网络插件使用calic,集群搭建完成后。搭建NFS共享存储环境,测试运行pod并挂载使用持久卷。 主机名 **IP地址 ** 角色 基础组件 el7-linux-node-01 192.168.240.11 k8s-master kubeadm,kubelet,kubectl,containerd,nf

    2024年04月26日
    浏览(48)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包