Skip to content

Latest commit

 

History

History
336 lines (229 loc) · 11.4 KB

README.md

File metadata and controls

336 lines (229 loc) · 11.4 KB

Kubernetes Setup

It's assumed that these software are installed and running:


Table of Contents


minikube setup

minikube version

image

Create a cluster with two nodes.

minikube start --driver=docker --nodes 2 -p demo
kubectl get nodes

image

Add labels to both nodes.

kubectl label nodes demo nodelabel=node-01
kubectl label nodes demo-m02 nodelabel=node-02
kubectl get nodes --show-labels

image


Scenario p2p-app

Two Pods were created to accommodate the p2p-app. Which is a Rust application using the libp2p ping protocol to test the connectivity and performance between these two Pods. For each Pod a image is created and deployed into the container inside of the corresponding Pod.

image

Dockerfile

docker build -f /p2p-setup/pod-a-dockerfile.dev -t p2p-pod-a:1.0 .

Note : to list images just run "docker image ls"

image

docker tag p2p-pod-a:1.0 {docker.hub}/p2p-pod-a:1.0

image

docker push {docker.hub}/p2p-pod-a:1.0

image

docker build -f /p2p-setup/pod-b-dockerfile.dev -t p2p-pod-b:1.0 .
docker tag p2p-pod-b:1.0 {docker.hub}/p2p-pod-b:1.0
docker push {docker.hub}/p2p-pod-b:1.0

image


Pods

image

kubectl apply -f 1_namespace.yml

Note: to list the namespaces just run "kubectl get namespaces"

image

kubectl apply -f 2_pod-a.yml
kubectl logs -f pod-a --namespace=peer-to-peer-platform

image

kubectl apply -f 3_pod-b.yml
kubectl logs -f pod-b --namespace=peer-to-peer-platform

image


Scenario mdns-app

For this scenario we are going to create a node with two pods. Each pod will have two containers. The mDNS protocol is not able to discover devices outside the pod local network.

image

Dockerfile

docker build -f /peer-to-peer/kubernetes-setup/2_scenario_mdns-app/mdns-app-dockerfile.dev -t mdns-app:1.0 .
docker tag mdns-app:1.0 {docker.hub}/mdns-app:1.0
docker push {docker.hub}/mdns-app:1.0

Pods

kubectl apply -f 1_namespace.yml

Note: to list the namespaces just run "kubectl get namespaces"

image

Create a pod "pod-a" with two containers "container-a" & "container-b".

kubectl apply -f 2_pod-a.yml

Create a pod "pod-b" with two containers "container-a" & "container-b".

kubectl apply -f 3_pod-b.yml
kubectl get pod -o wide --namespace=peer-to-peer-platform

image

Verify the logs for the container "container-a" inside of the pod "pod-a".

kubectl logs pod-a -c container-a  --namespace=peer-to-peer-platform

image

Verify the logs for the container "container-b" inside of the pod "pod-a".

kubectl logs pod-a -c container-b  --namespace=peer-to-peer-platform

image

Verify the logs for the container "container-a" inside of the pod "pod-b".

kubectl logs pod-b -c container-a  --namespace=peer-to-peer-platform

image

Verify the logs for the container "container-b" inside of the pod "pod-b".

kubectl logs pod-b -c container-b  --namespace=peer-to-peer-platform

image

Delete all resources belonging to the namespace.

kubectl delete namespace peer-to-peer-platform

Scenario dht-app

For this scenario we are going to create a cluster with two nodes, with two pods each. For the mDNS protocol to discover devices outside the pod local network. The HostNetwork is set to true(hostNetwork: true) to allow a pod to use the node network namespace. This was done for pod-a and pod-c. The network behavior is composed by the mDNS protocol for discovery and Kademlia for storing the IPs of the peers found and providers.

image

Dockerfile

docker build -f /peer-to-peer/kubernetes-setup/3_scenario_dht-app/dht-app-dockerfile.dev -t dht-app:1.0 .
docker tag mdns-app:1.0 {docker.hub}/dht-app:1.0
docker push {docker.hub}/dht-app:1.0

Pods

kubectl apply -f 1_namespace.yml

Note: to list the namespaces just run "kubectl get namespaces"

image

Create a pod "pod-a" with one container "container-a".

kubectl apply -f 2_pod-a.yml

Note:HostNetwork allows a pod to use the node-01 network namespace.This is done to allow the mDNS to discover all other pods in the node. This is not a best practice and is used only for demonstration proposes.

Create a pod "pod-b" with one container "container-a".

kubectl apply -f 3_pod-b.yml

Create a pod "pod-c" with one container "container-a".

kubectl apply -f 4_pod-c.yml

Note:HostNetwork allows a pod to use the node-02 network namespace.This is done to allow the mDNS to discover all other pods in the node. This is not a best practice and is used only for demonstration proposes.

Create a pod "pod-d" with one container "container-a".

kubectl apply -f 5_pod-d.yml

Get all pods created.

kubectl get pods -o wide --namespace=peer-to-peer-platform

image

Login into the pod-a, execute the command "cargo run" and insert the IP value for the pod-a into the Distributed Hash Tables/Kademlia "PUT pod-a 192.168.49.2".

kubectl exec -it pod-a --namespace=peer-to-peer-platform -- /bin/bash

image

Login into the pod-d, execute the command "cargo run" and get the IP value for the pod-a from the Distributed Hash Tables/Kademlia "GET pod-a".

kubectl exec -it pod-d --namespace=peer-to-peer-platform -- /bin/bash

image

Login into the pod-b, execute the command "cargo run", insert the IP value for the pod-b from the Distributed Hash Tables/Kademlia "PUT pod-b 10.244.0.3" and insert pod-b as a provider "PUT_PROVIDER pod-b".

kubectl exec -it pod-b --namespace=peer-to-peer-platform -- /bin/bash

image

Login into the pod-c, execute the command "cargo run", get the IP value for the pod-b from the Distributed Hash Tables/Kademlia "GET pod-b" and GET pod-b as a provider "GET_PROVIDER pod-b".

kubectl exec -it pod-c --namespace=peer-to-peer-platform -- /bin/bash

image

Delete all resources belonging to the namespace.

kubectl delete namespace peer-to-peer-platform

References:

Dockerfile reference
minikube
Kubernetes Documentation
Rust Official Image