创建一个namespace
1 kind: Namespace 2 apiVersion: v1 3 metadata: 4 name: nginx-test
创建一个configmap
1 apiVersion: v1 2 kind: ConfigMap 3 metadata: 4 name: nginx-config 5 namespace: nginx-test 6 data: 7 default: | 8 server { 9 listen 80; 10 server_name localhost; 11 location / { 12 root /var/www/html; 13 index index.html index.htm index.php; 14 } 15 error_page 500 502 503 504 /50x.html; 16 location = /50x.html { 17 root /var/www/html; 18 } 19 location ~ \.php$ { 20 root /var/www/html; 21 fastcgi_pass 127.0.0.1:9000; 22 fastcgi_index index.php; 23 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 24 include fastcgi_params; 25 } 26 location ~ /\.ht { 27 deny all; 28 } 29 }
构建deployment配置文件
1 apiVersion: apps/v1 2 kind: Deployment 3 metadata:
6 name: nginx-deploy 7 namespace: nginx-test
9 spec:
11 replicas: 1
13 selector: 14 matchLabels: 15 app: nginx-php
21 template: 22 metadata:
26 labels: 27 app: nginx-php 28 spec: 29 containers: 30 - image: 'nginx:1.21.1' 31 imagePullPolicy: IfNotPresent 32 name: nginx-server 33 ports: 34 - containerPort: 80 35 name: http 36 protocol: TCP 37 resources: 38 limits: 39 cpu: 500m 40 memory: 1Gi 41 requests: 42 cpu: 200m 43 memory: 500m
46 volumeMounts: 47 - mountPath: /var/www/html 48 name: php-html 49 - mountPath: /etc/nginx/conf.d 50 name: nginx-config
56 volumes: 57 - hostPath: 58 path: /data/k8s-data/nginx/html 59 type: Directory 60 name: php-html 61 - configMap:63 items: 64 - key: default 65 path: default.conf 66 name: nginx-config 67 name: nginx-config
绑定一个service
1 apiVersion: v1 2 kind: Service 3 metadata: 4 name: nginx-deploy 5 namespace: nginx-test 6 spec: 7 type: NodePort 8 ports: 9 - name: http 10 port: 80 11 protocol: TCP 12 targetPort: 80 13 nodePort: 30080 14 selector: 15 app: nginx-php
标签:index,php,name,示例,nginx,html,k8s,metadata From: https://www.cnblogs.com/jay763190097/p/16929726.html