Code Monkey home page Code Monkey logo

kubernetes-demo-pods-volume-access's Introduction

Demo - data flow between 2 pods in the same namespace

Introduction

This demo is a very naive implementation, this is ONLY meant to demonstrate the use of secrets and configmaps as volume mounts and data flow between two pods via services. This is by NO means production ready.

In this demo, 2 pods (frontend and backend) in the same namespace (demo) are demonstrated to communicate with each other via 2 services (frontend and backend), where the frontend service is exposed as a nodeport and the backend service is an internal service (not exposed).

The backend pod has a secret mounted as a volume. The frontend pod then requests the backend for this secret and displays it in the client browser.

The backend pod is running a Nginx web server which serves as a mock API endpoint which exposes the secret file. The frontend pod is running a simple NodeJS web server which the client accesses from the browser to retrieve the secret content. Since this is merely a demonstration, the pods are kept as minimalistic as possible.

Structure

- backend-app
  - nginx.conf
  - secret.key
- frontend-app
  - src
    - package.json
    - server.js
    - yarn.lock
  - Dockerfile
- manifests
  - configmap.yml
  - deployment-backend.yml
  - deployment-frontend.yml
  - namespace.yml
  - secret.yml
- docker-compose.yml
  • The backend-app directory consists of config files that are used in the docker-compose.yml to configure the backend app.
  • The frontend-app directory consists of files that are used to build the docker image for the frontend app.
  • The manifsts directory consists of YAML definitions for setting up the Kubernetes cluster for this demo.
  • The docker-compose.yml can be used for testing the communication between the frontend app and backend app when Kubernetes/Minikube is not installed.

Usage

Pre-requisites

These are required for this demo:

  • kubectl and minikube or
  • docker-compose
  1. Start the minikube cluster:
minikube start
  1. Build the frontend docker image:
cd frontend-app/
eval $(minikube docker-env)
docker build -t myapp/frontend-test:latest .
  1. Run the manifests in the following order:
cd manifests/
kubectl apply -f namespace.yml
kubectl apply -f configmap.yml
kubectl apply -f secret.yml
kubectl apply -f deployment-backend.yml
kubectl apply -f deployment-frontend.yml
  • A namespace demo will be created.
  • A configmap nginx.conf is used to configure the Nginx server for the backend to serve up the secret file.
  • A secret secret.key is created which will be used as a mounted volume in the backend deployment.
  • deployment-backend.yml consists of the deployment and service manifest for the backend.
  • deployment-frontend.yml consists of the deployment and service manifest for the frontend.
  1. Access the nodeport:
minikube service -n demo frontend
  1. You should see "This variable is a super secret!" in the browser.

Conclusion

This simple demonstration shows a way in which to transfer data from a mounted volume (in this case an insecure secret) of one pod to another pod requesting for the data. It is vital to note that secrets are not meant to be used in this way, this naive implementation defeats the purpose of having secrets in the first place.

kubernetes-demo-pods-volume-access's People

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.