Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

Kubernetes Resource Types for AWS CloudFormation

This project provides extensions to AWS CloudFormation that enable the management of kubernetes resources in CloudFormation. By example:

Kubernetes manifest:

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-cm
data:
  example_key: example_value

Can be added to a CloudFormation template:

Resources:
 ExampleCm:
   Type: "AWSQS::Kubernetes::Resource"
   Properties:
     ClusterName: my-eks-cluster-name
     Namespace: default
     Manifest: | 
       apiVersion: v1
       kind: ConfigMap
       metadata:
         name: example-cm
       data:
         example_key: example_value

At this time EKS is supported by providing the ClusterName, with plans for support for more kubernetes distributions coming soon.

Prerequisites

IAM role

An IAM role is used by CloudFormation to execute the resource type handler code provided by this project. A CloudFormation template to create the execution role is available here

Create an EKS cluster and provide CloudFormation access to the Kubernetes API

EKS clusters use IAM to allow access to the kubernetes API, as the CloudFormation resource types in this project interact with the kubernetes API, the IAM execution role must be granted access to the kubernetes API. This can be done in one of two ways:

  • Create the cluster using CloudFormation: Currently there is no native way to manage EKS auth using CloudFormation (+1 this GitHub issue to help prioritize native support). For this reason we have published AWSQS::EKS::Cluster. Instructions on activation and usage can be found here.
  • Manually: to allow these resource types to access the kubernetes API, follow the instructions in the EKS documentation adding the IAM execution role created above to the system:masters group. (Note: you can scope this down if you plan to use the resource type to only perform specific operations on the kubernetes cluster)

Activating the Resource types

To activate the resource types in your account follow the links below, then choose the AWS Region you would like to use it in and click Activate.

Usage

The properties and return values are documented here:

Examples

Create a Kubernetes ConfigMap in the default namespace

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  MyConfigMap:
    Type: "AWSQS::Kubernetes::Resource"
    Properties:
      ClusterName: my-eks-cluster-name
      Namespace: default
      Manifest: | 
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: example-cm
        data:
          example_key: example_value

Get the cluster IP for the kube-dns service and add it to stack outputs

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  GetKubeDnsClusterIp:
    Type: "AWSQS::Kubernetes::Get"
    Properties:
      ClusterName: my-eks-cluster-name
      Namespace: kube-system
      Name: svc/kube-dns
      JsonPath: '{.spec.clusterIP}'
Outputs:
  KubeDnsClusterIp:
    Value: !GetAtt GetKubeDnsClusterIp.Response