I have one kafka external service in which I have used type: Loadbalancer
Problem: This service will always create new load balancer after uninstall/delete.
Usecase: I want to register load balancer's dns against one static DNS in aws cloud-map.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
service.beta.kubernetes.io/aws-load-balancer-type: nlb
name: kafka-test-3-1-external
labels:
helm.sh/chart: kafka-0.21.5
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: kafka-broker
app.kubernetes.io/name: kafka
app.kubernetes.io/instance: kafka-test-3
pod: "kafka-test-3-1"
spec:
type: LoadBalancer
ports:
- name: external-broker
port: 19092
targetPort: 19092
protocol: TCP
#
selector:
app.kubernetes.io/component: kafka-broker
app.kubernetes.io/name: kafka
app.kubernetes.io/instance: kafka-test-3
statefulset.kubernetes.io/pod-name: "kafka-test-3-1"
How can I do that?
You can use the below annotations in your services
where
kafka.internal
is my cloud-map namespace.So service would be look like below snippet.
To register the service loadbalancer's dns to cloud-map, we need to use
external-dns
service.Note: You have to create namespaces in cloudmap. And provide enough access to your kubernetes user.
To use the AWS Cloud Map API, a user must have permissions to create the DNS namespace. Additionally you need to make sure that your nodes (on which External DNS runs) have an IAM instance profile with the AWSCloudMapFullAccess managed policy attached, that provides following permissions:
Before applying the below snippet, replace placeholders
kafka.internal
Snippet: external-dns
External-dns pod will polling for changes in kubernetes services and if find any changes it will use
external-dns.alpha.kubernetes.io/hostname
annotation to map that loadbalancer's dns into cloud-map namespaces.For more details for auto register, https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/aws-sd.md