amazon-web-serviceskubernetesaws-cloudformationamazon-eksaws-cloudformation-custom-resource

how to reference existing ELB DNSName in Cloudformation template


we have Cloudformation template through which we deploy the infra resources for our product. and below are the AWS component which are creating through CF templates: 1. Networking Components. Like VPC, Subnets, Security groups etc. 2. IAM roles and policies. 3. EMR 4. EKS 5. MSK 6. RDS 7. Elasticache

also in our Cloudformation templates we have few custom resources like "Custom::KubeManifest". through which we are deploying the objects in AWS EKS cluster. one of our kubernetes object is "Service" object. which creates a service endpoints for internal services so that requests from public network can reach to our kubernetes cluster.

we wanted to check if we can reference the existing ELB DNS names in Cloudformation templates so that we can show the ELB DnsName in as Output.

for Example, when we call the "Custom::KubeManifest" resources as below template:

  ServiceDeployment:
    Type: "Custom::KubeManifest"
    Version: '1.0'
    Properties:
      ServiceToken: !Ref KubeManifestLambdaArn
      KubeConfigPath: !Sub "s3://${KubeConfigS3Bucket}/${KubeConfigS3Key}"
      KubeConfigKmsContext: !Ref KmsContext
      Manifest:
        apiVersion: v1
        kind: Service
        metadata:
          name: test
          labels:
            app: client
            tier: master
        spec:
          selector:
            app: client
            tier: master
          ports:
          - name: client-api
            port: 9877
            protocol: TCP
          - name: client-snapshots
            port: 9878
            protocol: TCP
          - name: client-support
            port: 9881
            protocol: TCP
  UiDeployment:
    Type: "Custom::KubeManifest"
    Version: '1.0'
    Properties:
      ServiceToken: !Ref KubeManifestLambdaArn
      KubeConfigPath: !Sub "s3://${KubeConfigS3Bucket}/${KubeConfigS3Key}"
      KubeConfigKmsContext: !Ref KmsContext
      Manifest:
        apiVersion: v1
        kind: Service
        metadata:
          name: client-ui
          annotations:
            service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
            service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
            service.beta.kubernetes.io/aws-load-balancer-type: nlb
            service.beta.kubernetes.io/aws-load-balancer-backend-protocol: 'tcp'
            service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "tcp"
            service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"
          labels:
            app: client
            tier: master
        spec:
          type: LoadBalancer
          selector:
            app: client
            tier: master
          ports:
          - name: client-ui
            port: 80
            protocol: TCP
            targetPort: 8800
          - name: client-ui-https
            port: 443
            protocol: TCP
            targetPort: 8800

it creates a ELB in AWS account and maps it with the Service endpoints in the EKS cluster. now we want to know that if by any functions we can reference the newly created ELB DnsNames and show it as Output.


Solution

  • we took a look on post: aws-quickstart-examples-eks

    where we are able to get the DnsNames of the newly created loadBalancer which is mapped to service endpoint by using

    Custom::KubeGet

    resource.