반응형
개요
Nginx Pod에서 configmap으로 nginx.conf 내용 수정
configmap - 1 링크 : https://dongwook35.tistory.com/64
[ configmap 테스트 ]
configmap으로 설정한 내용으로 pod에 적용하기
nginx deployment 생성
- vi nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
run: nginx
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
run: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: /etc/nginx/nginx.conf # nginx.conf file mount
readOnly: true
name: nginx-conf-cm-vol
subPath: nginx.conf
- mountPath: /etc/nginx/conf.d/default.conf # default.conf file mount
readOnly: true
name: nginx-default-conf-cm-vol
subPath: default.conf
volumes:
- name: nginx-conf-cm-vol
configMap:
name: nginx-conf-cm
items:
- key: nginx-conf
path: nginx.conf
- name: nginx-default-conf-cm-vol
configMap:
name: nginx-default-conf-cm
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
ports:
- port: 80
selector:
run: nginx
configmap 생성
- /etc/nginx/nginx.conf
- vi cm-nginx-conf.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf-cm
data:
nginx-conf: |
# test dw
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
configmap 생성
- /etc/nginx/conf.d/default.conf
- vi cm-default-conf.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-default-conf-cm
data:
default.conf: |
# test dw
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
nginx 배포
kubectl apply -f cm-nginx-conf.yaml
kubectl apply -f cm-default-conf.yaml
kubectl apply -f nginx.yaml
반응형
'인프라 > 시스템 구축' 카테고리의 다른 글
[ istio ] ALB 설정 (Internal,Internet-facing) (0) | 2023.06.29 |
---|---|
[ istio ] Domain Redirect 설정 (0) | 2023.06.29 |
[ EKS ] Nginx-Ingress (0) | 2023.04.18 |
[ istio ] Install (0) | 2023.04.13 |
[ istio ] istio 이란? (0) | 2023.04.13 |