- Newest
- Most votes
- Most comments
Any chance to locate the cause by following:
Step 1: Verify Listener Rules Check Listener Rules: Ensure that the listener rules for port 80 are correctly configured. Since you have a redirection rule to port 443, make sure there are no other rules that might be causing the conflict.
Step 2: Deregister Targets Deregister Targets: Temporarily deregister the targets associated with the port 80 listener. This can be done through the AWS Management Console or using the AWS CLI. Once the targets are deregistered, you should be able to remove the listener.
Step 3: Update Ingress Annotations Remove Annotations: Update your Kubernetes ingress annotations to remove the port 80 listener. Ensure that the annotations are correctly applied to the ingress resource.
Step 4: Re-register Targets Re-register Targets: After successfully removing the port 80 listener, re-register the targets with the remaining listeners (e.g., port 443).
Hello, I appreciate you providing the detailed error message and context. Based on my analysis, I can see exactly what's happening here and why you're unable to remove port 80 from your ALB listener. The error message "Listener port '80' is in use by registered target" indicates that there are still active target groups with healthy or registered targets connected to the port 80 listener. This is a safety mechanism in AWS to prevent accidental removal of listeners that have active traffic routing.
Here's what's likely happening in your environment: Even though you've configured the port 80 listener with only a redirect rule to port 443, the ALB controller is still maintaining target group registrations on port 80. This could occur because:
- The ingress controller hasn't fully deregistered all targets from the port 80 target group yet
- There may be a delay in the target deregistration process
- The target group itself still exists with registered targets, even if they're not actively receiving traffic
Let me walk you through the resolution steps: STEP 1: VERIFY CURRENT STATE First, let's confirm what we're working with. Run these commands: kubectl get ingress -A -o yaml | grep -A 5 "listen-ports" This will show us all ingresses and their port configurations. Also check: kubectl describe ingress YOUR-INGRESS-NAME -n YOUR-NAMESPACE Look specifically for the alb.ingress.kubernetes.io/listen-ports annotation. STEP 2: CHECK THE ALB DIRECTLY Log into your AWS Console and navigate to EC2, then Load Balancers. Find your ALB and click on it. Go to the Listeners tab and check:
- How many listeners are currently configured
- For the port 80 listener, click on it and check the target groups
- Note the target group name associated with port 80 Then go to Target Groups and find the port 80 target group. Check how many targets are registered and their health status. This is critical information. STEP 3: DEREGISTER TARGETS BEFORE REMOVING THE LISTENER This is the key step you may have missed. Before the ALB controller can remove the listener, all targets must be deregistered. Here's what I recommend: First, update your ingress annotation to remove port 80: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: YOUR-INGRESS-NAME annotations: alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS": 443}]' alb.ingress.kubernetes.io/ssl-redirect: '443' After applying this change, wait about 2-3 minutes for the ingress controller to process it. Then manually check the target group in the AWS Console. If targets are still registered, you may need to manually deregister them. STEP 4: MANUAL CLEANUP IF NEEDED If the targets don't deregister automatically, you can do this manually:
- Go to EC2 > Target Groups in AWS Console
- Find the target group associated with port 80
- Select the target group
- Go to the Targets tab
- Select all registered targets
- Click Deregister
- Wait for the deregistration to complete After all targets are deregistered, the listener should be removable. STEP 5: REMOVE THE LISTENER Once targets are deregistered, apply your updated ingress manifest with only HTTPS on port 443. The ALB controller should now be able to remove the port 80 listener without errors.
IMPORTANT CONSIDERATIONS: Since you mentioned that security scanners are flagging port 80 as an issue, I want to clarify something important. If your port 80 listener is configured with a redirect rule to HTTPS (port 443), this is actually a security best practice and shouldn't be flagged as a vulnerability by most modern security scanners. However, if your organization's policy requires complete removal, the steps above will help you achieve that. Also, if you're using IngressGroups (where multiple ingresses share the same ALB), make sure all ingresses in that group have consistent port configurations. If one ingress still references port 80, it will prevent removal.
TROUBLESHOOTING IF ISSUES PERSIST: If you still encounter the error after following these steps, it could indicate:
- The ingress controller hasn't fully processed your annotation changes yet. Try waiting 5 minutes and redeploying.
- There's a stale target group that's not being cleaned up. In this case, you may need to manually delete the target group from the AWS Console after deregistering all targets.
- There's another ingress or service still using port 80 on the same ALB. Run the kubectl commands from Step 1 again to verify.
REFERENCES: [1] AWS Load Balancer Controller Documentation - https://kubernetes-sigs.github.io/aws-load-balancer-controller/ [2] ALB Ingress Annotations - https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/annotations/ [3] AWS Application Load Balancer User Guide - https://docs.aws.amazon.com/elasticloadbalancing/latest/application/ [4] Target Groups for Application Load Balancers - https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html [5] Deregistering Targets from Target Groups - https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-deregister-targets.html
answered a year ago
