Giter Club home page Giter Club logo

gitops-energy-usage-notes's Introduction

Energy-efficient Kubernetes

This project aims to measure and compare the energy consumption of snowflake clusters versus that of Flux-based GitOps clusters.

Another aim is to create a reference architecture for measuring the energy consumption of cloud-native processes using cloud-native tools.

The focus here is on energy usage rather than, for example, marginal emissions estimates. That being said, energy metrics could be used to deduce carbon emissions.

This project could be used as the base model for conducting Life Cycle Assessment (LCAs) of any cloud-native software that runs on a Pod.


[Update] The latest version of this project can be found here: https://github.com/nikimanoledaki/sustainability-journey-with-gitops


Resources

Get Started with Local Development

OS

Linux

For Linux users, create a cluster directly with minikube.

MacOS

For MacOS user, the dependencies are:

  • Virtualbox - brew install --cask virtualbox
  • Vagrant - brew install --cask vagrant

Then, use this Vagrantfile, and spin up a microVM with Flintlock:

vagrant up
vagrant ssh

Note: The Vagrantfile allocates 8GB for the microVM. The microVM itself is very lightweight but the cluster that will be allocated 6GB. Ensure you have enough RAM.

Start a Kubernetes cluster with minikube

First, create a minikube cluster:

minikube start --container-runtime=containerd --memory=6g --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.bind-address=0.0.0.0 --extra-config=controller-manager.bind-address=0.0.0.0
minikube addons disable metrics-server

You will need to install kube-prometheus and kepler on your cluster.

To do this in a GitOps way, bootstrap Flux on your cluster.

Then, copy the Flux manifests for kube-prometheus and kepler to your config repo. Flux will automatically reconcile these for you.

Get Started in a Cloud Environment

### Example: Use Equinix for the Baremetal Host Liquid Metal can be used to create microVMs on any baremetal machine.

Follow thse instructions for how to use Equinix as a host baremetal machine.

Use this Terraform manifest, which contains the necessary configuration to be used as a host for Kepler.

Set up a Kubernetes management cluster locally with CAPI. Then, set up more clusters hosted on microVMs with CAPMVM.

gitops-energy-usage-notes's People

Contributors

callisto13 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

gitops-energy-usage-notes's Issues

Provision KVM instance to use Kepler

What is Kepler?

Kepler (Kubernetes-based Efficient Power Level Exporter) uses eBPF to probe energy related system stats and exports as Prometheus metrics

It can help us get energy consumption metrics from a cluster.

Kepler requirements as outlined here:

  • Support for cgroup v2
  • Support for kernel-devel extensions
  • Provide the kernel headers (required by eBPF)
  • Kernel with eBPF support

For example, Kepler on Openshift has already been integrated and works. This integration can be used as an example of what configuration is needed, e.g.:

  kernelArguments:
    - systemd.unified_cgroup_hierarchy=1
    - cgroup_no_v1="all"
  extensions:
  - kernel-devel

TODO (before KubeCon)

Long-term TODO:

Deployment is unmarshalled with empty/null fields

Current Deployment that is created looks like this:

typemeta:
  kind: Deployment
  apiversion: apps/v1
objectmeta:
  name: 09-09-2022-18-17-02
  generatename: ""
  namespace: ""
  selflink: ""
  uid: ""
  resourceversion: ""
  generation: 0
  creationtimestamp:
    time: {}
  deletiontimestamp: null
  deletiongraceperiodseconds: null
  labels:
    app: date-setter
  annotations: {}
  ownerreferences: []
  finalizers: []
  managedfields: []
