ipvs

package module
v0.0.0-...-193ecd8 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: Apache-2.0 Imports: 56 Imported by: 0

README

Kube-proxy with built-in power minimization policy


Kubernetes is a portable, extensible, open source platform for facilitating declarative configuration management and automation, and managing containerized workloads and services. Kubernetes has a huge and fast-growing ecosystem with a wide range of services, support and tools available.

This document shows the steps to build and deploy kube-proxy with power minimization policy.


Prerequisites

Build kube-proxy with power minimization policy

  1. Download the Kubernetes source code

    *Since the directory structure is different in the latest version, use Kubernetes v1.19.7

    curl -L -o kubernetes.tar.gz https://github.com/kubernetes/kubernetes/archive/v1.19.7.tar.gz
    tar xvzf kubernetes.tar.gz
    
  2. Add Kube-proxy source code with power minimization policy

    git clone https://github.com/kaz260/wao-ploxy
    

    After cloning, copy to kubernetes/pkg/proxy/ipvs
    *Overwrite the file with the same name

  3. Add the required packages

    Add the prom2json package

    go get github.com/prometheus/prom2json
    
  4. Build a proxy

    Build results are output to kubernetes/cmd/proxy/

    cd ./kubernetes/cmd/proxy/
    CGO_ENABLED=0 go build -mod=mod proxy.go
    

Deploy to Kubernetes

Since there are multiple files required for deployment, it is recommended to create a suitable directory and work in it.

  1. Create a Docker image for kube-proxy

    Create Dockerfile with the following contents. The original image has been confirmed and may be up to date.

    FROM k8s.gcr.io/kube-proxy:v1.18.8
    COPY ./proxy /usr/local/bin/kube-proxy
    

    Copy the proxy built in the above steps to the same directory as the Dockerfile.
    Create an image and push it to your local repository.

    docker build -t [repository-address]/[image-name] .
    docker image push [repository-address]/[image-name]
    
  2. Preparing to start kube-proxy

    The following preparations are required for the first statup.

    • Change to a setting that users ipvs

      kubectl edit configmap kube-proxy -n kube-system
      Change two lines like below.
      mode: "ipvs"
      scheduler: "wrr"
      
    • Add role so that kube-proxy can get pods informations.

      kubectl create clusterrolebinding default-view --clusterrole=view --serviceaccount=kube-system:kube-proxy
      
    • Launch metrics-server (Kubernetes Metrics Server)

      kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
      
    • Launch tensorflow

      kubectl create -f tensorflow-server-dep.yaml
      
    • Labeling Give each node the following label;

      • ambient/max : Maximum ambinet temperature in celsius
      • ambient/min : Mimimum ambinet temperature in celsius
      • cpu1/max : Maximum CPU1 temperature in celsius
      • cpu1/min : Minimum CPU1 temperature in celsius
      • cpu2/max : Maximum CPU2 temperature in celsius
      • cpu2/min : Minimum CPU2 temperature in celsius
      • tensorflow/host: IP address of tensorflow serving
      • tensorflow/port: Port number of tensorflow serving
      • tensorflow/name: model name of tensorflow serving
  3. Launch kube-proxy

    Stop the currently running kube-proxy
    

    kubectl delete daemonset -n kube-system kube-proxy

    Lauch a new kube-proxy
    

    kubectl create -f kube-proxy.yaml

    Success if you can confirm the startup on each node with the following command
    (Successful if the pod status is [Running])
    

    kubectl get pod -n kube-system -o wide | grep kube-proxy

    If you want to see the result of ipvs, you need to install ipvsadm
    

    Installation

    sudo apt install ipset ipvsadm -y
    

    Verification

    sudo ipvsadm -Ln
    

Documentation

Index

Constants

