Skip to content

kaczenski/platform-localhost-emulation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Localhost Stack

Requirements

  • Docker

K8s emulators

  • Oldest option from K8s emulators
  • Can specify kubernetes version
  • Runs as Docker or some VirtualBox
  • There are a bunch of addons available. For instance, cert-manager, nginx-controller...
  • Runs images from localhost

asciicast

Deploy a cluster

brew install minikube
minikube start --driver=docker --memory 8196 --cpus=4 --kubernetes-version=v1.18.0

Delete a cluster

minikube delete

Loading a local image in your cluster

This is an example of pulling and running in the minikube cluster a nginx image:

minikube start --driver=docker --memory 8196 --cpus=4 --kubernetes-version=v1.18.0
eval $(minikube docker-env)
docker ps
docker pull nginx
docker tag nginx test-nginx:1.0
kubectl run --image=test-nginx:1.0 nginx-app --port=80 --image-pull-policy=Never
kubectl port-forward po/nginx-app 8080:80
  • Specify imagePullPolicy: IfNotPresent or imagePullPolicy: Never on your container(s).
  • K8s cluster into Docker containers
  • Faster startup than Minikube
  • Better documentation than Minikube
  • Runs images from localhost (previous load image as K3d)
  • Cluster setup as code

asciicast

Deploy a cluster

brew install kind
kind create cluster --config=kind/cluster-conf.yaml

Delete a cluster

kind delete cluster

Loading a local image in your cluster

This is an example of pulling and running in the Kind cluster a nginx image:

docker pull nginx:latest 
docker tag nginx:latest localhost-nginx:1.0
kind load localhost-nginx:1.0
kubectl run --image=localhost-nginx:1.0 localhost-nginx --port=80 --image-pull-policy=Never
kubectl get po
kubectl logs -f 
  • Specify imagePullPolicy: IfNotPresent or imagePullPolicy: Never on your container(s).

Ingress controller

asciicast

  • Lightweight k3s image from Docker
  • Runs on Docker
  • Runs faster than anyone
  • More than enough to gain knowledge in k8s
  • Runs images from localhost (previous load image as Kind)
  • https://github.com/iwilltry42/k3d-demo

asciicast

Deploy a cluster

brew install k3d
k3d cluster create mycluster

Delete a cluster

k3d cluster delete mycluster

Loading a local image in your cluster

This is an example of pulling and running in the K3d cluster a nginx image:

docker pull nginx:latest 
docker tag nginx:latest localhost-nginx:1.0
k3d image import localhost-nginx:1.0 -c mycluster
kubectl run --image=localhost-nginx:1.0 localhost-nginx --port=80 --image-pull-policy=Never
  • Specify imagePullPolicy: IfNotPresent or imagePullPolicy: Never on your container(s).

Localstack

asciicast

For those interested in try their services before going to AWS, they can deploy localstack in Minikube and create their AWS resources in localhost

The steps to deploy localstack in your Minikube are the following:

K8s yaml definition details

image: localstack/localstack

To be able to access from k8s:

kubectl expose pod localstack --type=ClusterIP --name=localstack

If you want to access localstack from your localhost:

kubectl port-forward po/localstack 4566:4566 

Now, you can access your localstack pod. For instance, you can create a bucket:

  • From localhost:
aws --endpoint-url=http://localhost:4566 s3api list-buckets
aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket test-localstack
aws --endpoint-url=http://localhost:4566 s3 cp test.sh s3://test-localstack
aws --endpoint-url=http://localhost:4566 s3 ls s3://test-localstack
  • From k8s:
aws --endpoint-url=http://localstack:4566 s3api list-buckets
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket test-localstack
aws --endpoint-url=http://localstack:4566 s3 cp test.sh s3://test-localstack
aws --endpoint-url=http://localstack:4566 s3 ls s3://test-localstack

For those supporters of Helm, there are a Helm chart in this repo to deploy with the serverless services (iam, lambda, dynamodb, apigateway, s3, sns). More settings: https://github.com/localstack/localstack#configurations

cd localstack
helm install localstack . -f values.yaml

Happy Localstacking!

Official Localstack documentation: https://github.com/localstack/localstack

Localstack Samples

Installation

helm install localstack -f ./../values.yaml

SQS sample

Golang code to test receive message in a Localstack SQS

asciicast

aws --endpoint-url=http://localstack.localhost sqs list-queues

aws --endpoint-url=http://localstack.localhost sqs create-queue --queue-name MyQueue

aws --endpoint-url=http://localstack.localhost sqs send-message --queue-url http://localstack.localhost/000000000000/MyQueue --message-body "Information about the largest city in Any Region."

go run main.go -q="MyQueue"

GCP Emulator

GCP offers emulator for the following GCP services:

  • BigTable
  • Datastore
  • Firestore
  • PubSub
  • Spanner

GCP PubSub Emulator

GCP offers PubSub emulator. A Helm chart has been setup to deploy it.

asciicast

K8s yaml definition details

image: google/cloud-sdk:latest
command: ["gcloud", "beta", "emulators", "pubsub", "start", "--host-port=0.0.0.0:8085", "--project=test"]
helm install gcp-emulator . -f values.yaml
cd gcp-emulator/samples/pubsub
go test -v .

About

Deploy in localhost K8s and cloud providers emulators

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 65.0%
  • Mustache 30.3%
  • Dockerfile 4.3%
  • Shell 0.4%