userspace

package module
v0.0.0-...-b3c6d96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 22 Imported by: 0

README

CSL7510-VCC-Project

Implementation of RAP ( Resource Adaptive Proxy)

What is Resource Adaptive Proxy

Resource Adaptive Proxy (RAP) enhances load balancing by periodically monitoring the resource and network status of each pod and worker node in a K8s cluster. It prioritizes local handling of requests and, if the local node is overloaded, intelligently forwards requests to the best-performing node in the cluster, considering resource availability. Experimental results demonstrate that RAP significantly improves throughput and reduces request latency compared to K8s' default load-balancing mechanism.

For knowing more about RAP, refer to https://www.mdpi.com/1424-8220/22/8/2869.

Adding RAP to K8s cluster

There are some prerequisites for adding RAP to your cluster. For RAP to work, you need to enable the userspace mode. Now, the userspace mode is deprecated in Kubernetes v1.23, therefore, we are using Kubernetes 1.21.10. Also, install Golang in your workstation.

  • Create 3 nodes with 1 master node and 2 worker nodes
    • We have used GCP for creating the instances at different locations and used the provided terraform code for launching the instances. To use the terraform commands:
      cd infra/
      cp tfvars.example terraform.tfvars
      
    • You need to download a service account key from GCP and set its path in the gcp_svc_key variable in the terraform.tfvars file. Also, you need to set the the gcp_project and gcp_svc_email variables in the terraform.tfvars file. Then run the following commands:
      terraform init
      terraform plan
      terraform apply
      
    • Launch the K8s cluster with kubeadm.
  • Now build the kube-proxy with the RAP code
    • Go ahead and clone the release-1.21 being checked out.
      git clone --branch release-1.21 https://github.com/kubernetes/kubernetes.git
      
    • change the code at pkg/proxy/userspace/roundrobin.go with the code provided at rap.go
    • Now build the kube-proxy with the command at the root of the repository
      make kube-proxy
      
    • Now build the docker image with the new kube-proxy.
      • Now let's go ahead and build the new docker image with the command using the provided Dockerfile
        docker build -t <your-docker-hub-username>/kube-proxy-rap:v1.21.10 .
        

        You need to run this command at the location where both Dockerfile and built kube-proxy are present. Take a look at the Dockerfile for better understanding.

      • push the new docker image to the hub so that later it can be pulled by our k8s cluster
        docker push  <your-docker-hub-username>/kube-proxy-rap:v1.21.10
        
    • Now replace the image of kube-proxy that is being used by the daemon sets created by kubeadm
      kubectl edit daemonset kube-proxy -n kube-system
      kubectl rollout restart daemonset kube-proxy -n kube-system
      
    • Now this will spin up our new kube-proxy with rap enabled, and make sure that userspace mode is enabled. Refer to this to know how to change it.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingServiceEntry = errors.New("missing service entry")
	ErrMissingEndpoints    = errors.New("missing endpoints")
)
View Source
var (
	Nodes         map[string]string
	Pods          map[string]*P
	BestNode      string
	EndpointsMap  map[string][]string
	NextEndpoints []string
	ResLists      map[string]ResourceList
)
View Source
var (
	KUBERNETES_SERVICE_HOST = os.Getenv("KUBERNETES_SERVICE_HOST")
	KUBERNETES_SERVICE_PORT = os.Getenv("KUBERNETES_SERVICE_PORT")
)
View Source
var (
	CPU_THRESHOLD    = 0.8
	MEMORY_THRESHOLD = 0.8
	WEIGHT_CPU       = 0.4
	WEIGHT_MEMORY    = 0.5
	WEIGHT_LATENCY   = 0.1
)

Functions

This section is empty.

Types

type CPU

type CPU struct {
	UsageNanoCores  int64 `json:"usageNanoCores"`
	UsageMilliCores int64 `json:"usageMilliCores"`
}

type LoadBalancerRR

type LoadBalancerRR struct {
	// contains filtered or unexported fields
}

LoadBalancerRR is a round-robin load balancer.

func NewLoadBalancerRR

func NewLoadBalancerRR() *LoadBalancerRR

NewLoadBalancerRR returns a new LoadBalancerRR.

func (*LoadBalancerRR) CleanupStaleStickySessions

func (lb *LoadBalancerRR) CleanupStaleStickySessions(svcPort proxy.ServicePortName)

func (*LoadBalancerRR) DeleteService

func (lb *LoadBalancerRR) DeleteService(svcPort proxy.ServicePortName)

func (*LoadBalancerRR) NewService

func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType v1.ServiceAffinity, ttlSeconds int) error

func (*LoadBalancerRR) NextEndpoint

func (lb *LoadBalancerRR) NextEndpoint(svcPort proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)

NextEndpoint returns a service endpoint. The service endpoint is chosen using the round-robin algorithm.

func (*LoadBalancerRR) OnEndpointsAdd

func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *v1.Endpoints)

func (*LoadBalancerRR) OnEndpointsDelete

func (lb *LoadBalancerRR) OnEndpointsDelete(endpoints *v1.Endpoints)

func (*LoadBalancerRR) OnEndpointsSynced

func (lb *LoadBalancerRR) OnEndpointsSynced()

func (*LoadBalancerRR) OnEndpointsUpdate

func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints)

func (*LoadBalancerRR) ServiceHasEndpoints

func (lb *LoadBalancerRR) ServiceHasEndpoints(svcPort proxy.ServicePortName) bool

ServiceHasEndpoints checks whether a service entry has endpoints.

type Memory

type Memory struct {
	UsageBytes     int64 `json:"usageBytes"`
	UsageMebiBytes int64 `json:"usageMebiBytes"`
}

type Node

type Node struct {
	Metadata NodeMetadata `json:"metadata"`
	Status   NodeStatus   `json:"status"`
}

type NodeAddress

type NodeAddress struct {
	Type    string `json:"type"`
	Address string `json:"address"`
}

type NodeList

type NodeList struct {
	Items []Node `json:"items"`
}

type NodeMetadata

type NodeMetadata struct {
	Name string `json:"name"`
}

type NodeStatus

type NodeStatus struct {
	Addresses []NodeAddress `json:"addresses"`
}

type P

type P struct {
	IP       string
	NodeName string
}

type Pod

type Pod struct {
	Metadata PodMetadata `json:"metadata"`
	Status   PodStatus   `json:"status"`
	Spec     PodSpec     `json:"spec"`
}

type PodList

type PodList struct {
	Items []Pod `json:"items"`
}

type PodMetadata

type PodMetadata struct {
	Name string `json:"name"`
}

type PodSpec

type PodSpec struct {
	NodeName string `json:"nodeName"`
}

type PodStatus

type PodStatus struct {
	PodIP string `json:"podIP"`
}

type ResourceList

type ResourceList struct {
	CPU     CPU
	Memory  Memory
	Latency int64
}

type Resources

type Resources struct {
	Node map[string]interface{} `json:"node"`
	Pod  map[string]interface{} `json:"pod"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