View Source
const (

	// KubeFireWallChain is the kubernetes firewall chain.
	KubeFireWallChain utiliptables.Chain = "KUBE-FIREWALL"

	// KubeMarkMasqChain is the mark-for-masquerade chain
	KubeMarkMasqChain utiliptables.Chain = "KUBE-MARK-MASQ"

	// KubeNodePortChain is the kubernetes node port chain
	KubeNodePortChain utiliptables.Chain = "KUBE-NODE-PORT"

	// KubeMarkDropChain is the mark-for-drop chain
	KubeMarkDropChain utiliptables.Chain = "KUBE-MARK-DROP"

	// KubeForwardChain is the kubernetes forward chain
	KubeForwardChain utiliptables.Chain = "KUBE-FORWARD"

	// KubeLoadBalancerChain is the kubernetes chain for loadbalancer type service
	KubeLoadBalancerChain utiliptables.Chain = "KUBE-LOAD-BALANCER"

	// DefaultScheduler is the default ipvs scheduler algorithm - round robin.
	DefaultScheduler = "rr"

	// DefaultDummyDevice is the default dummy interface which ipvs service address will bind to it.
	DefaultDummyDevice = "kube-ipvs0"

	// MaxWeight is highest ipvs weight.(1 ~ 65535)
	MaxWeight = 100
)
View Source
const EntryInvalidErr = "error adding entry %s to ipset %s"

EntryInvalidErr indicates if an ipset entry is invalid or not

Variables

This section is empty.

Functions

func CanUseIPVSProxier

func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner) (bool, error)

CanUseIPVSProxier returns true if we can use the ipvs Proxier. This is determined by checking if all the required kernel modules can be loaded. It may return an error if it fails to get the kernel modules information without error, in which case it will also return false.

func CleanupLeftovers

func CleanupLeftovers(ipvs utilipvs.Interface, ipt utiliptables.Interface, ipset utilipset.Interface, cleanupIPVS bool) (encounteredError bool)

CleanupLeftovers clean up all ipvs and iptables rules created by ipvs Proxier.

func NewDualStackProxier

func NewDualStackProxier(
	ipt [2]utiliptables.Interface,
	ipvs utilipvs.Interface,
	ipset utilipset.Interface,
	sysctl utilsysctl.Interface,
	exec utilexec.Interface,
	syncPeriod time.Duration,
	minSyncPeriod time.Duration,
	excludeCIDRs []string,
	strictARP bool,
	tcpTimeout time.Duration,
	tcpFinTimeout time.Duration,
	udpTimeout time.Duration,
	masqueradeAll bool,
	masqueradeBit int,
	localDetectors [2]proxyutiliptables.LocalTrafficDetector,
	hostname string,
	nodeIP [2]net.IP,
	recorder record.EventRecorder,
	healthzServer healthcheck.ProxierHealthUpdater,
	scheduler string,
	nodePortAddresses []string,
	kernelHandler KernelHandler,
) (proxy.Provider, error)

NewDualStackProxier returns a new Proxier for dual-stack operation

Types

type IPGetter

type IPGetter interface {
	NodeIPs() ([]net.IP, error)
	BindedIPs() (sets.String, error)
}

IPGetter helps get node network interface IP and IPs binded to the IPVS dummy interface

type KernelHandler

type KernelHandler interface {
	GetModules() ([]string, error)
	GetKernelVersion() (string, error)
}

KernelHandler can handle the current installed kernel modules.

type LinuxKernelHandler

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

LinuxKernelHandler implements KernelHandler interface.

func NewLinuxKernelHandler

func NewLinuxKernelHandler() *LinuxKernelHandler

NewLinuxKernelHandler initializes LinuxKernelHandler with exec.

func (*LinuxKernelHandler) GetKernelVersion

func (handle *LinuxKernelHandler) GetKernelVersion() (string, error)

GetKernelVersion returns currently running kernel version.

func (*LinuxKernelHandler) GetModules

func (handle *LinuxKernelHandler) GetModules() ([]string, error)

GetModules returns all installed kernel modules.

type Proxier

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

Proxier is an ipvs based proxy for connections between a localhost:lport and services that provide the actual backends.

func NewProxier

func NewProxier(ipt utiliptables.Interface,
	ipvs utilipvs.Interface,
	ipset utilipset.Interface,
	sysctl utilsysctl.Interface,
	exec utilexec.Interface,
	syncPeriod time.Duration,
	minSyncPeriod time.Duration,
	excludeCIDRs []string,
	strictARP bool,
	tcpTimeout time.Duration,
	tcpFinTimeout time.Duration,
	udpTimeout time.Duration,
	masqueradeAll bool,
	masqueradeBit int,
	localDetector proxyutiliptables.LocalTrafficDetector,
	hostname string,
	nodeIP net.IP,
	recorder record.EventRecorder,
	healthzServer healthcheck.ProxierHealthUpdater,
	scheduler string,
	nodePortAddresses []string,
	kernelHandler KernelHandler,
) (*Proxier, error)

NewProxier returns a new Proxier given an iptables and ipvs Interface instance. Because of the iptables and ipvs logic, it is assumed that there is only a single Proxier active on a machine. An error will be returned if it fails to update or acquire the initial lock. Once a proxier is created, it will keep iptables and ipvs rules up to date in the background and will not terminate if a particular iptables or ipvs call fails.

func (*Proxier) CalcWeight

func (proxier *Proxier) CalcWeight(endpointlist []string) map[string]int

CalcWeight calculate endpoints weight

func (*Proxier) OnEndpointSliceAdd

func (proxier *Proxier) OnEndpointSliceAdd(endpointSlice *discovery.EndpointSlice)

OnEndpointSliceAdd is called whenever creation of a new endpoint slice object is observed.

func (*Proxier) OnEndpointSliceDelete

func (proxier *Proxier) OnEndpointSliceDelete(endpointSlice *discovery.EndpointSlice)

OnEndpointSliceDelete is called whenever deletion of an existing endpoint slice object is observed.

func (*Proxier) OnEndpointSliceUpdate

func (proxier *Proxier) OnEndpointSliceUpdate(_, endpointSlice *discovery.EndpointSlice)

OnEndpointSliceUpdate is called whenever modification of an existing endpoint slice object is observed.

func (*Proxier) OnEndpointSlicesSynced

func (proxier *Proxier) OnEndpointSlicesSynced()

OnEndpointSlicesSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.

func (*Proxier) OnEndpointsAdd

func (proxier *Proxier) OnEndpointsAdd(endpoints *v1.Endpoints)

OnEndpointsAdd is called whenever creation of new endpoints object is observed.

func (*Proxier) OnEndpointsDelete

func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints)

OnEndpointsDelete is called whenever deletion of an existing endpoints object is observed.

func (*Proxier) OnEndpointsSynced

func (proxier *Proxier) OnEndpointsSynced()

OnEndpointsSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.

func (*Proxier) OnEndpointsUpdate

func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints)

OnEndpointsUpdate is called whenever modification of an existing endpoints object is observed.

func (*Proxier) OnNodeAdd

func (proxier *Proxier) OnNodeAdd(node *v1.Node)

OnNodeAdd is called whenever creation of new node object is observed.

func (*Proxier) OnNodeDelete

func (proxier *Proxier) OnNodeDelete(node *v1.Node)

OnNodeDelete is called whenever deletion of an existing node object is observed.

func (*Proxier) OnNodeSynced

func (proxier *Proxier) OnNodeSynced()

OnNodeSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.

func (*Proxier) OnNodeUpdate

func (proxier *Proxier) OnNodeUpdate(oldNode, node *v1.Node)

OnNodeUpdate is called whenever modification of an existing node object is observed.

func (*Proxier) OnServiceAdd

func (proxier *Proxier) OnServiceAdd(service *v1.Service)

OnServiceAdd is called whenever creation of new service object is observed.

func (*Proxier) OnServiceDelete

func (proxier *Proxier) OnServiceDelete(service *v1.Service)

OnServiceDelete is called whenever deletion of an existing service object is observed.

func (*Proxier) OnServiceSynced

func (proxier *Proxier) OnServiceSynced()

OnServiceSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.

func (*Proxier) OnServiceUpdate

func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service)

OnServiceUpdate is called whenever modification of an existing service object is observed.

func (*Proxier) Score

func (proxier *Proxier) Score(nodeName string) int64

Score calculates node score. The returned score is the amount of increase in current power consumption.

func (*Proxier) Sync

func (proxier *Proxier) Sync()

Sync is called to synchronize the proxier state to iptables and ipvs as soon as possible.

func (*Proxier) SyncLoop

func (proxier *Proxier) SyncLoop()

SyncLoop runs periodic work. This is expected to run as a goroutine or as the main loop of the app. It does not return.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL