Git Product home page Git Product logo

study-kubernetes's Introduction

Study Kubernetes

This repository has some examples of Kubernetes and Kubernetes Resources. The goals were to build a simple solution, to help get a few examples of how to deploy an application, or some applications, on Kubernetes infrastructure.

Database

The database used in this example is simple. We only have one table, responsible for storing a history of the process executed by the application.

This database runs outside Kubernetes, and we use a docker-compose file to configure how this database should work. On the container's startup, we execute two scripts. The first creates the table background_entity, which will store our data. The second one makes the application user and applies some grants for this user. We configure a headless service without selectors to expose the database inside the cluster and create an endpoint pointing to the database IP address.

UUID Service

This application only generates the IDs that will be used as an identifier on the database. The goal is to show how the communication between applications inside Kubernetes works.

The API receives a request on /generate endpoint, and returns a new UUID.

The infrastructure of this application is composed of:

  • deployment.yml: configures our pods. As the app is simple, we run only one replica.
  • nodePort.yml: configure a service of type nodePort.

Using a nodePort service, in addition to being possible for other applications inside the cluster to consume this service using the internal clusterIp, it is also possible to call it from outside the cluster. For this, we can call any IP of the cluster and use port 32000. Background API

Background API

This API is our principal application. It works simply: the API receives a number and executes a background process (creating a new thread for each processing). The application will count until the goal received in the request is reached.

The application saves the data of each process in the bank, storing the current status (Scheduled, Running, Finished, or Error), how many counts have been made, and also how many counts it should do.

The identifier for each processing is obtained from the UUID Service, making a rest call for this service.

The infrastructure of this application is composed of: 

  • deployment.yml: configures our pods. This app starts with two replicas.
  • clusterIp.yml: configure a service for the application that will redirect and balance requests to our pods.
  • ingress.yml: enable the application to receive requests from outside the cluster.
Configure Ingress:

We need to create a host for ingress to work correctly. To do this, first get the IP address of the main container (control plane) of the cluster run by kind:

docker inspect study-kubernetes-cluster-control-plane | grep IPAddress

Now, open the /etc/hosts file and add the line below:

<ip-control-plane> backgroundprocess.io

This configures our control plane IP to respond to the backgroundprocess.io host. With this done, we can make calls to our application within the cluster

curl -X GET 'http://backgroundprocess.io/hello'
curl -X POST 'http://backgroundprocess.io/background/10'
curl -X GET 'http://backgroundprocess.io/background'

study-kubernetes's People

Contributors

frozendo avatar

Watchers

 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.