k8s用congfigMap文件搭建nginx详细教程 8月28号实验

k8s用congfigMap文件搭建nginx

创建configmap文件替换nginx的nginx.conf文件

废话不多说,上代码
首先是deployment文件:
PS:经过几天的学习呢,我现在已经可以默写yaml文件了

deploy文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: default
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 3
  template:
    metadata:
      name: nginx-tem
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: IfNotPresent
        name: nginx-pod
        volumeMounts:
          - name: nginx-configmap
            mountPath: /etc/nginx/nginx.conf
            subPath: nginx.conf
        ports:
        - containerPort: 80
          name: nginx-port
      volumes:
        - name: nginx-configmap
          configMap:
            name: nginx-configmap
            items:
            - key: nginx.conf
              path: nginx.conf

configmap文件

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-configmap
data:
  nginx.conf: |
    user  nginx;
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

测试

我们更改一下configmap文件,进入pod看一下是否同步修改了

kubectl edit cm nginx-configmap
  configmap/nginx-configmap edited

通过命令呢,我们把进程数改为4
注意:POD需要重启,否则需要等待同步一会,为了方便我们这里直接重启啦
在这里插入图片描述
我们重启一下pod(自己家里的虚拟机,没多少应用hh)
在这里插入图片描述
通过命令进入容器

kubectl exec -it nginx-768cc7f8f6-cknnj  -- /bin/bash

在这里插入图片描述
可以看到我们的进程数已经变成了我们修改的4,代表我们试验成功

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈小c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值