已解决
使用Docker/K8S/Helm部署项目流程
来自网友在路上 167867提问 提问时间:2023-11-20 10:12:11阅读次数: 67
最佳答案 问答题库678位专家为你答疑解惑
假设项目已经开发完成,部署流程如下:
一、制作镜像:
1、创建nginx配置文件default.conf
server {listen 80;server_name localhost; # 修改为docker服务宿主机的iplocation / {root /usr/share/nginx/html;index index.html index.htm;try_files $uri $uri/ /index.html =404;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}
}
root /usr/share/nginx/html:这个目录和下面创建的Dockerfile中目录要保持一致
2、创建Dockerfile
FROM nginx:1.20.2MAINTAINER testRUN rm /etc/nginx/conf.d/default.confADD default.conf /etc/nginx/conf.d/COPY dist/ /usr/share/nginx/html
- FROM nginx -- 打包容器的底层来刚才先拉取的nginx
- MAINTAINER beizhu:备注
- RUN rm /usr/local/nginx/conf/nginx.conf.default:删除目录下的nginx.conf.default 文件
- ADD nginx.conf.default /usr/local/nginx/conf/:将default.conf复制到/usr/local/nginx/conf/下,用本地的default.conf配置来替换nginx镜像里的默认配置
- COPY dist/ /usr/local/nginx/html/:将项目根目录下dist文件夹(构建之后才会生成)下的所有文件复制到镜像/usr/local/nginx/html/目录下上一步root地址
3、准备静态模板(项目)
4、打包docker镜像image并推送
docker build -f Dockerfile -t [dockerhub用户名]/web-pro:1.0 .
docker push [dockerhub用户名]/web-pro:1.0
如果是用的阿里云镜像,请参照阿里云镜像推送方式。
二、K8S部署:
1、编写 K8S yaml 文件
vi deploy-web.yaml
apiVersion: v1
kind: Namespace
metadata:name: shop-web---apiVersion: apps/v1
kind: Deployment
metadata:name: manager-webnamespace: shop-web
spec:replicas: 1selector:matchLabels:app: manager-webtemplate:metadata:labels:app: manager-webspec:containers:- name: manager-webimage: registry.cn-hangzhou.aliyuncs.com/samve/k8s:2.0ports:- name: httpcontainerPort: 80
---apiVersion: v1
kind: Service
metadata:name: manager-ui-servicenamespace: shop-web
spec:selector:app: manager-webports:- name: httpprotocol: TCPport: 80targetPort: 80nodePort: 30001type: NodePort
2、部署服务
kubectl apply -f deploy-web.yaml
三、使用helm部署:
1、准备环境 k8s集群
[root@k8s-master-136 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master-136 Ready control-plane,master 296d v1.21.0
k8s-node-135 Ready <none> 296d v1.21.0
k8s-node-137 Ready <none> 296d v1.21.0
2、创建一个模板的chart包,删除原来的内容,自定义成我们自己需要的内容,后面我们自定义部署的yaml文件
[root@k8s-master-136 ~]# helm create nginx-chart
Creating nginx-chart
[root@k8s-master-136 nginx-chart]# cd ./nginx-chart/templates/
[root@k8s-master-136 templates]# rm -rf ./*
自定义部署的模板yaml文件:
vim templates/nginx-deploy-service.yaml
nginx-deploy-service.yaml
apiVersion: v1
kind: Namespace
metadata:name: {{.Values.namespace}}---apiVersion: apps/v1
kind: Deployment
metadata:name: {{.Values.deployment_name}}namespace: {{.Values.namespace}}
spec:replicas: {{.Values.replicas}}selector:matchLabels:app: {{.Values.pod_label}}template:metadata:labels:app: {{.Values.pod_label}}spec:containers:- name: {{.Values.pod_label}}image: registry.cn-hangzhou.aliyuncs.com/samve/k8s:2.0ports:- name: httpcontainerPort: {{.Values.containerport}}
---apiVersion: v1
kind: Service
metadata:name: {{.Values.service_name}}namespace: {{.Values.namespace}}
spec:selector:app: {{.Values.pod_label}}ports:- name: httpprotocol: TCPport: {{.Values.port}}targetPort: {{.Values.targetport}}nodePort: {{.Values.nodeport}}type: NodePort
[root@k8s-master-136 nginx-chart]# vim values.yaml
values.yaml
deployment_name: manager-web
service_name: manager-web-service
namespace: shop-web
pod_label: manager-web
replicas: 2
port: 80
targetport: 80
containerport: 80
nodeport: 30002
3、通过chart包安装一个release实例
[root@k8s-master-136 ~]# helm install nginx-service ./nginx-chart
NAME: nginx-service
LAST DEPLOYED: Sun Nov 19 21:50:28 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
[root@k8s-master-136 nginx-chart]# vim values.yaml
[root@k8s-master-136 nginx-chart]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
nginx-service default 1 2023-11-19 21:50:28.744590789 +0800 CST deployed nginx-chart-0.1.0 1.16.0
查看全文
99%的人还看了
相似问题
- 树莓派镜像安装 + 设置 + 镜像批量化操作 - 自动化烧写工具 (四)
- composer切换全局镜像源的方法
- 推荐一个windows上传linux服务器/linux服务器的docker镜像的工具,摆脱docker cp,以及解决常见问题。
- docker下移除不使用的镜像、容器、卷、网络
- 一起学docker系列之四docker的常用命令--系统操作docker命令及镜像命令
- qcow2、raw、vmdk等镜像格式工具
- 获取阿里云Docker镜像加速器
- 3.8-镜像的发布
- 【备忘录】Docker容器、镜像删除与资源清理命令
- 8.jib-maven-plugin构建springboot项目镜像,docker部署配置
猜你感兴趣
版权申明
本文"使用Docker/K8S/Helm部署项目流程":http://eshow365.cn/6-40248-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!