简体   繁体   English

如何自定义由使用AWS NLB作为TCP服务的Kubernetes LoadBalancer类型服务创建的安全组入口规则

[英]How to customize the Security Group Ingress Rules created by a Kubernetes LoadBalancer type service that uses AWS NLB for TCP services

I have a TCP service that runs on via a Kubernetes Deployment on an AWS EKS cluster and is exposed to the internet by a Service of type LoadBalancer using the following definition 我有一个TCP服务,该服务通过AWS EKS集群上的Kubernetes部署运行,并通过使用以下定义的LoadBalancer类型的服务暴露给Internet

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
  name: tcpservice
spec:
  selector:
    app: tcpapp
  type: LoadBalancer
  ports:
  - port: 4453
    targetPort: 4453
    name: tcpport

Because the load balancer type is NLB, the ingress traffic has to be explicitly allowed on the security group that is applied to the nodes themselves. 由于负载均衡器类型为NLB,因此必须在应用于节点本身的安全组上显式允许入口流量。 The security group was created like this: 安全组是这样创建的:

✔ ~$ aws ec2 describe-security-groups --group-ids sg-2645567125762c6e2 | jq '.SecurityGroups[0].IpPermissions[0]'
{
  "FromPort": 32163,
  "IpProtocol": "tcp",
  "IpRanges": [
    {
      "CidrIp": "10.20.0.0/20",
      "Description": "kubernetes.io/rule/nlb/health=afd5427b6058811ea989512627425a2e"
    },
    {
      "CidrIp": "0.0.0.0/0",
      "Description": "kubernetes.io/rule/nlb/client=afd5427b6058811ea989512627425a2e"
    }
  ],
  "Ipv6Ranges": [],
  "PrefixListIds": [],
  "ToPort": 32163,
  "UserIdGroupPairs": []
}

So now I need to change the CidrIp in the "0.0.0.0/0" to a different block. 因此,现在我需要将“ 0.0.0.0/0”中的CidrIp更改为其他块。 How can I do this using kubernetes manifests? 如何使用kubernetes清单执行此操作? I've looked at the NetworkPolicy and Calico documentation, but this controls traffic to pods not services. 我看过NetworkPolicy和Calico文档,但这可以控制到Pod而不是服务的流量。 I can change it with the AWS API or manually, but those changes are lost when the service is redeployed. 我可以使用AWS API或手动进行更改,但是在重新部署服务时这些更改会丢失。

you need to add in your service manifest the loadBalancerSourceRanges parameter. 您需要在服务清单中添加loadBalancerSourceRanges参数。

from documentation: 来自文档:

In order to limit which client IP's can access the Network Load Balancer, specify loadBalancerSourceRanges. 为了限制哪些客户端IP可以访问网络负载平衡器,请指定loadBalancerSourceRanges。

spec:
  loadBalancerSourceRanges:
  - "143.231.0.0/16"

https://v1-13.docs.kubernetes.io/docs/concepts/services-networking/service/ https://v1-13.docs.kubernetes.io/docs/concepts/services-networking/service/

how code is implemented can be found here: 代码的实现方式可以在这里找到:

https://github.com/kubernetes/kubernetes/blob/9d6ebf6c78f406d8639aae189901e47562418071/pkg/api/service/util.go https://github.com/kubernetes/kubernetes/blob/9d6ebf6c78f406d8639aae189901e47562418071/pkg/api/service/util.go

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 撤销所有 AWS 安全组入口规则 - Revoke all AWS security group ingress rules 如何将kubernetes LoadBalancer Ingress URL发布到aws route53 - How to publish kubernetes LoadBalancer Ingress URL to aws route53 Kubernetes 和 AWS:将 LoadBalancer 设置为使用预定义的安全组 - Kubernetes and AWS: Set LoadBalancer to use predefined Security Group 在service.beta.kubernetes.io/aws-load-balancer-type注释中指定nlb时创建的经典负载均衡器 - Classic load balancer created when specifying nlb in service.beta.kubernetes.io/aws-load-balancer-type annotation 如何使用 `service.spec.externalIPs` 而不是 `--type=LoadBalancer` 在 AWS 上公开 Kubernetes 服务? - How to expose a Kubernetes service on AWS using `service.spec.externalIPs` and not `--type=LoadBalancer`? 为什么 AWS 中的 NLB 不需要安全组? - Why is it that an NLB in AWS does not require a Security Group? 使用 NLB 入口的 EKS 和部署在节点组中的多个服务 - EKS using NLB ingress and multiple services deployed in node group LetsEncrypt 不通过 AWS EKS 中的 Kubernetes 入口和负载均衡器进行验证 - LetsEncrypt not verifying via Kubernetes ingress and loadbalancer in AWS EKS 如何使用基于目标组“IP”的 [AWS] 设置 Kubernetes NLB 负载均衡器? - How to setup Kubernetes NLB Load Balancer with target group "IP" based [AWS]? 在通过 Kops 在 AWS 中创建的 kubernetes 中创建 nlb-ip 负载均衡器 - Create nlb-ip loadbalancers in kubernetes created in AWS through Kops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM