K8S+GitLab-自动化分布式部署ASP.NET Core(一) 部署环境
程序员文章站
2022-04-28 11:57:30
一.部署流程介绍 开发人员通过Git上传asp.net core 项目到Gilab,并编写好.gitlab-ci.yml , GitLab-Runner 自动拉取代码,然后进行Build,编译,单元测试,生成镜像,并推送到Harbor仓库,docker 进行测试部署,最后部署部署到K8S. 二.集群 ......
一.部署流程介绍
开发人员通过git上传asp.net core 项目到gilab,并编写好.gitlab-ci.yml , gitlab-runner 自动拉取代码,然后进行build,编译,单元测试,生成镜像,并推送到harbor仓库,docker 进行测试部署,最后部署部署到k8s.
二.集群组件介绍
节点 | ip | 组件 |
deploy | 192.168.0.201 |
breeze |
master01 | 192.168.0.202 | docker+loadbalancer+etc+k8s |
harbor | 192.168.0.203 | harbor+docker |
work01 | 192.168.0.204 | docker+gitlab |
work02 | 192.168.0.205 | docker+gitlab-runner |
三.部署组件
1.先部署k8s 环境.
推荐两种部署方式:
1.https://github.com/wise2c-devops/breeze (可视化kubernetes集群部署工具,注本篇的部署方式)
2.https://github.com/opsnull/follow-me-install-kubernetes-cluster (手动部署)
2.部署redis
docker-compose安装推荐
https://www.cnblogs.com/guoyiwen/p/10391885.html
3.部署gitlab,使用docker-compose方式,创建docker-compose.yml文件
version: '3' services: gitlab: image: 'twang2218/gitlab-ce-zh' container_name: gitlab restart: unless-stopped environment: tz: 'asia/shanghai' gitlab_omnibus_config: | external_url 'http://gitlab.evan.com' gitlab_rails['time_zone'] = 'asia/shanghai' #以下为启用邮件相关设置,我用的是qq邮箱 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = 'smtp.qq.com' gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = '你的邮箱@qq.com' gitlab_rails['smtp_password'] = '邮箱密码' gitlab_rails['smtp_domain'] = 'smtp.qq.com' gitlab_rails['smtp_authentication'] = 'plain' gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = '你的邮箱@qq.com' user["git_user_email"] = '你的邮箱@qq.com' #修改sidekiq的数量,减少内存占用,默认为15,也可以不填 sidekiq['concurrency'] = 10 #使用外部redis所需设置,根据刚刚生成的redis设置修改 gitlab_rails['redis_port'] = 6379 gitlab_rails['redis_host'] = '127.0.0.1' gitlab_rails['redis_password'] = '123' gitlab_rails['redis_database'] = '2' #因为22端口被占用,修改映射的端口号时,同时修改在gitlab项目中的ssh地址加上端口号 gitlab_rails['gitlab_shell_ssh_port'] = 10022 ports: - '10080:80' - '10443:443' - '10022:22' networks: - net_db volumes: - ./config:/etc/gitlab - gitlab-data:/var/opt/gitlab - ./logs:/var/log/gitlab volumes: gitlab-data: external: true networks: net_db: external: true
docker network create net_db
docker volume create gitlab-data
docker-compose up -d
docker-compose logs -f (查看部署状态)
修改gitlab.rb文件
external_url 'http://你的gitlab地址:10080'
nginx['listen_port'] =80
docker-compose restart
部署成功后git运行以下命令:
git global setup(git全局设置):
git config --global user.name "xxx"
git config --global user.email "xxx.com"
ssh-keygen -t rsa -c "xxx@qq.com" -b 4096
cat ~/.ssh/id_rsa.pub
ssh -t -p 10022 git@localhost (修改成你的地址,测试是否连接成功)
打印: welcome to gitlab, @xxx! 说明成功了
4.安装部署gitlab-runner(centos7)
如果官方的runner下载不了下载下面的
链接: https://pan.baidu.com/s/1q7erww53osi0lry8so8gaw 提取码: d9n7
1.下载二进制文件
# linux x86-64 sudo wget -o /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
2.赋予它执行权限:
sudo chmod +x /usr/local/bin/gitlab-runner
3.创建gitlab ci用户:
sudo useradd --comment 'gitlab runner' --create-home gitlab-runner --shell /bin/bash
4.将gitlab ci用户添加到docker运行用户的组里面
sudo usermod -ag root gitlab-runner
5.安装并作为服务运行:
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
6.注册gitlab-runner ,shell 方式
sudo gitlab-runner register
官网参考链接:https://docs.gitlab.com/runner/register/index.html
7.测试
sudo -u gitlab-runner -h docker info
8.给gitlab-runner 执行kubectl权限,拷贝 /root/.kube 文件夹 到 gitlab-runner 用户家目录下,且修改此文件夹属于 gitlab-runner用户和组
chown -r gitlab-runner.gitlab-runner .kube
sudo -u gitlab-runner kubectl get cs
5.安装.net core sdk (centos7)
在部署gitlab-runner的机器上安装sdk,因为gitlab ci 要构建代码和运行asp.net core单元测试.
sudo rpm -uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.2
微软官方安装链接
6.下一章节:asp.net core devops
上一篇: 来来来,走过路过别错过
下一篇: 线上实操中端暴利产品运营推广全历程
推荐阅读
-
Linux下自动化部署ASP.NET CORE 3.1(Docker+Jenkins+Nginx)
-
详解将ASP.NET Core应用程序部署至生产环境中(CentOS7)
-
【.NET Core】Docker Jenkins ASP.NET Core自动化部署
-
Asp.Net Core 使用Docker进行容器化部署(一)
-
K8S+GitLab-自动化分布式部署ASP.NET Core(二) ASP.NET Core DevOps
-
K8S+GitLab-自动化分布式部署ASP.NET Core(一) 部署环境
-
关于Jenkins + Docker + ASP.NET Core自动化部署的问题(避免踩坑)
-
ASP.NET Core部署系列一:发布到IIS上
-
asp.net core结合docker实现自动化获取源码、部署、更新
-
又一篇Centos7下的asp.net core部署教程