k8s中configmap挂载配置nginx.conf

2023-05-16

ConfigMap

ConfigMap作用是存储不加密的数据到etcd中,让Pod以变量或数据卷Volume挂载到容器中

应用场景:配置文件

创建配置文件

首先我们需要创建一个配置文件 nginx.conf

user  nginx;
        worker_processes  auto;
        worker_cpu_affinity 00000001 00000010 00000100 00001000;

        error_log  /var/log/nginx/error.log warn;
        pid        /var/run/nginx.pid;


        worker_rlimit_nofile 65536;

        events {
                worker_connections  65535;
                accept_mutex on;
                multi_accept on;
        }


        http {
                include       mime.types;
                default_type  application/octet-stream;
                log_format access_json '{"@timestamp":"$time_iso8601",'
                '"host":"$server_addr",'
                '"clientip":"$remote_addr",'
                '"size":$body_bytes_sent,'
                '"responsetime":$request_time,'
                '"upstreamtime":"$upstream_response_time",'
                '"upstreamhost":"$upstream_addr",'
                '"http_host":"$host",'
                '"url":"$uri",'
                '"domain":"$host",'
                '"xff":"$http_x_forwarded_for",'
                '"referer":"$http_referer",'
                '"status":"$status"}';
                access_log  /var/log/nginx/access.log  access_json;

                client_max_body_size 50M;
                keepalive_timeout  300;
                fastcgi_buffers 8 128k;
                fastcgi_buffer_size  128k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                proxy_connect_timeout 90;
                proxy_read_timeout 300;
                proxy_send_timeout 300;
                sendfile        on;

                server {
                        listen       80;
                        server_name  localhost;
                        add_header Cache-Control no-cache;

                        location / {
                                root   /usr/share/nginx/html;
                                        #proxy_read_timeout 220s
                                index  index.html index.htm;
                        }


                        error_page   500 502 503 504  /50x.html;
                        location = /50x.html {
                                root   html;
                        }
                }

                include /etc/nginx/conf.d/*.conf;

                }

命令创建ConfigMap

kubectl create configmap nginx1-config --from-file=nginx.conf

然后查看详细信息

kubectl describe cm nginx1-config

yaml方式创建ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
    name: nginx1-config
data:
  nginx.conf: |
        user  nginx;
        worker_processes  auto;
        worker_cpu_affinity 00000001 00000010 00000100 00001000;

        error_log  /var/log/nginx/error.log warn;
        pid        /var/run/nginx.pid;


        worker_rlimit_nofile 65536;

        events {
                worker_connections  65535;
                accept_mutex on;
                multi_accept on;
        }


        http {
                include       mime.types;
                default_type  application/octet-stream;
                log_format access_json '{"@timestamp":"$time_iso8601",'
                '"host":"$server_addr",'
                '"clientip":"$remote_addr",'
                '"size":$body_bytes_sent,'
                '"responsetime":$request_time,'
                '"upstreamtime":"$upstream_response_time",'
                '"upstreamhost":"$upstream_addr",'
                '"http_host":"$host",'
                '"url":"$uri",'
                '"domain":"$host",'
                '"xff":"$http_x_forwarded_for",'
                '"referer":"$http_referer",'
                '"status":"$status"}';
                access_log  /var/log/nginx/access.log  access_json;

                client_max_body_size 50M;
                keepalive_timeout  300;
                fastcgi_buffers 8 128k;
                fastcgi_buffer_size  128k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                proxy_connect_timeout 90;
                proxy_read_timeout 300;
                proxy_send_timeout 300;
                sendfile        on;

                server {
                        listen       80;
                        server_name  localhost;
                        add_header Cache-Control no-cache;

                        location / {
                                root   /usr/share/nginx/html;
                                        #proxy_read_timeout 220s
                                index  index.html index.htm;
                        }


                        error_page   500 502 503 504  /50x.html;
                        location = /50x.html {
                                root   html;
                        }
                }

                include /etc/nginx/conf.d/*.conf;

                }

Volume数据卷形式挂载

vim cm.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web1-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
        - name: web1
          image: "nginx:latest"
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 80
          volumeMounts:
          - name: nginx1-config
            mountPath: /etc/nginx/nginx.conf
            subPath: nginx.conf

      volumes:
        - name: nginx1-config
          configMap:
            name: nginx1-config
            items:
            - key: nginx.conf
              path: nginx.conf

kubectl apply -f cm.yaml

kubectl get deploy -o wide

进入pod容器查看是否修改

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

k8s中configmap挂载配置nginx.conf 的相关文章

随机推荐

  • 非全日制计算机考研有哪些性价比高的院校呢?

    非全日制计算机考研有哪些性价比高的院校呢 xff1f 附 xff1a 各大高校专业课资料整理可以看一下我的博客主页上传的资源哦 xff01 感谢关注 xff0c 点赞 xff0c 评论 计算机行业的非全日制研究生院校 xff0c 大都包含大
  • C++ vector数组实现多级排序—使用sort()函数

    之前有记录过 python 使用 numpy 的多级排序方法 xff1a numpy 多级排序 xff1a lexsort 函数详解 地球被支点撬走啦的博客 CSDN博客 lexsort C 43 43 多级排序可以借用 sort 函数 x
  • 数学符号及读法大全(超经典)

    数学符号及读法大全 附 xff1a 各大高校专业课资料整理可以看一下我的博客主页上传的资源哦 xff01 感谢关注 xff0c 点赞 xff0c 评论 数学符号及读法大全 常用数学输入符号 xff1a xff1d xff1c xff1e x
  • 【计算机】数据结构-严蔚敏/清华大学(完)

    计算机 数据结构 严蔚敏 清华大学 xff08 完 xff09 需要其他资源的可以在我博客主页找找 xff0c 太多了 xff0c 我懒得整理 数据结构 43 43 C语言版 43 43 第2版严蔚敏 清华大学 pdf 链接 https p
  • 2021 王道考研 数据结构+习题讲解

    2021 王道考研 数据结构 2021王道数据结构高清PDF 链接 https pan baidu com s 1czh6EiRxnTj9uJgc5i12 w 提取码 frnh 复制这段内容后打开百度网盘手机App xff0c 操作更方便哦
  • 2015考研数学复习全书【数一】

    2015考研数学复习全书 数一 链接 https pan baidu com s 1nuXM0fINXRKCYbyy o kSg 提取码 vr45 复制这段内容后打开百度网盘手机App xff0c 操作更方便哦
  • 教你如何零基础备考公务员

    教你如何零基础备考公务员 零基础复习一个月国考上岸 xff0c 笔试120 43 岗位第一 近年题目简单 xff0c 这个分数可能看着不高 xff0c 我考试那年是除了极少数部委进不了面试 xff0c 绝大部分岗位都能进面试的 xff0c
  • 零基础考公务员,备考多长时间最合适?

    零基础考公务员 xff0c 备考多长时间最合适 xff1f 说到考公务员 xff0c 小伙伴们最关心的问题就是 xff0c 到底多长时间才能考上 xff1f 小伙伴们都知道 xff0c 上岸要趁早 xff01 毒姐经常在网上看到一些提问 x
  • stm32上基于FreeRTOS多任务程序运行

    一 FreeRTOS简介二 在stm32开发板上实现多任务程序运行1 任务要求2 编写程序3 编译生成hex文件4 将程序下载到stm32开发板上 一 FreeRTOS简介 FreeRTOS是一个迷你操作系统内核的小型嵌入式系统 作为一个轻
  • C#---winform基础

    一 winform 1 winform应用程序是一种智能客户端技术 xff0c 我们可以使用winform应用程序帮助我们获得信息或者传输信息等 2 属性 Name 在后台要获得前台的控件对象 xff0c 需要使用Name属性 visibl
  • ubuntu20.04安装编译kalibr与出现的问题

    1 安装依赖 ubuntu20与18依赖的内容差别很大 xff0c 在逐个更改和参考 25条消息 Ubuntu20 04安装kalibr 可即的博客 CSDN博客 ubuntu安装kalibr和官网 后终于安装依赖成功了hhh sudo a
  • 100道最新Java面试题,常见面试题及答案汇总

    除了掌握扎实的专业技能之外 xff0c 你还需要一份 Java程序员面试宝典 才能在万千面试者中杀出重围 xff0c 成功拿下offer 小编特意整理了100道Java面试题 xff0c 送给大家 xff0c 希望大家都能顺利通过面试 xf
  • SSH远程连接实例

    目录 0 实例场景 1 Windows10中的SSH环境配置 2 Ubuntu端的SSH配置 3 SSH使用 3 1 在终端命令行中连接 3 2 使用VSCode连接 0 实例场景 本实例是在校园网的环境中 xff0c 使用SSH在个人电脑
  • Windows环境下安装tensorflow(操作简单)

    写在最前 xff1a 本人之前也安装过tensorflow xff0c 但因为好长时间没用 xff0c 最近需要用到 xff0c 结果一打开发现版本太低 xff0c 运行代码时出现了很多语法错误 想要直接更新tensorflow xff0c
  • STM32串口基础通讯函数配置

    外设篇 串口 标准库 在串口屏 xff0c WiFi模块时候经常会用到串口 xff0c 所以串口还是需要了解一下原理 xff0c 才能更好的借鉴别人代码 xff08 doge xff09 初窥门径 当数据发送时候 xff0c 单片机向发送数
  • unable prepare context:unable to evaluate symlinks in Dockerfile path:lstat /XXXXXX

    问题描述 今天在构建镜像文件时 报错 unable prepare context unable to evaluate symlinks in Dockerfile path lstat 根据提示是说 找不到当前我们要构建的 文件 spa
  • STM32基于FreeRTOS的多任务程序

    目录 任务要求FreeRTOS移植介绍应用 任务要求 在STM32下完成一个基于FreeRTOS的多任务程序 xff0c 执行3个周期性task task1 xff0c 每间隔500ms闪烁 xff08 变化 xff09 一次LED xff
  • 如何判断两个ip是否属于同一子网;如何确定子网掩码,让300台服务器处于同一网段

    一 什么是子网掩码 xff1f 在了解ip地址的网段之前 xff0c 我们先来了解子网掩码 xff0c 很多对网络了解不深的朋友都对子网掩码有些迷惑 xff0c 不了解它是用来干什么的 xff1f 子网掩码不能单独存在 xff0c 它必须结
  • 刷leetcode常用的一些库函数

    1 比较两个数大小 xff0c 求出更大的数或者更小的数 Math max a b Math min a b 2 批量化初始数组 当然 xff0c 你遍历一遍一个一个赋值也可以 Arrays fill nums 1 如果是二维数组 xff0
  • k8s中configmap挂载配置nginx.conf

    ConfigMap ConfigMap作用是存储不加密的数据到etcd中 xff0c 让Pod以变量或数据卷Volume挂载到容器中 应用场景 xff1a 配置文件 创建配置文件 首先我们需要创建一个配置文件 nginx conf user