How can I assign a static IP to my EKS service?
Asked Answered
W

4

15

I have an EKS cluster.

I created my service and exposed it using ingress-nginx.

ingress-nginx external IP appears as a DNS name and not as IP.

How can I connect my private domain to point to my EKS service?

I know that there is an annotation for using AWS Elastic IP with Kubernetes,

but it's only available starting from Kubernetes 1.16 and EKS supports only up to 1.14.

So what are my options to assign some static IP to my service and configure my DNS to point this IP?

Winsome answered 6/2, 2020 at 13:15 Comment(0)
O
9

Assigning Static IP Address to AWS Load Balancer

The answer to this post still rings true in this case.

The way Amazon does load balancing is it will scale up and down interfaces as needed to handle the request load. This is why they assign you a domain name instead of an IP address since your load balancer could have multiple physical interfaces and the IP addresses will frequently change.

If all you are trying to do is create a DNS name for your load balancer, this can simply be done with any DNS provider by creating a CNAME record pointing to the dns name of the load balancer provisioned by AWS. If you are using Route53, it is even simpler since you can just create an A record with an alias to the DNS name.

I hope this helps. FWIW, it is not possible to get a single static IP address for your load balancer unless you are only deploying it in one Availability Zone.

Odo answered 6/2, 2020 at 14:47 Comment(1)
will the DNS name eks gives us changed?Masorete
L
19

When creating LoadBalancer service (which will create an actual load balancer), you can now specify preallocated Elastic IPs by id via annotations.

Example:

apiVersion: v1
kind: Service
metadata:
  name: some-name
  annotations:
    # only network load balancer supports static IP
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
    # comma-separated list of Elastic IP ids
    # the length of the list must be equal to the number of subnets
    service.beta.kubernetes.io/aws-load-balancer-eip-allocations: eipalloc-abcd0000,eipalloc-abcd0001,eipalloc-abcd0002
  ...
spec:
  type: LoadBalancer
  ...
Lederer answered 11/9, 2020 at 15:11 Comment(1)
Be aware that Elastic IPs are public and cost around $3/month.Spittle
O
9

Assigning Static IP Address to AWS Load Balancer

The answer to this post still rings true in this case.

The way Amazon does load balancing is it will scale up and down interfaces as needed to handle the request load. This is why they assign you a domain name instead of an IP address since your load balancer could have multiple physical interfaces and the IP addresses will frequently change.

If all you are trying to do is create a DNS name for your load balancer, this can simply be done with any DNS provider by creating a CNAME record pointing to the dns name of the load balancer provisioned by AWS. If you are using Route53, it is even simpler since you can just create an A record with an alias to the DNS name.

I hope this helps. FWIW, it is not possible to get a single static IP address for your load balancer unless you are only deploying it in one Availability Zone.

Odo answered 6/2, 2020 at 14:47 Comment(1)
will the DNS name eks gives us changed?Masorete
M
2

NOW you can assign to a EKS load service/load balancer elastic ips or private ips .

A example for private ips :

apiVersion: v1
kind: Service
metadata:
  annotations:
    external-dns.alpha.kubernetes.io/hostname: foobar.internal.k8s.test.
    external-dns.alpha.kubernetes.io/ttl: '30'
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
    service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: '600'
    service.beta.kubernetes.io/aws-load-balancer-internal: 'true'
    service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses: 10.10.1.15,10.20.1.15,10.30.1.30,10.40.1.30,10.50.1.45,10.50.1.45
 labels:
    app.kubernetes.io/instance: foobar
  name: foobar
  namespace: test-foobar
spec:
  ports:
  - name: foobar
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    internaldeployment: foobar
  type: LoadBalancer
  loadBalancerClass: service.k8s.aws/nlb

Source of documentation :

https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/service/annotations/#private-ipv4-addresses

for elastic ips , the documentation is here :

https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/service/annotations/#eip-allocations

Morgue answered 12/1, 2023 at 14:24 Comment(0)
T
-9

You can provision the Elastic IP on AWS and configure the service with that IP.

Ex:
type: LoadBalancer 
loadBalancerIP: xxxxx
Tanaka answered 6/2, 2020 at 14:27 Comment(1)
It will not work. You will get the following error message: "LoadBalancerIP cannot be specified for AWS ELB"Friary

© 2022 - 2024 — McMap. All rights reserved.