🔎这里是【云原生实战】,关注我学习云原生不迷路
👍如果对你有帮助,给博主一个免费的点赞以示鼓励
欢迎各位🔎点赞👍评论收藏⭐️
👀专栏介绍
【云原生实战】 目前主要更新微服务,一起学习一起进步。
👀本期介绍
本期主要介绍DevOps基础与实战项目
文章目录
目录
DevOps简介
DevOps落地
项目架构
中间件
devops%E5%AE%9E%E6%88%98-toc" style="margin-left:0px;">devops实战
DevOps简介
DevOps 是一系列做法和工具,可以使 IT 和软件开发团队之间的流程实现自动化。其中,随着敏
捷软件开发日趋流行,持续集成 (CI) 和持续交付 (CD) 已经成为该领域一个理想的解决方案。在
CI/CD 工作流中,每次集成都通过自动化构建来验证,包括编码、发布和测试,从而帮助开发者提
前发现集成错误,团队也可以快速、安全、可靠地将内部软件交付到生产环境。
DevOps落地
概述
1、内置的Agent
选择 Jenkins Agent
项目架构
yygh-parent
|---common //通用模块
|---hospital-manage //医院后台 [9999]
|---model //数据模型
|---server-gateway //网关 [80]
|---service //微服务层
|-------service-cmn //公共服务 [8202]
|-------service-hosp //医院数据服务 [8201]
|-------service-order //预约下单服务 [8206]
|-------service-oss //对象存储服务 [8205]
|-------service-sms //短信服务 [8204]
|-------service-statistics //统计服务 [8208]
|-------service-task //定时服务 [8207]
|-------service-user //会员服务 [8203]
====================================================================
yygh-admin //医院管理后台 [9528]
yygh-site //挂号平台 [3000]
中间件
中间件 | 集群内地址 | 外部访问地址 |
Nacos | his-nacos.his:8848 | http://139.198.165.238:30349/nacos |
MySQL | his-mysql.his:3306 | 139.198.165.238:31840 |
Redis | his-redis.his:6379 | 139.198.165.238:31968 |
Sentinel | his-sentinel.his:8080 | http://139.198.165.238:31523/ |
MongoDB | mongodb.his:27017 | 139.198.165.238:32693 |
RabbitMQ | rabbitm-yp1tx4-rabbitmq.his:5672 | 139.198.165.238:30375 |
ElasticSearch | his-es.his:9200 | 139.198.165.238:31300 |
devops%E5%AE%9E%E6%88%98">devops实战
1、项目地址
https://gitee.com/leifengyang/yygh-parent
https://gitee.com/leifengyang/yygh-admin
https://gitee.com/leifengyang/yygh-site
2、项目默认规则
- 每个微服务项目,在生产环境时,会自动获取
微服务名-prod.yml
作为自己的核心配置文件 - 每个微服务项目,在生产环境时,默认都是使用
8080
端口
3、生产与开发配置隔离
4、deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: service-cart
name: service-cart
namespace: his #一定要写名称空间
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: service-cart
strategy:
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
app: service-cart
spec:
imagePullSecrets:
- name: aliyun-docker-hub #提前在项目下配置访问阿里云的账号密码
containers:
- image: $REGISTRY/$ALIYUNHUB_NAMESPACE/service-cart
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
timeoutSeconds: 10
failureThreshold: 30
periodSeconds: 5
imagePullPolicy: Always
name: app
ports:
- containerPort: 8080
protocol: TCP
resources:
limits:
cpu: 300m
memory: 600Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
labels:
app: service-cart
name: service-cart
namespace: his
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: service-cart
sessionAffinity: None
type: ClusterIP
4、devops实战
1、修改maven让他从阿里云下载镜像
- 使用admin登陆ks
- 进入集群管理
- 进入配置中心
- 找到配置
-
- ks-devops-agent
- 修改这个配置。加入maven阿里云镜像加速地址
2、缓存机制
已经下载过的jar包,下一次流水线的启动,不会重复下载
3、部署到k8s集群
- 给每一个微服务准备一个 deploy.yaml(k8s的部署配置文件)
- 执行以下步骤
传入 deploy.yaml 的位置就能部署
kubectl apply -f xxxx
一定在项目里面(his,不是流水线项目),找到配置--密钥,配置一个阿里云的访问账号密码
4、前端项目
1、yygh-admin
npm run build
会生成dist
目录,放到nginx的html下,即可运行
2、yygh-site
npm install --registry=https://registry.npm.taobao.org
安装项目依赖npm run build
对项目打包,
- 打包完成后把
.nuxt ,static, nuxt.config.js, package.json
这四个关键文件复制到node
环境。先npm install
再使用npm run start
即可运行
3、思考
- admin的镜像和site的镜像大小为何差距那么大?
-
- 如何对镜像进行瘦身?
5、webhook
- 1、每个项目,都有流水线文件
- 2、每次修改完项目,手动点击运行
- 3、希望,每次修改完项目,代码推送,流水线能自动运行
写代码并提交------> gitee ---------> 给指定的地方发请求(webhook)------> kubesphere平台感知到 -----> 自动启动流水线继续运行
- http://139.198.165.238:30880/devops_webhook/git/?url=https://gitee.com/leifengyang/yygh-admin.git