参考:

简介

  • 转发不同的域名请求到集群中不同的服务上
  • Ingress 就是从 Kubernetes 集群外访问集群的入口,将用户的URL请求转发到不同的 Service 上。

安装

  1. helm install --namespace kube-system --name nginx-ingress \
  2. --set rbac.create=true \
  3. --set controller.hostNetwork=true \
  4. --set controller.dnsPolicy=ClusterFirstWithHostNet \
  5. --set controller.kind=DaemonSet \
  6. --set controller.stats.enabled=true \
  7. --set controller.metrics.enabled=true \
  8. stable/nginx-ingress

helm 安装

  • hostNetwork方式
  1. helm install --namespace kube-system --name nginx-ingress \
  2. --set rbac.create=true \
  3. --set controller.hostNetwork=true \
  4. --set controller.dnsPolicy=ClusterFirstWithHostNet \
  5. --set controller.kind=DaemonSet \
  6. --set controller.stats.enabled=true \
  7. --set controller.metrics.enabled=true \
  8. stable/nginx-ingress
  • externalIPs方式
    1. helm install --name nginx-ingress --set "rbac.create=true,controller.service.externalIPs[0]=10.141.179.103" stable/nginx-ingress

安装Ingress Controller

  1. kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
  1. kubectl edit pod nginx-ingress-controller-7995bd9c47-6g8xd -n ingress-nginx

使用Ingress

创建测试服务

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: myapp-ding
  5. namespace: default
  6. spec:
  7. selector:
  8. app: myapp
  9. release: ding
  10. ports:
  11. - name: http
  12. port: 80
  13. targetPort: 80
  14. ---
  15. apiVersion: apps/v1
  16. kind: Deployment
  17. metadata:
  18. name: myapp-ding
  19. namespace: default
  20. spec:
  21. replicas: 3
  22. selector:
  23. matchLabels:
  24. app: myapp
  25. release: ding
  26. template:
  27. metadata:
  28. labels:
  29. app: myapp
  30. release: ding
  31. spec:
  32. containers:
  33. - name: myapp-ding
  34. image: ikubernetes/myapp:v2
  35. ports:
  36. - name: http
  37. containerPort: 80

创建Ingress规则

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: ingress-ding
  5. namespace: default
  6. annotations:
  7. kubernetes.io/ingress.class: "nginx"
  8. spec:
  9. rules:
  10. - host: socsight.com
  11. http:
  12. paths:
  13. - path: /
  14. backend:
  15. serviceName: web-mindoc
  16. servicePort: 80
文档更新时间: 2020-06-10 11:10   作者:admin