mirror of https://github.com/istio/istio.io.git
[zh] sync /ingress/kubernetes-ingress/index.md (#12266)
* [zh] sync /ingress/kubernetes-ingress/index.md * updated by zirain's comments
This commit is contained in:
parent
26d657961c
commit
0fd366cab7
|
|
@ -7,10 +7,10 @@ owner: istio/wg-networking-maintainers
|
||||||
test: yes
|
test: yes
|
||||||
---
|
---
|
||||||
|
|
||||||
此任务描述如何使用 [Ingress 资源](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)为 Istio 配置入口网关以暴露网格内的服务。
|
此任务描述如何使用 [Kubernetes Ingress](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/) 为 Istio 配置入口网关以暴露服务网格集群内的服务。
|
||||||
|
|
||||||
{{< tip >}}
|
{{< tip >}}
|
||||||
建议使用 [Istio Gateway](/zh/docs/tasks/traffic-management/ingress/ingress-control/) 而不是 Ingress 来利用 Istio 提供的完整功能集,例如丰富的流量管理和安全功能。
|
建议使用 [Gateway](/zh/docs/tasks/traffic-management/ingress/ingress-control/) 而不是 Ingress 来利用 Istio 提供的完整功能集,例如丰富的流量管理和安全功能。
|
||||||
{{< /tip >}}
|
{{< /tip >}}
|
||||||
|
|
||||||
## 准备工作{#before-you-begin}
|
## 准备工作{#before-you-begin}
|
||||||
|
|
@ -19,15 +19,15 @@ test: yes
|
||||||
|
|
||||||
## 使用 Ingress 资源配置入口网关 {#configuring-ingress-using-an-ingress-resource}
|
## 使用 Ingress 资源配置入口网关 {#configuring-ingress-using-an-ingress-resource}
|
||||||
|
|
||||||
[Kubernetes Ingress 资源](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)公开了从集群外到集群内服务的 HTTP 和 HTTPS 路由。
|
[Kubernetes Ingress](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/) 公开了从集群外到集群内服务的 HTTP 和 HTTPS 路由。
|
||||||
|
|
||||||
让我们看看如何在端口 80 上配置 `Ingress` 以实现 HTTP 流量。
|
让我们看看如何在端口 80 上配置 `Ingress` 以实现 HTTP 流量。
|
||||||
|
|
||||||
1. 创建一个 `Ingress` 资源:
|
1. 创建一个 `Ingress` 资源:
|
||||||
|
|
||||||
{{< text bash >}}
|
{{< text bash >}}
|
||||||
$ kubectl apply -f - <<EOF
|
$ kubectl apply -f - <<EOF
|
||||||
apiVersion: networking.k8s.io/v1beta1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
|
|
@ -38,16 +38,19 @@ test: yes
|
||||||
- host: httpbin.example.com
|
- host: httpbin.example.com
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- path: /status/*
|
- path: /status
|
||||||
|
pathType: Prefix
|
||||||
backend:
|
backend:
|
||||||
serviceName: httpbin
|
service:
|
||||||
servicePort: 8000
|
name: httpbin
|
||||||
|
port:
|
||||||
|
number: 8000
|
||||||
EOF
|
EOF
|
||||||
{{< /text >}}
|
{{< /text >}}
|
||||||
|
|
||||||
需要使用 `kubernetes.io/ingress.class` 注解来告知 Istio 网关控制器它应该处理此 `Ingress`,否则它将被忽略。
|
需要使用 `kubernetes.io/ingress.class` 注解来告知 Istio 网关控制器它应该处理此 `Ingress`,否则它将被忽略。
|
||||||
|
|
||||||
1. 使用 _curl_ 访问 _httpbin_ 服务:
|
1. 使用 _curl_ 访问 _httpbin_ 服务:
|
||||||
|
|
||||||
{{< text bash >}}
|
{{< text bash >}}
|
||||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/status/200"
|
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/status/200"
|
||||||
|
|
@ -58,7 +61,7 @@ test: yes
|
||||||
|
|
||||||
注意,您需要使用 `-H` 标志将 _Host_ 的 HTTP header 设置为 "httpbin.example.com",因为 `Ingress` 中已经配置为处理访问 "httpbin.example.com" 的请求,但是在测试环境中,该 host 并没有相应的 DNS 绑定。
|
注意,您需要使用 `-H` 标志将 _Host_ 的 HTTP header 设置为 "httpbin.example.com",因为 `Ingress` 中已经配置为处理访问 "httpbin.example.com" 的请求,但是在测试环境中,该 host 并没有相应的 DNS 绑定。
|
||||||
|
|
||||||
1. 访问未显式公开的其他 URL 时,将返回 HTTP 404 错误:
|
1. 访问未显式公开的其他 URL 时,将返回 HTTP 404 错误:
|
||||||
|
|
||||||
{{< text bash >}}
|
{{< text bash >}}
|
||||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
|
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
|
||||||
|
|
@ -70,7 +73,7 @@ test: yes
|
||||||
|
|
||||||
### TLS {#TLS}
|
### TLS {#TLS}
|
||||||
|
|
||||||
`Ingress` 支持[TLS](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/#tls)设置。 Istio 支持此功能,但是引用的 `Secret` 必须存在于`istio-ingressgateway` 部署的名称空间(通常是 `istio-system` )中。 [cert-manager](/zh/docs/ops/integrations/certmanager/)可用于生成这些证书。
|
`Ingress` 支持[指定 TLS 设置](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/#tls)。Istio 支持此功能,但是引用的 `Secret` 必须存在于 `istio-ingressgateway` 部署的命名空间(通常是 `istio-system`)中。[cert-manager](/zh/docs/ops/integrations/certmanager/) 可用于生成这些证书。
|
||||||
|
|
||||||
### 指定路径类型{#specifying-path-type}
|
### 指定路径类型{#specifying-path-type}
|
||||||
|
|
||||||
|
|
@ -83,14 +86,14 @@ Istio 默认路径类型为精确匹配,除非路径以 `/*` 或 `.*` 结尾
|
||||||
在 Kubernetes 1.18 中,添加了新资源 `IngressClass`,以替换 Ingress 资源上的 `kubernetes.io/ingress.class` 注解。如果使用此资源,则需要将 `controller` 字段设置为 `istio.io/ingress-controller`。例如:
|
在 Kubernetes 1.18 中,添加了新资源 `IngressClass`,以替换 Ingress 资源上的 `kubernetes.io/ingress.class` 注解。如果使用此资源,则需要将 `controller` 字段设置为 `istio.io/ingress-controller`。例如:
|
||||||
|
|
||||||
{{< text yaml >}}
|
{{< text yaml >}}
|
||||||
apiVersion: networking.k8s.io/v1beta1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: IngressClass
|
kind: IngressClass
|
||||||
metadata:
|
metadata:
|
||||||
name: istio
|
name: istio
|
||||||
spec:
|
spec:
|
||||||
controller: istio.io/ingress-controller
|
controller: istio.io/ingress-controller
|
||||||
---
|
---
|
||||||
apiVersion: networking.k8s.io/v1beta1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: ingress
|
name: ingress
|
||||||
|
|
@ -103,8 +106,10 @@ spec:
|
||||||
- path: /
|
- path: /
|
||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
backend:
|
backend:
|
||||||
serviceName: httpbin
|
service:
|
||||||
servicePort: 8000
|
name: httpbin
|
||||||
|
port:
|
||||||
|
number: 8000
|
||||||
{{< /text >}}
|
{{< /text >}}
|
||||||
|
|
||||||
## 清除{#cleanup}
|
## 清除{#cleanup}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue