zh-trans website/content/zh/docs/tasks/access-application-cluster/configure-cloud-provider-firewall.md (#11741)
增加了英文注释,同时针对更新的英文文档做了中文补充,修改了部分译文是阅读更加流畅
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
a2919a91a8
commit
db9ea3c03f
+105
-69
@@ -1,33 +1,52 @@
|
||||
---
|
||||
approvers:
|
||||
reviewers:
|
||||
- bprashanth
|
||||
- davidopp
|
||||
title: 配置你的云平台防火墙
|
||||
content_template: templates/task
|
||||
weight: 90
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
许多云服务商(比如 Google Compute Engine)定义防火墙以防止服务无意间暴露到 internet 上。
|
||||
<!--
|
||||
Many cloud providers (e.g. Google Compute Engine) define firewalls that help prevent inadvertent
|
||||
exposure to the internet. When exposing a service to the external world, you may need to open up
|
||||
one or more ports in these firewalls to serve traffic. This document describes this process, as
|
||||
well as any provider specific details that may be necessary.
|
||||
-->
|
||||
许多云服务提供商(比如 谷歌计算引擎)定义防火墙以防止服务无意间暴露到互联网上。
|
||||
当暴露服务给外网时,你可能需要在防火墙上开启一个或者更多的端口来支持服务。
|
||||
本文描述了这个过程,以及其他云服务商的具体信息。
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
<!--
|
||||
## Restrict Access For LoadBalancer Service
|
||||
-->
|
||||
## 负载均衡(LoadBalancer)服务的访问限制
|
||||
|
||||
|
||||
|
||||
|
||||
当以 `spec.type: LoadBalancer` 使用服务时,你可以使用 `spec.loadBalancerSourceRanges` 指定允许访问负载均衡的 IP 段。
|
||||
这个字段采用 CIDR 的 IP 段,Kubernetes 会使用这个段配置防火墙。支持这个功能的平台目前有 Google Compute Engine,Google Kubernetes Engine 和 AWS。
|
||||
如果云服务商不支持这个功能,这个字段会被忽略。
|
||||
<!--
|
||||
When using a Service with `spec.type: LoadBalancer`, you can specify the IP ranges that are allowed to access the load balancer
|
||||
by using `spec.loadBalancerSourceRanges`. This field takes a list of IP CIDR ranges, which Kubernetes will use to configure firewall exceptions.
|
||||
This feature is currently supported on Google Compute Engine, Google Kubernetes Engine, AWS Elastic Kubernetes Service, and Azure Kubernetes Service. This field will be ignored if the cloud provider does not support the feature.
|
||||
-->
|
||||
当以 `spec.type: LoadBalancer` 方式配置服务时,你可以使用 `spec.loadBalancerSourceRanges` 来指定允许访问负载均衡器的 ip 段。
|
||||
这个字段采用 CIDR 的 IP 段, kubernetes 使用该段配置防火墙。目前只有 谷歌计算引擎,谷歌云原生引擎,亚马逊弹性原生云服务 和 微软云原生平台支持此功能。
|
||||
如果云服务提供商不支持这个功能,这个字段将被忽略。
|
||||
|
||||
|
||||
|
||||
假设 10.0.0.0/8 是内部的子网。在下面这个例子中,会创建一个只有集群内部 ip 可以访问的负载均衡器。
|
||||
集群外部的客户端是无法访问这个负载均衡器的。
|
||||
<!--
|
||||
Assuming 10.0.0.0/8 is the internal subnet. In the following example, a load balancer will be created that is only accessible to cluster internal IPs.
|
||||
This will not allow clients from outside of your Kubernetes cluster to access the load balancer.
|
||||
-->
|
||||
假设内部子网为假设10.0.0.0/8,在下面这个例子中,将创建一个仅能由群集内部IP访问的负载均衡器。此负载均衡器不允许来自 kubernetes 集群外部客户端的访问。
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
@@ -36,17 +55,18 @@ metadata:
|
||||
name: myapp
|
||||
spec:
|
||||
ports:
|
||||
- port: 8765
|
||||
targetPort: 9376
|
||||
- port: 8765
|
||||
targetPort: 9376
|
||||
selector:
|
||||
app: example
|
||||
type: LoadBalancer
|
||||
loadBalancerSourceRanges:
|
||||
- 10.0.0.0/8
|
||||
```
|
||||
|
||||
|
||||
这个例子中,会创建一个只能被 IP 为 130.211.204.1 和 130.211.204.2 的客户端访问的负载据衡器。
|
||||
<!--
|
||||
In the following example, a load balancer will be created that is only accessible to clients with IP addresses from 130.211.204.1 and 130.211.204.2.
|
||||
-->
|
||||
在下面这个例子中,将创建一个只能被 IP 为 130.211.204.1 和 130.211.204.2 的客户端访问的负载据衡器。
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
@@ -55,8 +75,8 @@ metadata:
|
||||
name: myapp
|
||||
spec:
|
||||
ports:
|
||||
- port: 8765
|
||||
targetPort: 9376
|
||||
- port: 8765
|
||||
targetPort: 9376
|
||||
selector:
|
||||
app: example
|
||||
type: LoadBalancer
|
||||
@@ -64,63 +84,79 @@ spec:
|
||||
- 130.211.204.1/32
|
||||
- 130.211.204.2/32
|
||||
```
|
||||
<!--
|
||||
## Google Compute Engine
|
||||
-->
|
||||
## 谷歌计算引擎 (Google Compute Engine)
|
||||
|
||||
<!--
|
||||
When using a Service with `spec.type: LoadBalancer`, the firewall will be
|
||||
opened automatically. When using `spec.type: NodePort`, however, the firewall
|
||||
is *not* opened by default.
|
||||
-->
|
||||
当以 `spec.type: LoadBalancer` 方式配置服务时,该服务的防火墙将自动打开。
|
||||
当以 `spec.type: NodePort` 方式配置服务时,该服务的防火墙在默认情况下不会打开。
|
||||
|
||||
### 谷歌计算引擎(Google Compute Engine)
|
||||
<!--
|
||||
Google Compute Engine firewalls are documented [elsewhere](https://cloud.google.com/compute/docs/networking#firewalls_1).
|
||||
-->
|
||||
谷歌计算引擎的防火墙会进行记录 [他处] (https://cloud.google.com/compute/docs/networking#firewalls_1)。
|
||||
|
||||
|
||||
|
||||
|
||||
当以 `spec.type: LoadBalancer` 使用服务时,防火墙会被自动打开。
|
||||
然而,当以 `spec.type: NodePort` 使用服务时,防火墙默认 *不会* 被打开。
|
||||
|
||||
|
||||
Google Compute Engine 的防火墙文档在[别处](https://cloud.google.com/compute/docs/networking#firewalls_1)。
|
||||
|
||||
|
||||
你可以使用 `gcloud` 命令行工具添加一个防火墙:
|
||||
<!--
|
||||
You can add a firewall with the `gcloud` command line tool:
|
||||
-->
|
||||
你也可以使用 gcloud 命令行工具自行添加防火墙:
|
||||
|
||||
```shell
|
||||
$ gcloud compute firewall-rules create my-rule --allow=tcp:<port>
|
||||
gcloud compute firewall-rules create my-rule --allow=tcp:<port>
|
||||
```
|
||||
|
||||
|
||||
|
||||
**注意**
|
||||
使用 Google Compute Engine 平台的防火墙时有一个重要的关于安全的注意点:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
在 Kubernetes v1.0.0 版本,GCE 防火墙是定义按虚拟机(VM)来的,而不是按 ip 来的。
|
||||
{{< note >}}
|
||||
<!--
|
||||
GCE firewalls are defined per-vm, rather than per-ip address. This means that
|
||||
when you open a firewall for a service's ports, anything that serves on that
|
||||
port on that VM's host IP address may potentially serve traffic. Note that this
|
||||
is not a problem for other Kubernetes services, as they listen on IP addresses
|
||||
that are different than the host node's external IP address.
|
||||
-->
|
||||
GCE 防火墙是按照虚拟机来定义的,而不是通过ip地址来定义的。
|
||||
这就意味着当你在防火墙上打开一个服务端口时,任何在那台虚拟机 IP 上的同一端口的服务
|
||||
都有被外部访问的潜在可能。注意,这对于其他 Kubernetes 服务来说不是问题,因为他们监
|
||||
听的 IP 地址与主机节点的外部 IP 地址不同。
|
||||
都有被外部访问的潜在可能。需要注意的是,对于其他的 kubernetes 服务而言,这不是问题。
|
||||
因为他们监听的ip 地址与主机节点外部的 ip 地址并不相同。
|
||||
|
||||
<!--
|
||||
Consider:
|
||||
-->
|
||||
试想一下:
|
||||
|
||||
考虑一下:
|
||||
<!--
|
||||
* You create a Service with an external load balancer (IP Address 1.2.3.4)
|
||||
and port 80
|
||||
-->
|
||||
* 你建立一个( ip 地址为1.2.3.4)端口为80的外部负载均衡器
|
||||
|
||||
* 你创建了一个服务,使用了外部服务均衡 (IP 地址为 1.2.3.4) 和 80 端口。
|
||||
* 你在防火墙上为集群的所有节点都打开了 80 端口,所以外部的服务可以向你的
|
||||
<!--
|
||||
* You open the firewall for port 80 for all nodes in your cluster, so that
|
||||
the external Service actually can deliver packets to your Service
|
||||
-->
|
||||
* 因为在防火墙上为集群的所有节点都打开了 80 端口,所以外部的服务可以向你的
|
||||
服务发送数据包。
|
||||
* 你又在虚拟机(IP 为2.3.4.5)上使用 80 端口启动了一台 nginx 服务器.
|
||||
这个 nginx 在虚拟机的外部 IP 地址上也被暴露到了 internet 上。
|
||||
|
||||
<!--
|
||||
* You start an nginx server, running on port 80 on the host virtual machine
|
||||
(IP Address 2.3.4.5). This nginx is also exposed to the internet on
|
||||
the VM's external IP address.
|
||||
-->
|
||||
* 最后你又虚拟机上的80端口启动 nginx 服务器(ip地址2.3.4.5)。
|
||||
这个 nginx 在虚拟机的外部 IP 地址上也被暴露到了互联网上。
|
||||
|
||||
<!--
|
||||
Consequently, please be careful when opening firewalls in Google Compute Engine
|
||||
or Google Kubernetes Engine. You may accidentally be exposing other services to
|
||||
the wilds of the internet.
|
||||
-->
|
||||
因此请务必小心,在谷歌计算引擎或者谷歌云原生引擎中打开防火墙时,可能无意间把其他服务也暴露给了互联网。
|
||||
|
||||
{{< /note >}}
|
||||
|
||||
|
||||
|
||||
因此,在 Google Compute Engine 或者 Google Kubernetes Engine 上开启防火墙端口时请
|
||||
小心。你可能无意间把其他服务也暴露给了 internet。
|
||||
|
||||
|
||||
这个问题会在 Kubernetes 后续版本中被修复。
|
||||
|
||||
|
||||
### 其他云服务商
|
||||
|
||||
|
||||
即将更新
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
Reference in New Issue
Block a user