Why does K8S allow multiple port name definitions for a single port

Could anyone help me understand why K8S allows users to define multiple port names for a specific port? Is there any valid reason behind such an acceptance pattern?


            - name: https
              containerPort: 6443
              protocol: TCP
            - name: https-tls
              containerPort: 6443
              protocol: TCP

Originally it was a side-effect of the design, but it turns out some people use it to get different hostPorts (rare) so we decided not to “fix” it.

@thockin : Thanks for the quick response! But do we know the list of use cases that people use today and the recommendation/ good practice from k8s? I have no clue who added this support in k8s and why. It would be good if someone can point me to the bug/PR in the gitHub.

It wasn’t added on purpose, it was the side-effect of other decisions.

Best practice would be “don’t use it if you can’t explain why you need it”. Really, I doubt we would have added it on purpose, but it was emergent and we decided not to “fix” it (breaking users).

I tried but I could not find the issue where this was discussed. I will try again later.

1 Like

@thockin: Thanks for the clarification! Now I understand the background story and the right design practice.