Git Product home page Git Product logo

av2-kubernetes-v3's Introduction

Alison Vandromme - Ynov M1 Docker Elective

Kubernetes - V3

Note:

V1 & V2 were mostly to learn the basic concepts of Kubernetes. I didn't want to modify them as I'd like to keep the learning steps available. Hence, the multiple repos.

App description

  • Users-API: Creates users and Logs users
  • Auth-API: Generate and verify tokens for authenticated users
  • Tasks-API: Stores users tasks in a file and received a token to be verified
  • Client: Calls the Tasks API through Nginx Reverse Proxy

Note: Dummy data, there is no database (so far)

Stack

Architecture

Method used

Step 1: Node/Express Apps

  • Created user-API
  • Created auth-API
  • Created tasks-API
  • Tested each app individually with npm start and Postman

Step 2: Dockerized APIs

  • Created Dockerfile for each API
  • Created docker-compose
  • Replaced API url with docker network name
  • Tested with :
docker-compose up --build

Note: Didn't add volumes, I want to focus on containers and pods interactions

Step 3: Deployment & Service Creation for User API

  • Verify that Minikube is up and running with
minikube status
  • If it's not running, then :
minikube start
  • Check if there is no ungoing deployments or services
kubectl get deployments
kubectl get services
  • Modified users-app.js so it doesn't make any requests for now to auth-api
  • Built image and pushed it to DockerHub
docker build -t alisonv2/kub-v3-users .
docker push alisonv2/kub-v3-users
  • Created users-deployment.yaml and applied it
  • Verify that pod is up and running
  • Created users-service.yaml and applied it
  • Expose service with Minikube
  • Tested the service with Postman at {minikube-url}/login (passing email and password)
cd ..
cd kubernetes
kubectl apply -f users-deployment.yaml
kubectl get pods
kubectl apply -f users-service.yaml
minikube service users-service

Step 4: Deployment & Service Creation for Auth API

  • Reverted users-api code so it does send requests to the auth-api
  • Replaced API urls with environment variables so the exact url used can be changed depending on which environment we're running
  • Added environment to docker-compose
  • Built new image only for auth and pushed it to DockerHub
cd auth-api
docker build -t alisonv2/kub-v3-auth .
docker push alisonv2/kub-v3-auth
  • Created auth-deployment inside users-deployment so it doesn't create another pod. The goal is to have auth and users as two different containers inside the same pod.
  • Updated users image
cd ..
cd users-api
docker build -t alisonv2/kub-v3-users .
docker push alisonv2/kub-v3-users
  • Provide AUTH_ADDRESS for Pod-internal communication
  • Applied updated users-deployment
  • Check if both containers are running (should see 2/2 Running and 1/1 Terminating)
cd ..
cd kubernetes
kubectl apply -f users-deployment.yaml
  • Signup test with Postman: Tests the users-api

  • Login test with Postman: Tests users/auth APIs communication, as the token is created in the auth-api

Step 5: Users-deployment and auth-deployment Separation

  • Created auth-deployment.yaml
  • Created auth-service.yaml
  • Chosed ClusterIP as a service type so the auth-api is not exposed outside the cluster
  • Modified get adress in users-app.js to used env variables provided by kubernetes (ALLCAPSSERVICENAME_SERVICE_SERVICE_HOST)
  • Added the same env name to docker-compose
  • Modified env in users-deployment
  • Applied auth-deployment and service
  • Reapplied users-deployment (As the file didn't change, I deleted the currently running one so the new one is applied.)
  • Checked if pods are up and running
# Make sure you're in users-api folder
docker build -t alisonv2/kub-v3-users .
docker push alisonv2/kub-v3-users
cd ..
cd kubernetes
kubectl apply -f auth-service.yaml,auth-deployment.yaml
kubectl delete -f users-deployment.yaml
kubectl apply -f users-deployment.yaml
kubectl get pods

Note: I kept the manually set env variable for the first call, so I can have both options as a reminder.

  • Option 1: Native env variables created by kubernetes
process.env.NAME_SERVICE_SERVICE_HOST

- Option 2: CoreDNS for automatic domain names

value: "servicename.namespace"

The namespaces are available with

kubectl get namespaces
  • Tested with Postman

Step 6: Tasks API Deployment and Service

  • Created tasks-deployment.yaml and service-deployment.yaml with env variables
  • Modified API url in tasks-app.js to use env variables
  • Modified docker-compose to set env variables
  • Built and pushed tasks image to DockerHub
  • Applied deployment and service
  • Checked running deployments & pods
  • Checked services
docker build -t alisonv2/kub-v3-tasks .
docker push alisonv2/kub-v3-tasks
cd ..
cd kubernetes
kubectl apply -f tasks-service.yaml,tasks-deployment.yaml
kubectl get deployments
kubectl get pods

  • Check what services are running with
kubectl get services

  • Start tasks service and get the URL to send requests to the tasks service
minikube service tasks-service

  • Test with Postman:

Note: As we don't have any tasks yet, the get request will send an error. So first, we need to send a POST request with a header and body.

Now we can send the get request, with the same header.

Step 7: Client Creation

  • Created Client with CRA
  • Created Dockerfile with Node
  • Created nginx config file
  • Added Nginx to client's Dockerfile
  • Built and ran container
docker build -t alisonv2/kub-v3-client .
docker run -p 80:80 --rm -d alisonv2/kub-v3-client
  • Created client-deployment and service
  • Built and pushed image to DockerHub
  • Applied deployment and service
  • Checked if services and pods are all available

  • Exposed client service
minikube service client-service

Step 8: Styles Improvements

  • Tweaked styles to make it look a tiny bit better
  • Added window location reload for auto fetch
  • Rebuilt image
  • Pushed image to DockerHub
  • Removed deployment
  • Reapplied deployment
  • Checked if everything is still up and running
docker build -t alisonv2/kub-v3-client .
docker push alisonv2/kub-v3-client:latest
cd ..
cd kubernetes
kubectl delete -f client-deployment.yaml
kubectl apply -f client-deployment.yaml
kubectl get deployments

av2-kubernetes-v3's People

Contributors

alisonv2 avatar

Watchers

 avatar  avatar

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.