参考:

简介

  • 转发不同的域名请求到集群中不同的服务上
  • 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
  9. ```s
  10. #### helm 安装
  11. + hostNetwork方式

helm install —namespace kube-system —name nginx-ingress \
—set rbac.create=true \
—set controller.hostNetwork=true \
—set controller.dnsPolicy=ClusterFirstWithHostNet \
—set controller.kind=DaemonSet \
—set controller.stats.enabled=true \
—set controller.metrics.enabled=true \
stable/nginx-ingress

  1. + externalIPs方式

helm install —name nginx-ingress —set “rbac.create=true,controller.service.externalIPs[0]=10.141.179.103” stable/nginx-ingress

  1. #### 安装Ingress Controller

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

kubectl edit pod nginx-ingress-controller-7995bd9c47-6g8xd -n ingress-nginx

  1. ## 使用Ingress
  2. #### 创建测试服务

apiVersion: v1
kind: Service
metadata:
name: myapp-ding
namespace: default
spec:
selector:
app: myapp
release: ding
ports:

  1. - name: http
  2. port: 80
  3. targetPort: 80

apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-ding
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: myapp
release: ding
template:
metadata:
labels:
app: myapp
release: ding
spec:
containers:

  1. - name: myapp-ding
  2. image: ikubernetes/myapp:v2
  3. ports:
  4. - name: http
  5. containerPort: 80
  1. #### 创建Ingress规则

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-ding
namespace: default
annotations:
kubernetes.io/ingress.class: “nginx”
spec:
rules:

  • host: socsight.com
    http:
    paths:
    • path: /
      backend:
      serviceName: web-mindoc
      servicePort: 80
      ```
文档更新时间: 2019-08-26 03:50   作者:admin