栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

k8S通过Nginx挂载静态资源

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

k8S通过Nginx挂载静态资源

k8S通过Nginx挂载静态资源 1、上传静态资源到服务器

我们将准备好的静态资源上传到服务器 /home/rke/nginx/html 该路径下

2、编写Nginx的Deployment

注意:Nginx通过K8S部署之后所使用的nginx.conf和静态文件位置的内容都需要通过挂载的方式去配置使用

apiVersion: apps/v1
kind: Deployment
metadata:
  name: photo-nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: photo-nginx
  template:
    metadata:
      labels:
        app: photo-nginx
    spec:
      containers:
      - name: photo-nginx
        image: nginx
        imagePullPolicy: Always
        ports:
        - containerPort: 83
        volumeMounts:
        - mountPath: /etc/nginx/nginx.conf
          name: photo-conf
          subPath: nginx.conf
        - mountPath: /usr/share/nginx/html
          name: nfs   #/usr/share/nginx/html 挂载到volumes中server+path
      volumes:
      - name: photo-conf
        configMap:
          name: photo-conf
      - name: nfs
        nfs:
          server: "172.31.0.110"    #挂载的IP地址
          path: "/home/rke/nginx/html" #挂载的位置
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: photo-conf
data:
  nginx.conf: |
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        client_max_body_size 50m;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       83;
            server_name  localhost;
            root   /usr/share/nginx/html;
            location / {
               index  index.html index.htm;
            }
            location ~* ^.+.(js|ico|gif|jpg|jpeg|png|html|htm)$ {
               log_not_found off;
               access_log off;
               expires 7d;
            }
        }
    }
---
apiVersion: v1
kind: Service
metadata:
  name: photo-nginx
  labels:
    name: photo-nginx
spec:
  type: NodePort
  ports:
  - port: 83
    targetPort: 83
    nodePort: 83
  selector:
    app: photo-nginx

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/962200.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号