Skip to content

Instantly share code, notes, and snippets.

@xialeistudio
Created April 24, 2023 11:24
Show Gist options
  • Save xialeistudio/27b759cd564cbfff94f650aa4b5e689c to your computer and use it in GitHub Desktop.
Save xialeistudio/27b759cd564cbfff94f650aa4b5e689c to your computer and use it in GitHub Desktop.
Deployment an ingress controller

Deloyment a nginx ingress

Step

  1. Create configmap to store nginx.conf, which modified the events config
  2. Apply nginx-deployment.yaml to deploy nginx pods
  3. Apply nginx-service.yaml to deploy nginx services
  4. Execute kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.0/deploy/static/provider/cloud/deploy.yaml to deploy a nginx ingress controller, once deployed, you can access http://localhost through browser. Because there is no ingress, so any request will get a 404 Not Found
  5. Apply nginx-ingress.yaml to deploy ingress rul
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
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
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
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