Created
January 20, 2022 12:38
-
-
Save warolv/e982ccce78a6b78c40cea4227c13912f to your computer and use it in GitHub Desktop.
Playing with EKS Fargate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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