Skip to content

Instantly share code, notes, and snippets.

@warolv
Created Jan 20, 2022
Embed
What would you like to do?
Playing with EKS Fargate
apiVersion: v1
kind: ServiceAccount
metadata:
name: httpbin
namespace: play-with-fargate
---
apiVersion: v1
kind: Service
metadata:
name: httpbin
namespace: play-with-fargate
labels:
app: httpbin
service: httpbin
spec:
ports:
- name: http
port: 8000
targetPort: 80
selector:
app: httpbin
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin
namespace: play-with-fargate
spec:
replicas: 1
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
spec:
serviceAccountName: httpbin
containers:
- image: docker.io/kennethreitz/httpbin
name: httpbin
ports:
- containerPort: 80
# Provision EKS cluster
eksctl create cluster \
--name fargate-cluster \
--region eu-west-3
# Create fargate profile
eksctl create fargateprofile \
--cluster fargate-cluster \
--name play-with-fargate \
--namespace play-with-fargate \
--region eu-west-3
# Provision AWS Load Balancer Controller
# Create IAM OIDC provider
eksctl utils associate-iam-oidc-provider \
--region eu-west-3 \
--cluster fargate-cluster \
--approve
# Create an IAM policy
curl -o iam_policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.2.0/docs/install/iam_policy.json
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam_policy.json
rm iam_policy.json
# Create an IAM role and ServiceAccount for the Load Balancer controller
eksctl create iamserviceaccount \
--cluster fargate-cluster \
--region eu-west-3 \
--namespace kube-system \
--name aws-load-balancer-controller \
--attach-policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AWSLoadBalancerControllerIAMPolicy \
--override-existing-serviceaccounts \
--approve
# Install the TargetGroupBinding CRDs
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
# Install the AWS Load Balancer Controller
# get your VPC ID first:
aws eks describe-cluster \
--name fargate-cluster \
--region eu-west-3 \
--query "cluster.resourcesVpcConfig.vpcId" \
--output text
# Change vpcId before executing the next command.
helm repo add eks https://aws.github.io/eks-charts
helm upgrade -i aws-load-balancer-controller eks/aws-load-balancer-controller \
--set clusterName=fargate-cluster \
--set serviceAccount.create=false \
--set region=eu-west-3 \
--set vpcId=vpc-xxxxx \
--set serviceAccount.name=aws-load-balancer-controller -n kube-systeme vpcId before executing the next command.
# Verify that the AWS Load Balancer Controller is installed:
kubectl get deployment -n kube-system aws-load-balancer-controller
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
name: httpbin-ingress
spec:
rules:
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: httpbin
port:
number: 8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment