Skip to content

jeanpsv/kubernetes-elixir-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubernetes-elixir-example

Elixir application into Kubernetes Cluster

Set up your database configuration

  1. copy dev secret template file
cp config/dev.secret.exs.example config/dev.secret.exs
  1. update username and password to authorize your database connection
  2. run mix ecto.create
  3. run mix ecto.migrate

Run application

REPLACE_OS_VARS=true \
PORT=4000 \
HOST=example.com \
SECRET_KEY_BASE=${secret_key_base} \
DB_USERNAME=${db_username} \
DB_PASSWORD=${db_password} \
DB_NAME=${db_name} \
DB_HOSTNAME=${db_hostname} \
_build/prod/rel/kubernetes_elixir_example/bin/kubernetes_elixir_example foreground

replace ${variable} for their real values

Prepare Kubernetes (Minikube)

Before generating your application images, start Minikube ( minikube start) and run eval $(minikube docker-env) to reuse Docker daemon.

Generate Docker images

mix docker.build
mix docker.release

Run application with Docker

docker run -it -p 8000:8000 \
-e "HOST=example.com" \
-e "SECRET_KEY_BASE=${secret_key_base}" \
-e "DB_USERNAME=${db_username}" \
-e "DB_PASSWORD=${db_password}" \
-e "DB_NAME=${db_name}" \
-e "DB_HOSTNAME=${db_hostname}" \
--rm jeanpsv/kubernetes-elixir-example:release foreground

Run minikube ip to discover the IP address of Minikube VM and access your application in:

http://<minikube ip>:8000

Run application on Kubernetes using Minikube

  1. Copy k8s/secrets.yml.example to k8s/secrets.yml
cp k8s/secrets.yml.example k8s/secrets.yml
  1. Replace <secret_key_base_here> to your real value and do the same for <db_password_here>.
  2. Apply secrets: kubectl create -f k8s/secrets.yml
  3. Apply deployment: kubectl create -f k8s/deployment.yml
  4. Apply service: kubectl create -f k8s/service.yml

Type minikube service kubernetes-elixir-example-service on terminal to open your application on browser and know the IP address.

You can try something like http:<app ip>:<app port>/api/greetings to see all greetings stored. I implemented CRUD operations to greetings model. So, we have the following endpoints:

  • GET /api/greetings
  • GET /api/greetings/:id
  • POST /api/greetings
  • PUT /api/greetings/:id
  • DELETE /api/greetings/:id

Furthermore

I followed that tutorials:

About

Elixir application into Kubernetes Cluster

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages