configmap的创建 命令创建configmap [root@k8s-master1 configmap]# kubectl create configmap nginx-config --from-literal =nginx_port=80 --from-literal=server_name=myapp.magedu.com configmap/nginx-config created [root@k8s-master1 configmap]# kubectl get cm NAME DATA AGE nginx-config 2 8s [root@k8s-master1 configmap ]# kubectl describe cm nginx-config Name: nginx-config Namespace: default Labels: <none configmap/nginx-config edited [root@k8s-master1 configmap]# kubectl exec -it pod-cm-1 -- /bin/sh / #
用前面的两个文件生成 Configmap 供容器引用: kubectl create configmap nginx-config \ --from-file=proxy.conf --from-file name: nginx volumeMounts: - mountPath: /etc/nginx/conf.d name: nginx-config - name: nginx-config configMap: name: nginx-config 因为端口发生了变化,所以还需要修改 Service
您可以通过创建一个YAML文件来做到这一点,我们称之为 nginx-config.yaml,其中包含以下内容: apiVersion: v1 kind: ConfigMap metadata: name: nginx-config latest ports: - containerPort: 80 volumeMounts: - name: nginx-config configMap: name: nginx-config 在此示例中,我们将创建一个名为 nginx-deployment 的部署,其中包含一个副本。 修改 nginx.conf 部分,如下所示: apiVersion: v1 kind: ConfigMap metadata: name: nginx-config data: nginx.conf configMap: name: nginx-config 在此示例中,我们添加了一个名为 SERVER_NAME 的环境变量,并使用 fieldRef
我们将创建一个名为“nginx-config”的持久卷,并将其挂载为“/etc/nginx/conf.d”目录。最后,我们将HostPath卷类型设置为“/var/lib/my-data”。 Podmetadata: name: nginx-podspec: containers: - name: nginx image: nginx volumeMounts: - name: nginx-config mountPath: /etc/nginx/conf.d volumes: - name: nginx-config hostPath: path: /var/lib/my-data 我们还将该目录设置为持久卷“nginx-config”的路径。容器将此持久卷挂载为“/etc/nginx/conf.d”目录。这使得容器可以读取和写入宿主机上的文件。
from-literal=nginx_port=80 --from-literal=server_name=youmen kubectl get cm NAME DATA AGE nginx-config 2 8s kubectl describe cm nginx-config Name: nginx-config Namespace: default Labels /www.conf kubectl get cm NAME DATA AGE nginx-config 2 3m13s nginx-www 1 80 env: - name: NGINX_SERVER_PORT valueFrom: configMapKeyRef: name: nginx-config nginx_port - name: NGINX_SERVER_NAME valueFrom: configMapKeyRef: name: nginx-config
/nginx-config/nginx.conf:/etc/nginx/nginx.conf - . /nginx-config/conf.d:/etc/nginx/conf.d - . /nginx-config/snippets:/etc/nginx/snippets - /etc/nginx/ssl:/ssl - . /nginx-config/nginx.conf:/etc/nginx/nginx.conf - . /nginx-config/conf.d:/etc/nginx/conf.d - .
首先我们创建正常的一个nginx资源,资源清单如下: apiVersion: v1 kind: ConfigMap metadata: name: nginx-config data: default.conf my-app image: nginx imagePullPolicy: IfNotPresent volumeMounts: - name: nginx-config mountPath: /etc/nginx/conf.d volumes: - name: nginx-config configMap: name: nginx-config 然后创建资源对象。 configMap: name: nginx-config 手动修改configmap后,reloader监测到configmap变化,会主动向nginx主进程发起
Service 将 nginx 容器的 80 端口暴露出来---kind: ConfigMap # 对象类型apiVersion: v1 # api 版本metadata: # 元数据 name: nginx-config etc/nginx/nginx.conf # 挂载配置了 nginx.conf 的 volume subPath: nginx.conf name: nginx-config # 网站文件通过nfs挂载 nfs: path: /html/ server: 192.168.1.123 - name: nginx-config configMap: # configMap name: nginx-config部署网站# 下载网站代码wget https://typecho.org/
http://127.0.0.1:12080; } } } 2.使用文件创建configmap [root@master01 cm]# kubectl create cm nginx-config \ --from-file=nginx.conf configmap/nginx-config created 3.pod使用configmap apiVersion: v1 kind: Pod metadata subPath: nginx.conf volumes: - name: nginx-config-volume configMap: name: nginx-config
supervisord.conf start Supervisord CMD ["/usr/bin/supervisord"] config Nginx like config Supervisord vim nginx-config debconf-set-selections RUN apt-get install -yqq mysql-server mysql-client EXPOSE 80 22 COPY nginx-config /var/www/wordpress/wp-config.php CMD ["/usr/bin/supervisord"] make sure you have Dockerfile nginx-config
[root@master kubelet]# kubectl get configmap -n nginx-ingress NAME DATA AGE nginx-config 1 2d2h [root@master kubelet]# kubectl edit configmap nginx-config -n nginx-ingress # Please edit data":{"server-names-hash-bucket-size":"1024"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"nginx-config ","namespace":"nginx-ingress"}} creationTimestamp: "2019-10-30T08:48:50Z" name: nginx-config namespace : nginx-ingress resourceVersion: "2986" selfLink: /api/v1/namespaces/nginx-ingress/configmaps/nginx-config
添加配置文件nginx-config.yaml用于创建ConfigMap,ConfigMap名称为nginx-config,配置信息存放在data节点下: apiVersion: v1 kind: ConfigMap metadata: name: nginx-config namespace: default data: nginx-env: test 应用nginx-config.yaml文件创建 获取所有ConfigMap: kubectl get configmap NAME DATA AGE kube-root-ca.crt 1 2d22h nginx-config 1 13s 通过yaml格式查看ConfigMap中的内容: kubectl get configmaps nginx-config -o yaml apiVersion: nginx-env: {} manager: kubectl-create operation: Update time: "2021-01-08T01:49:44Z" name: nginx-config
假设这是Nginx配置文件的位置 volumes: - name: nginx-conf-volume configMap: name: nginx-config 而触发Pod更新 Normal Reloaded 87s (x2 over 2m57s) reloader-configMaps Changes detected in 'nginx-config
nextcloud 目录 $ mkdir -p /data/nextcloud $ cd /data/nextcloud # 创建数据存储目录 $ mkdir db nextcloud-data nginx-config redis-data # 创建 nextcloud nginx 配置 $ vim nginx-config/default.conf upstream php-handler { server image: nginx:1.19.2 restart: always ports: - 8088:80 volumes: - /data/nextcloud/nginx-config
containers: - name: nginx image: nginx:alpine volumeMounts: - name: nginx-config mountPath: /etc/nginx/nginx.conf subPath: nginx.conf volumes: - name: nginx-config
repostitory or download it as a zip then move its content to /etc/nginx/ (or wherever you store your nginx-config ) 克隆这个仓库或者下载一个zip文件,然后把它的内容移动到/etc/nginx/(或者你保存nginx-config的地方) read through the 通读 sites-available/matomo.conf
现在访问 http://localhost:82 就可以看到 nginx 页面了: 我们要修改下配置文件,把它复制出来: docker cp gray1:/etc/nginx/conf.d ~/nginx-config 指定数据卷,挂载本地的 ~/nginx-config 目录到容器内的 /etc/nginx/conf.d 目录。 点击 run。
来忽略某个资源 部署成功后,就可以直接使用了,我提前部署了nginx和configmap 这是目前的配置,看一下Nginx目前的配置 接着,我修改Nginx的Deployment,添加reloader,监听nginx-config revision": "9", "description": "nginx应用" # 主要是这行 "reloader.stakater.com/reload": "nginx-config
containerPort: 80 name: nginx protocol: TCP volumeMounts: - name: nginx-config mountPath: /etc/nginx/nginx.conf subPath: nginx.conf volumes: - name: nginx-config
: athena readOnly: false - mountPath: /etc/nginx/nginx.conf name: nginx-config volumes: - name: athena hostPath: path: "/data/athena/" - name: nginx-config