aws-samples / aws-pod-eip-controller

MIT No Attribution
53 stars 4 forks source link

feat: disable pod eip reclaim && support fixed public eip #92

Closed thehackercat closed 1 month ago

thehackercat commented 2 months ago

Issue #, if available: https://github.com/aws-samples/aws-pod-eip-controller/issues/84

We have a use case where we utilize fixed Elastic IP addresses in AWS, and we believe that other users may encounter similar situations. In this PR, I have implemented the technical solution to allow users to use both fixed Elastic IP and random Elastic IP modes through annotations.

Description of changes: Support fixed public eip for controller.

To achieve a fixed public EIP in AWS eip controller, you can follow these steps:

  1. Allocate an Elastic IP address: Use the AWS Management Console, or patch annotataion to pod in order to allocate an Elastic IP address. This reserves a specific public IP address within Amazon's pool of addresses.
  2. Associate the Elastic IP address with pod: Associate the allocated Elastic IP address with the desired pod via annotation. This ensures the instance is reachable through the fixed public IP address.
cat << EOF > no-reclaim-eip-sts.yaml
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: no-reclaim-eip-sts
  namespace: lexus-test
spec:
  replicas: 2
  selector:
    matchLabels:
      app: no-reclaim-eip-sts
  template:
    metadata:
      labels:
        app: no-reclaim-eip-sts
      annotations:
        aws-samples.github.com/aws-pod-eip-controller-mode: "fixed"
        aws-samples.github.com/aws-pod-eip-controller-type: auto
    spec:
      containers:
      - name: nginx-app-container
        image: nginx
EOF
kubectl apply -f no-reclaim-eip-sts.yaml        

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

turmind commented 1 month ago

Thank you for your contribution. I reviewed this part of the code last week. The method you used to implement fixed EIP binding is indeed very flexible.

However, there are some issues with the code structure of the project, so I started refactoring, resulting in quite a few code conflicts. Referring to the method in your code, I added a fixed-tag-value pattern to support the use of fixed IPs.

thehackercat commented 1 month ago

Referring to the method in your code, I added a fixed-tag-value pattern to support the use of fixed IPs.

@turmind Awesome, that will be great to have fixed IPs implemented in the next release.

Btw, we have also done some internal code optimizations of this project to make it more reliable in the production environment, such as adding leader election function and more reporting of Kubernetes events.

If you still need those features after refactoring the code, please let me know, I would like to contribute the codes.

turmind commented 1 month ago

Thank you for sharing the updates and your willingness to contribute! I really appreciate developers like yourself who are actively involved in improving this project.