Tasks
Setup an extension API server
Administer a Cluster
Access Clusters Using the Kubernetes API (EN)
Access Services Running on Clusters (EN)
Advertise Extended Resources for a Node (EN)
Autoscale the DNS Service in a Cluster (EN)
Change the Reclaim Policy of a PersistentVolume (EN)
Change the default StorageClass (EN)
Cluster Management (EN)
Configure Multiple Schedulers (EN)
Configure Out Of Resource Handling (EN)
Configure Quotas for API Objects (EN)
Control CPU Management Policies on the Node (EN)
Customizing DNS Service (EN)
Debugging DNS Resolution (EN)
Declare Network Policy (EN)
Developing Cloud Controller Manager (EN)
Encrypting Secret Data at Rest (EN)
Guaranteed Scheduling For Critical Add-On Pods (EN)
IP Masquerade Agent User Guide (EN)
Kubernetes Cloud Controller Manager (EN)
Limit Storage Consumption (EN)
Namespaces Walkthrough (EN)
Operating etcd clusters for Kubernetes (EN)
Reconfigure a Node's Kubelet in a Live Cluster (EN)
Reserve Compute Resources for System Daemons (EN)
Safely Drain a Node while Respecting Application SLOs (EN)
Securing a Cluster (EN)
Set Kubelet parameters via a config file (EN)
Set up High-Availability Kubernetes Masters (EN)
Share a Cluster with Namespaces (EN)
Static Pods (EN)
Storage Object in Use Protection (EN)
Using CoreDNS for Service Discovery (EN)
Using a KMS provider for data encryption (EN)
Using sysctls in a Kubernetes Cluster (EN)
Accessing Clusters
Use Port Forwarding to Access Applications in a Cluster
Provide Load-Balanced Access to an Application in a Cluster
Use a Service to Access an Application in a Cluster
删除 StatefulSet
Create an External Load Balancer
配置你的云平台防火墙
List All Container Images Running in a Cluster
Configure DNS for a Cluster
Federation - Run an App on Multiple Clusters
Administer-clusters
Access Clusters Using the Kubernetes API (EN)
Advertise Extended Resources for a Node (EN)
Autoscale the DNS Service in a Cluster (EN)
Configure Multiple Schedulers (EN)
Configure Out Of Resource Handling (EN)
Configure Quotas for API Objects (EN)
Debugging DNS Resolution (EN)
Developing Cloud Controller Manager (EN)
Encrypting Secret Data at Rest
IP Masquerade Agent User Guide (EN)
Kubernetes Cloud Controller Manager (EN)
Limit Storage Consumption (EN)
Namespaces Walkthrough (EN)
Operating etcd clusters for Kubernetes (EN)
Reconfigure a Node's Kubelet in a Live Cluster (EN)
Reserve Compute Resources for System Daemons (EN)
Safely Drain a Node while Respecting Application SLOs (EN)
Securing a Cluster (EN)
Set up High-Availability Kubernetes Masters (EN)
Share a Cluster with Namespaces (EN)
Storage Object in Use Protection (EN)
Using CoreDNS for Service Discovery (EN)
Using a KMS provider for data encryption (EN)
使用 Calico 来提供 NetworkPolicy
使用 Romana 来提供 NetworkPolicy
使用 Weave 网络来提供 NetworkPolicy
关键插件 Pod 的调度保证
在 Kubernetes 中配置私有 DNS 和上游域名服务器
在 Kubernetes 集群中使用 sysctl
声明网络策略
将 kubeadm 集群在 v1.8 版本到 v1.9 版本之间升级/降级
应用资源配额和限额
控制节点上的CPU管理策略
改变默认 StorageClass
更改 PersistentVolume 的回收策略
设置 Pod CPU 和内存限制
访问集群上运行的服务
通过配置文件设置 Kubelet 参数
配置命名空间下pod总数
集群管理
静态Pods
Extend kubectl with plugins (EN)
使用 Service 把前端连接到后端
使用Deployment运行一个无状态应用
同 Pod 内的容器使用共享卷通信
基于Replication Controller执行滚动升级
对 DaemonSet 执行回滚
弹缩StatefulSet
管理巨页(HugePages)
证书轮换
调度 GPU
运行一个单实例有状态应用
配置对多集群的访问

Edit This Page

配置你的云平台防火墙

许多云服务提供商(比如 谷歌计算引擎)定义防火墙以防止服务无意间暴露到互联网上。 当暴露服务给外网时,你可能需要在防火墙上开启一个或者更多的端口来支持服务。 本文描述了这个过程,以及其他云服务商的具体信息。

准备开始

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using Minikube, or you can use one of these Kubernetes playgrounds:

To check the version, enter kubectl version.

负载均衡(LoadBalancer)服务的访问限制

当以 spec.type: LoadBalancer 方式配置服务时,你可以使用 spec.loadBalancerSourceRanges 来指定允许访问负载均衡器的 ip 段。 这个字段采用 CIDR 的 IP 段, kubernetes 使用该段配置防火墙。目前只有 谷歌计算引擎,谷歌云原生引擎,亚马逊弹性原生云服务 和 微软云原生平台支持此功能。 如果云服务提供商不支持这个功能,这个字段将被忽略。

假设内部子网为假设10.0.0.0/8,在下面这个例子中,将创建一个仅能由群集内部IP访问的负载均衡器。此负载均衡器不允许来自 kubernetes 集群外部客户端的访问。

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  ports:
  - port: 8765
    targetPort: 9376
  selector:
    app: example
  type: LoadBalancer
  loadBalancerSourceRanges:
  - 10.0.0.0/8

在下面这个例子中,将创建一个只能被 IP 为 130.211.204.1 和 130.211.204.2 的客户端访问的负载据衡器。

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  ports:
  - port: 8765
    targetPort: 9376
  selector:
    app: example
  type: LoadBalancer
  loadBalancerSourceRanges:
  - 130.211.204.1/32
  - 130.211.204.2/32

谷歌计算引擎 (Google Compute Engine)

当以 spec.type: LoadBalancer 方式配置服务时,该服务的防火墙将自动打开。 当以 spec.type: NodePort 方式配置服务时,该服务的防火墙在默认情况下不会打开。

谷歌计算引擎的防火墙会进行记录 他处

你也可以使用 gcloud 命令行工具自行添加防火墙:

gcloud compute firewall-rules create my-rule --allow=tcp:<port>
Note:

GCE 防火墙是按照虚拟机来定义的,而不是通过ip地址来定义的。 这就意味着当你在防火墙上打开一个服务端口时,任何在那台虚拟机 IP 上的同一端口的服务 都有被外部访问的潜在可能。需要注意的是,对于其他的 kubernetes 服务而言,这不是问题。 因为他们监听的ip 地址与主机节点外部的 ip 地址并不相同。

试想一下:

  • 你建立一个( ip 地址为1.2.3.4)端口为80的外部负载均衡器
  • 因为在防火墙上为集群的所有节点都打开了 80 端口,所以外部的服务可以向你的 服务发送数据包。
  • 最后你又虚拟机上的80端口启动 nginx 服务器(ip地址2.3.4.5)。 这个 nginx 在虚拟机的外部 IP 地址上也被暴露到了互联网上。

因此请务必小心,在谷歌计算引擎或者谷歌云原生引擎中打开防火墙时,可能无意间把其他服务也暴露给了互联网。

反馈