Skip to content

gympass/ocean-right-sizing-mutator

 
 

Repository files navigation

Ocean Resource Mutator

Spot resource mutator is a server which intercepts API requests and validates resource requirements definition within the Pod Spec. This is done by configuring the dynamic admission controller to send webhook mutating requests to this server before the request is being persisted in K8s. The server integrates with your Spot account and validates the resource requirements defined by the user. If there is no definition, the resource will be mutated with the appropriate values from the Spot backend recommended by Ocean.

Contents

Requirements

  • The target cluster must be integrated with Ocean.
  • The mutator requires a Spot account ID from the previously installed Ocean controller.

The deployment process will generate a Self Signed Certificate and will create a secret in your cluster for the resource mutator server

make gencerts-deploy

Installation

To use the Ocean Right-Sizing Mutator, you need to perform the following 2 small changes:

  1. Add the following label: value to any Namespace that you want the mutating webhook to intercept - spot.io/mutate-resource: enabled. Only Namespaces with this label will be processed as part of the mutating webhook configuration (see file - mutatingwebhook-template.tmpl)
  2. Add the following label to your deployment file - spot.io/mutate-resource: enabled. The webhook server will only get tomutate deployment that contains this label (based on the MutatingWebhookConfiguration object configured while deploying the webhook). The webhook server will mutate the resource requests with recommendations from Ocean Right-Sizing API.

Here is an example of a deployment with the annotation above:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nodejs-backend
  labels:
    app: nodejs-backend
    spot.io/mutate-resource: enabled
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-backend
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nodejs-backend
    spec:
      containers:
        - image: tduek/nodejs-demo:latest
          imagePullPolicy: Always
          name: nodejs-backend
          ports:
            - containerPort: 3000
              protocol: TCP
          resources:
            requests:
              memory: "200Mi"
              cpu: "200m"
            limits:
              memory: "256Mi"
              cpu: "400m"

Run Locally

To run the webhook server locally, create the certs for the server:

make gencerts-deploy

In addition to the certs above, the following environment variables should be set:

  • SPOTINST_CONTROLLER_ID - the controller id for the Ocean cluster
  • SPOTINST_TOKEN - token for Spot API
  • SPOTINST_ACCOUNT - Spot account which the ocean cluster exists in

With the above environment variables set, run the server with:

make runlocal

Documentation

For a comprehensive documentation, check out the API documentation.

Getting Help

We use GitHub issues for tracking bugs and feature requests. Please use these community resources for getting help:

Community

Contributing

Please see the contribution guidelines.

License

Code is licensed under the Apache License 2.0. See NOTICE.md for complete details, including software and third-party licenses and permissions.

Releases

No releases published

Packages

No packages published

Languages

  • Go 66.1%
  • Shell 23.7%
  • Makefile 7.3%
  • Dockerfile 2.9%