spec:
  replicas: 1
  selector:
    matchlabels:
      app: date-setter
    matchexpressions: []
  template:
    objectmeta:
      name: ""
      generatename: ""
      namespace: ""
      selflink: ""
      uid: ""
      resourceversion: ""
      generation: 0
      creationtimestamp:
        time: {}
      deletiontimestamp: null
      deletiongraceperiodseconds: null
      labels:
        app: date-setter
      annotations: {}
      ownerreferences: []
      finalizers: []
      managedfields: []
    spec:
      volumes: []
      initcontainers: []
      containers:
      - name: date-setter
        image: docker.io/niki2401/date-setter:latest
        command: []
        args: []
        workingdir: ""
        ports:
        - name: ""
          hostport: 0
          containerport: 8080
          protocol: ""
          hostip: ""
        envfrom: []
        env: []
        resources:
          limits: {}
          requests: {}
        volumemounts: []
        volumedevices: []
        livenessprobe: null
        readinessprobe: null
        startupprobe: null
        lifecycle: null
        terminationmessagepath: ""
        terminationmessagepolicy: ""
        imagepullpolicy: ""
        securitycontext: null
        stdin: false
        stdinonce: false
        tty: false
      ephemeralcontainers: []
      restartpolicy: ""
      terminationgraceperiodseconds: null
      activedeadlineseconds: null
      dnspolicy: ""
      nodeselector: {}
      serviceaccountname: ""
      deprecatedserviceaccount: ""
      automountserviceaccounttoken: null
      nodename: ""
      hostnetwork: false
      hostpid: false
      hostipc: false
      shareprocessnamespace: null
      securitycontext: null
      imagepullsecrets: []
      hostname: ""
      subdomain: ""
      affinity: null
      schedulername: ""
      tolerations: []
      hostaliases: []
      priorityclassname: ""
      priority: null
      dnsconfig: null
      readinessgates: []
      runtimeclassname: null
      enableservicelinks: null
      preemptionpolicy: null
      overhead: {}
      topologyspreadconstraints: []
      sethostnameasfqdn: null
      os: null
      hostusers: null
  strategy:
    type: ""
    rollingupdate: null
  minreadyseconds: 0
  revisionhistorylimit: null
  paused: false
  progressdeadlineseconds: null
status:
  observedgeneration: 0
  replicas: 0
  updatedreplicas: 0
  readyreplicas: 0
  availablereplicas: 0
  unavailablereplicas: 0
  conditions: []
  collisioncount: null

Setup local dev env

  • Create a cluster on KVM for local dev env
  • Setup Kepler, Prometheus, Grafana
  • Meet requirements for Kepler on KVM
  • Get cluster-wide metrics locally

[EPIC] Design energy-consumption tests

date-setter Go app

  • Go server that takes current date, sets it as a deployment.yaml metadata name, and marshals it into YAML

GitOps arch

  • Script to bootstrap Flux to watch this repo's deployment.yaml
  • #4

Snowflake arch

Setup energy metrics

Cron job

  • Schedule job that runs date-setter app and should trigger Flux reconciliation & GitHub Action workflow

Run on EC2 instance

Acceptance Criteria

This is to find an AWS instance that meets the following requirements:

  • will run KVM
  • can be used as instances to run a Kubernetes cluster, ideally in a EKS self-managed nodegroup using eksctl

Suggestions

  • Check out this demo on installing KVM on AWS.
  • On the other hand, the demo linked above recommends i3.metal. Try eksctl create cluster with self-managed nodegroups and specify i3.metal as the instance.
  • Question: Is baremetal necessary to run KVM? Can these reqs be met on non-baremetal instances? They can be quite expensive so it would be nice to use something cheaper.
  • EKS works with a m5.metal instance so we could use that.
  • If nothing else works, here is a list of EC2 instances (search those with .metal)

Add Kepler prerequisites on Flintlock Vagrantfile

Add the following to this Vagrantfile:

Example from Openshift:

---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  name: 50-master-kernel-devel-cgroupv2
  labels:
    machineconfiguration.openshift.io/role: master
spec:
  kernelArguments:
    - systemd.unified_cgroup_hierarchy=1
    - cgroup_no_v1="all"
  extensions:
  - kernel-devel

Add Helm chart for Kepler

Open an issue / PR to add that to their repo :)
Perhaps include instructions on how to use Flux to add Kepler to a cluster. ✨

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.