Helm 3安装Nginx Ingress Controller


安装

先添加Chart仓库。

helm repo add nginx-stable https://helm.nginx.com/stable

helm repo update

查找nginx-ingress,我们选择nginx-stable/nginx-ingress Chart。

helm search repo nginx-ingress

NAME                            CHART VERSION   APP VERSION     DESCRIPTION

nginx-stable/nginx-ingress      0.7.0           1.9.0           NGINX Ingress Controller

stable/nginx-ingress            1.41.3          v0.34.1         DEPRECATED! An nginx Ingress controller that us...

stable/nginx-lego               0.3.1                           Chart for nginx-ingress-controller

展示values.yaml文件,分析helm安装Nginx Ingress的命令行覆盖参数。

helm show values nginx-stable/nginx-ingress

由于Nginx Ingress的service缺省采用"type: LoadBalancer",为了外部访问,修改为"type: NodePort",顺便设置固定的nodePort。

helm install nginx-ingress nginx-stable/nginx-ingress \  --set controller.service.type=NodePort \  --set controller.service.httpPort.nodePort=80 \  --set controller.service.httpsPort.nodePort=443

-n ingress-controller  

kc get svc -n ingress-controller  

NAME            TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE

ingress-nginx   NodePort   192.168.96.148   <none>        80:30080/TCP,443:30443/TCP   188d

使用

先创建1个集群服务

vi echo-service.yaml

--- apiVersion: v1 kind: Service metadata:  labels:    app: echo  name: echo spec:  ports:  - name: http    port: 8080    protocol: TCP    targetPort: 8080  selector:    app: echo --- apiVersion: apps/v1 kind: Deployment metadata:  labels:    app: echo  name: echo spec:  replicas: 1  selector:    matchLabels:      app: echo  strategy: {}  template:    metadata:      creationTimestamp: null      labels:        app: echo    spec:      containers:      - image: e2eteam/echoserver:2.2        name: echo        ports:        - containerPort: 8080        env:          - name: NODE_NAME            valueFrom:              fieldRef:                fieldPath: spec.nodeName          - name: POD_NAME            valueFrom:              fieldRef:                fieldPath: metadata.name          - name: POD_NAMESPACE            valueFrom:              fieldRef:                fieldPath: metadata.namespace          - name: POD_IP            valueFrom:              fieldRef:                fieldPath: status.podIP        resources: {}

kubectl apply -f echo-service.yaml

vi echo-ingress.yaml

apiVersion: extensions/v1beta1 kind: Ingress metadata:  name: echo-ingress  namespace: default  annotations:    kubernetes.io/ingress.class: nginx spec:  rules:  - host: echo.com    http:      paths:      - path: /        backend:          serviceName: echo          servicePort: 8080

kubectl apply -f echo-ingress.yaml

通过代理访问echo服务

curl -i -H "Host: echo.com" http://192.168.1.55:30080/ HTTP/1.1 200 OK Server: nginx/1.17.9 Date: Fri, 27 Mar 2020 11:13:40 GMT Content-Type: text/plain Transfer-Encoding: chunked Connection: keep-alive     Hostname: echo-75cf96d976-bdh6l Pod Information:        node name:      k8s-node1        pod name:       echo-75cf96d976-bdh6l        pod namespace:  default        pod IP: 10.244.1.3 Server values:        server_version=nginx: 1.14.2 - lua: 10015 Request Information:        client_address=10.244.2.4        method=GET        real path=/        query=        request_version=1.1        request_scheme=http        request_uri=http://echo.com:8080/ Request Headers:        accept=*/*        connection=close        host=echo.com        user-agent=curl/7.29.0        x-forwarded-for=10.244.0.0        x-forwarded-host=echo.com        x-forwarded-port=80        x-forwarded-proto=http        x-real-ip=10.244.0.0 Request Body:        -no body in request-


https://www.shengchulai.com/blog-P5EsLgAoxj.htm

发表评论