Ingress

Ingress



ingress-nginx

  • 部署ingress-nginx 控制器

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/cloud/deploy.yaml
    

    annotation 中的内容有用,后面需学习

  • 测试tls

    openssl genrsa -out tls.key 2048
    openssl req -x509 -new -key tls.key -out tls.crt -subj /CN="*" -days 3650
    kubectl create secret tls https-test --cert=./tls.crt --key=./tls.key  
    
    cat <<EOF|kubectl -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: test-tls
      labels:
        app: python
    spec:
      containers:
      - name: test-tls
        image: python
        command: ["python","-m","http.server"]
        ports:
        - name: http
          containerPort: 8000
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: test-tls-svc
      labels:
        tier: frond
    spec:
      selector:
        app: python
      ports:
      - name: http
        port: 80
        targetPort: 8000
      type: ClusterIP
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: tls-example-ingress
      annotations:
        kubernetes.io/ingress.class: "nginx"
        ingressClass.kubernetes.io/is-default-class: "true"
        #ingressClassName: "nginx"
        nginx.ingress.kubernetes.io/ssl-redirect: "true"
    spec:
      ingressClassName: nginx
      tls:
      - hosts:
          - test.com
        secretName: https-test
      rules:
      - host: test.com
        http:
          paths:
          - path: /bin
            pathType: Prefix
            backend:
              service:
                name: test-tls-svc
                port: 
                  number: 80
    EOF  
    
  • 在k8s 集群外使用代理访问

    upstream test {
    	 	server 10.4.7.50:31196;  # 10.4.7.50:31196  ingress controller的地址和端口
    		}
    
    	server {
            listen       80;
            location / {
            rewrite ^.*(.*) https://test.com:31196/$1 permanent;
            }
    

Ingress | Kubernetes

ingress-nginx/docs/examples/rewrite/README.md at main · kubernetes/ingress-nginx (github.com)

ingress-nginx/README.md at main · kubernetes/ingress-nginx (github.com)

Installation Guide - Ingress-Nginx Controller (kubernetes.github.io)

posted @ 2021-11-10 21:53  mingtian是吧  阅读(67)  评论(0编辑  收藏  举报