Kubernetes(K8S) 配置静态资源服务
---
apiVersion: v1
kind: ConfigMap
metadata:
name: img-config
namespace: vipsoft
data:
img.conf: |
server {
charset utf-8;
listen 8080; #改端口、或者绑 域名、或者把default.conf 删除
server_name localhost;
add_header X-Frame-Options ALLOW-FROM;
location / {
root /img/;
}
access_log /app/logs/img_access.log main;
error_log /app/logs/img_error.log;
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: img
namespace: vipsoft
labels:
app: img
spec:
replicas: 1
template:
metadata:
name: img
labels:
app: img
spec:
imagePullSecrets:
- name: registry-vipsoft
containers:
- name: img
image: nginx:1.20.1
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /app/logs
name: applogs
- mountPath: /img
name: img
- mountPath: /etc/nginx/conf.d # Nginx 配置文件所在目录
name: img-config
resources:
requests:
cpu: "100m"
memory: "512Mi"
limits:
cpu: "1000m"
memory: "1024Mi"
volumes:
- name: img
hostPath:
path: /nfs/vipsoft/img
- name: img-config
configMap:
name: img-config
restartPolicy: Always
selector:
matchLabels:
app: img
---
apiVersion: v1
kind: Service
metadata:
name: service-img
namespace: vipsoft
spec:
selector:
app: img
ports:
- name: img
port: 8080 # 服务访问端口
targetPort: 8080 # 容器端口
nodePort: 30080 # 对外暴露的端口
type: NodePort
标签:Kubernetes,img,静态,app,metadata,vipsoft,log,K8S,name
From: https://www.cnblogs.com/vipsoft/p/16911125.html