Elixir application into Kubernetes Cluster
- copy dev secret template file
cp config/dev.secret.exs.example config/dev.secret.exs
- update username and password to authorize your database connection
- run
mix ecto.create
- run
mix ecto.migrate
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
Before generating your application images, start Minikube ( minikube start
) and run eval $(minikube docker-env)
to reuse Docker daemon.
mix docker.build
mix docker.release
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
- Copy
k8s/secrets.yml.example
tok8s/secrets.yml
cp k8s/secrets.yml.example k8s/secrets.yml
- Replace
<secret_key_base_here>
to your real value and do the same for<db_password_here>
. - Apply secrets:
kubectl create -f k8s/secrets.yml
- Apply deployment:
kubectl create -f k8s/deployment.yml
- 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
I followed that tutorials:
- A Complete Guide to Deploying Elixir & Phoenix Applications on Kubernetes — Part 1: Setting up Distillery
- A Complete Guide to Deploying Elixir & Phoenix Applications on Kubernetes — Part 2: Docker and Minikube
- A Complete Guide to Deploying Elixir & Phoenix Applications on Kubernetes — Part 3: Deploying to Kubernetes
- A Complete Guide to Deploying Elixir & Phoenix Applications on Kubernetes — Part 4: Secret Management