k8s configmap 创建与使用
创建configmap
cat /root/k8s/nmp/conf/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;111111
#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 php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$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;
#}
}
kubectl create configmap default-conf -n ns-nginx --from-file=/root/k8s/nmp/conf/default.conf
nginx-deploy.yaml
[root@centos-7]# more nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-php
namespace: ns-nginx
spec:
selector:
matchLabels:
app: nginx-php
replicas: 1
template:
metadata:
labels:
app: nginx-php
spec:
containers:
- name: nginx-php
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: default-conf
mountPath: /etc/nginx/conf.d/
- name: nginx-data
mountPath: /usr/share/nginx/html
volumes:
- name: default-conf
configMap:
name: default-conf
items:
- key: default.conf
path: default.conf
- name: nginx-data
hostPath:
path: /root/k8s/nmp/html
nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-php
namespace: ns-nginx
spec:
type: NodePort
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
nodePort: 30003
selector:
app: nginx-php