1:首先你需要在nginx上确认是不是有你的新项目;
下面的以project项目名称为例 在你的配置映射里面进行进行查找 没有的话你需要进行添加:
location /project {
try_files $uri $uri/ /project/index.html;
}
2:导入YAML文件
yaml文件格式:project举例,到时候需要替换你的静态文件打包名称 需要将镜像文件放到注明的位置上
---
apiVersion: v1
kind: Service
metadata:
name: project
labels:
app: project
spec:
selector:
app: project
ports:
- name: server-port
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: project
spec:
replicas: 1
selector:
matchLabels:
app: project
template:
metadata:
labels:
app: project
spec:
imagePullSecrets:
- name: //这里每个公司不一样 需要你的镜像拉取地址
containers:
- name: project
image: //这里是你打包的镜像文件放在这
ports:
- containerPort: 80
name: server-port
resources:
limits:
memory: 1Gi
requests:
memory: 512Mi
env:
- name: TZ
value: Asia/Shanghai
volumeMounts:
- name: public-config//每个公司的配置文件不一样
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: public-config
configMap:
name: public-config
defaultMode: 0777
items:
- key: nginx.conf
path: nginx.conf
3:配置负载均衡
总结:大致经过以上三步,就可以在K8s上创建一个新的静态web服务,希望其他读者看后对你有所帮助,如若需讨论,可在评论留言.