Nginx
April 7, 2023
Nginx. Ingress без сертификатов.
Примеры работы Nginx ingress под ключ.
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx && \ helm repo update && \ helm install ingress-nginx ingress-nginx/ingress-nginx
Deployment+Service, которые являются бекендом у ingress
cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: app1-deploy labels: app: app1 spec: replicas: 1 selector: matchLabels: app: app1 template: metadata: labels: app: app1 spec: containers: - name: app1 image: nginx:latest ports: - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: app2-deploy labels: app: app2 spec: replicas: 1 selector: matchLabels: app: app2 template: metadata: labels: app: app2 spec: containers: - name: app2 image: nginx:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: app1 spec: selector: app: app1 ports: - port: 80 name: http targetPort: 80 --- apiVersion: v1 kind: Service metadata: name: app2 spec: selector: app: app2 ports: - port: 80 name: http targetPort: 80 EOF
Простой ingress без TLS сертификата.
cat <<EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: mac.cameda.ga http: paths: - path: / pathType: Prefix backend: service: name: app1 port: number: 80 EOF
cat <<EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: mac.infra.cameda.ga http: paths: - path: / pathType: Prefix backend: service: name: app port: number: 80 EOF
# Данная конфигурация ingress используется для двух доменов, работающих # по принципу двух server. cat <<EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: cat.infra.cameda.ga http: paths: - path: / pathType: Prefix backend: service: name: app1 port: number: 80 - host: dog.infra.cameda.ga http: paths: - path: / pathType: Prefix backend: service: name: app2 port: number: 80 EOF
Ingress без TLS сертификата и с несколькими бакендами.
# Данная конфигурация ingress используется для двух доменов, работающих # по принципу двух листенеров в одном блоке server. cat <<EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cameda-ingress annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - host: mac.infra.cameda.ga http: paths: - path: /app1 pathType: Prefix backend: service: name: app1 port: number: 80 - path: /app2 pathType: Prefix backend: service: name: app2 port: number: 80 EOF
# Данная конфигурация ingress используется для одного бекенда. cat <<EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: cameda.tk http: paths: - path: / pathType: Prefix backend: service: name: app port: number: 80 EOF