Kubernetes(K8S) 配置静态资源服务

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

 
posted @   VipSoft  阅读(352)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示