Reputation: 454
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.
Upvotes: 5
Views: 5935
Reputation: 31
The answers provided are not right. The question is how to work with an existing loadbalancer that is NOT CREATED by the cloudformation template. I have the same problem and all I can think of using ssm parameters type in the cloudformation. The syntax is explained here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
This allows you to externally set the parameter before running the cloudformation then reading it from ssm when you execute the template.
Upvotes: 0
Reputation: 234
Yu can refer the DNS name with:
Fn::GetAtt: [LoadBalancer, DNSName]
LoadBalancer is the created Load balancer resource.
Upvotes: 0
Reputation: 454
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.
Upvotes: 1
Reputation: 2728
This is my YAML example
Resources:
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref EnvironmentName
Subnets: !Ref Subnets
SecurityGroups:
- !Ref SecurityGroup
Tags:
- Key: Name
Value: !Ref EnvironmentName
LoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref DefaultTargetGroup
Both LoadBalancer
and LoadBAlanceListener
must be included. Then you must add outputs which declare values that you want available to a describe stacks API call.
Outputs:
LoadBalancer:
Description: A reference to the Application Load Balancer
Value: !Ref LoadBalancer
LoadBalancerUrl:
Description: The URL of the ALB
Value: !GetAtt LoadBalancer.DNSName
Listener:
Description: A reference to a port 80 listener
Value: !Ref LoadBalancerListener
Upvotes: 8