Skip to content

Instantly share code, notes, and snippets.

@shearluck
Last active October 17, 2022 07:44
Show Gist options
  • Save shearluck/efbab2510f95b07201cf1f874a8120cb to your computer and use it in GitHub Desktop.
Save shearluck/efbab2510f95b07201cf1f874a8120cb to your computer and use it in GitHub Desktop.
Kubernetes k3s, EC2 spot instance, ECR, Private registry
apiVersion: v1
kind: Pod
metadata:
name: <app-name>
labels:
app: <app-name>
spec:
containers:
- name: <app-name>
image: <account>.dkr.ecr.us-west-2.amazonaws.com/<app-name>:latest
imagePullSecrets:
- name: regcred
#!/bin/bash
# Install dependencies
yum update -y
yum install -y vim git curl wget docker awscli
# Configure AWS CLI
aws configure
# Get docker login command from ECR
aws ecr get-login --no-include-email --region <region>
# Store ECR login credentials as kubernetes secret
k3s kubectl create secret docker-registry regcred \
--docker-server=<account>.dkr.ecr.<region>.amazonaws.com \
--docker-username=AWS \
--docker-password=<password from ecr login command>
# When docker login is already run
$(aws ecr get-login --no-include-email --region us-west-2)
kubectl delete secret ecr
kubectl create secret generic ecr \
--from-file=.dockerconfigjson=/home/centos/.docker/config.json \
--type=kubernetes.io/dockerconfigjson
k3s kubectl get secret regcred --output=yaml
# Run pod
k3s kubectl apply -f pod.yaml
# Create service, port is the docker exposed port
k3s kubectl expose pod <app-name> --type=LoadBalancer --port=3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment