Code Monkey home page Code Monkey logo

kubernetes-elixir-example's Introduction

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.