当前位置:网站首页>Kubernetes basic self-study series | introduction to ingress API

Kubernetes basic self-study series | introduction to ingress API

2022-06-27 16:37:00 51CTO

Video source :B standing 《2021 At the end of the year, strive to build Kubernetes Introduction to mastery - 2022 Happy appetizer of the year

Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !


Information

Ingress-Nginx github Address :
​​ ​https://github.com/kubernetes/ingress-nginx​

Ingress-Nginx Official website :
​​ ​https://kubernetes.github.io/ingress-nginx/​

Kubernetes Basic self-study series | Ingress API Explain _githubKubernetes Basic self-study series | Ingress API Explain _ Redirect _02

Deploy Ingress-Nginx

      
      
$ kubectl apply -f mandatory.yaml
$ kubectl apply -f service-nodeport.yaml
  • 1.
  • 2.

Ingress HTTP Agent access

deployment、Service、Ingress Yaml file

      
      
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-dm
spec:
replicas: 2
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: wangyanglinux/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
name: nginx
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-test
spec:
rules:
- host: www1.hongfu.com
http:
paths:
- path: /
backend:
serviceName: nginx-svc
servicePort: 80
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.

Ingress HTTPS Agent access

Create certificate , as well as cert storage

      
      
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=nginxsvc/O=nginxsvc"
kubectl create secret tls tls-secret --key tls.key --cert tls.crt
  • 1.
  • 2.

deployment、Service、Ingress Yaml file

      
      
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-test
spec:
tls:
- hosts:
- ssl.hongfu.com
secretName: tls-secret
rules:
- host: ssl.hongfu.com
http:
paths:
- path: /
backend:
serviceName: nginx-svc
servicePort: 80
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

Nginx Conduct BasicAuth

      
      
yum -y install httpd
htpasswd -c auth foo
kubectl create secret generic basic-auth --from-file=auth
  • 1.
  • 2.
  • 3.
      
      
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: auth.hongfu.com
annotations:
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: basic-auth
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - foo'
spec:
rules:
- host: auth.hongfu.com
http:
paths:
- path: /
backend:
serviceName: nginx-svc
servicePort: 80
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

Nginx Rewrite

name

describe

value

nginx.ingress.kubernetes.io/rewrite-target

The destination of the traffic must be redirected URI

strand

nginx.ingress.kubernetes.io/ssl-redirect

Indicates whether the location section is accessible only SSL( When Ingress When the certificate is included, it defaults to True)

Boolean

nginx.ingress.kubernetes.io/force-ssl-redirect

Even if Ingress not enabled TLS, Also force redirection to HTTPS

Boolean

nginx.ingress.kubernetes.io/app-root

Definition Controller Application root that must be redirected , If it's in '/' In the context of

strand

nginx.ingress.kubernetes.io/use-regex

instructions Ingress Whether the path defined on uses a regular expression

Boolean

      
      
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rew.hongfu.com
annotations:
nginx.ingress.kubernetes.io/rewrite-target: https://www.baidu.com
spec:
rules:
- host: rew.hongfu.com
http:
paths:
- path: /
backend:
serviceName: nginx-svc
servicePort: 80
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206271523396423.html