- Create configmap to store
nginx.conf, which modified theeventsconfig - Apply
nginx-deployment.yamlto deploy nginx pods - Apply
nginx-service.yamlto deploy nginx services - Execute
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.0/deploy/static/provider/cloud/deploy.yamlto deploy a nginx ingress controller, once deployed, you can access http://localhost through browser. Because there is no ingress, so any request will get a404 Not Found - Apply
nginx-ingress.yamlto deploy ingress rul
Created
April 24, 2023 11:24
-
-
Save xialeistudio/27b759cd564cbfff94f650aa4b5e689c to your computer and use it in GitHub Desktop.
Deployment an ingress controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: nginx-deployment | |
| spec: | |
| selector: | |
| matchLabels: | |
| app: nginx | |
| replicas: 4 # tells deployment to run 2 pods matching the template | |
| template: | |
| metadata: | |
| labels: | |
| app: nginx | |
| spec: | |
| containers: | |
| - name: nginx | |
| image: nginx:1.14.2 | |
| volumeMounts: | |
| - name: nginx-conf | |
| mountPath: /etc/nginx/nginx.conf # 挂载路径 | |
| subPath: nginx.conf # configmap的文件名 | |
| ports: | |
| - containerPort: 80 | |
| volumes: | |
| - name: nginx-conf | |
| configMap: | |
| name: nginx-config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: networking.k8s.io/v1 | |
| kind: Ingress | |
| metadata: | |
| name: nginx-ingress | |
| annotations: | |
| nginx.ingress.kubernetes.io/rewrite-target: / | |
| kubernetes.io/ingress.class: "nginx" | |
| spec: | |
| rules: | |
| - http: | |
| paths: | |
| - path: /nginx | |
| pathType: Prefix | |
| backend: | |
| service: | |
| name: nginx | |
| port: | |
| number: 80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: nginx | |
| labels: | |
| app: nginx | |
| spec: | |
| selector: | |
| app: nginx | |
| ports: | |
| - protocol: TCP | |
| port: 80 | |
| targetPort: 80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user nginx; | |
| worker_processes auto; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| events { | |
| worker_connections 65535; | |
| use epoll; | |
| mutil_accept on; | |
| } | |
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment