Skip to main content

A Sceptre resolver to retrieve a kubernetes service load balancer URI

Project description

PyPI PyPI - Wheel CI/CD PyPI - Downloads PyPI pyversions PyPI license

sceptre-eks-lb-resolver

Sceptre custom resolver you can use to dynamically read AWS EKS Load Balancer URI into your Sceptre config.

It reads services inside your Kubernetes cluster with type LoadBalancer and returns its External DNS/URI.

Installation

$> pip install sceptre-eks-lb-resolver

Usage

Simply call the resolver inside your Sceptre configuration files:

template_path: mystack.yaml

parameters:
  ProjectName: "My k8s API"
  LoadBalancerURI: !eks_lb_uri -n backend -s data_api 

Will resolve to something like:

LoadBalancerURI: "XXXXXXXXXXX.us-east-1.elb.amazonaws.com"

You can use your Sceptre variables as arguments for the resolver:

  ...
  LoadBalancerURI: !eks_lb_uri -n {{ var.namespace }} -s {{ var.service }}

So with that in place, when you run sceptre launch --yes dev/us-east-1, it will call the resolver and assign the k8s load balancer URI to the Sceptre variable LoadBalancerURI at runtime.

Make sure to guarantee that you are properly authenticated within AWS

Syntax

Resolver expects two arguments: -n | --namespace and -s | --service-name. The --namespace argument is optional. It assumes kubeernetes default namespace as its default value.

All available ways of using this resolver are as follows:

  LBArn: !eks_lb_uri --namespace {{ var.namespace }} --service-name {{ var.service }}
  LBArn: !eks_lb_uri -n {{ var.namespace }} -s {{ var.service }}
  LBArn: !eks_lb_uri -s {{ var.service }}  # Assumes default namespace
  LBArn: !eks_lb_uri -s "my_api_service_name"
  LBArn: !eks_lb_uri -n backend -s data_api

How does it works?

The resolver is called by Sceptre in order to retrieve remote k8s cluster services. The EKS Load Balancer Resolver uses kubernetes python client to connect on the remote cluster and retrieve data of the given service name from a given namespace.

The K8s Load Balancer URI resolver simply tries to get the Load Balancer DNS as if you run:

$> kubectl --namespace backend get service api-service
NAME               TYPE           CLUSTER-IP       EXTERNAL-IP                               PORT(S)         AGE
api-service        LoadBalancer   10.0.42.123      XXXXXXXXXXX.us-east-1.elb.amazonaws.com   443:32214/TCP   12h40m

The resolver goes after the XXXXXXXXXXX.us-east-1.elb.amazonaws.com value. When succeeds, it loads in place this value in your Sceptre template.

Notes

Be aware that the shell which sceptre will be called MUST be authenticated on AWS and your kubeconfig properly updated to point to your AWS EKS remote cluster.

You can refer to the following links for either AWS and Kubernetes authentication:

Contributing

Fork, change, make test, make check, Pull Request. I will review the code and if Github Actions pipeline succeeds: congratulations! We are going to merge ;)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sceptre-eks-lb-resolver-0.2.1.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

sceptre_eks_lb_resolver-0.2.1-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page