All Projects → cybermaggedon → ksonnet-cheat-sheet

cybermaggedon / ksonnet-cheat-sheet

Licence: other
No description or website provided.

Projects that are alternatives of or similar to ksonnet-cheat-sheet

vuepress-plugin-example-preview
Easily display the preview of a code snippet
Stars: ✭ 15 (-16.67%)
Mutual labels:  example
waypoint-plugin-examples
An example repository that demonstrates how to create and run an external Waypoint plugin
Stars: ✭ 16 (-11.11%)
Mutual labels:  example
PoC-Examples
This repository contains synthesizable examples which use the PoC-Library.
Stars: ✭ 27 (+50%)
Mutual labels:  example
example cml
No description or website provided.
Stars: ✭ 21 (+16.67%)
Mutual labels:  example
nodejs-cron-job-must-know
it is an example of running node.js script with every certain period(cron job)
Stars: ✭ 35 (+94.44%)
Mutual labels:  example
cdi-events-playground
Demonstrates the capabilities of Java EE CDI events
Stars: ✭ 23 (+27.78%)
Mutual labels:  example
purescript-halogen-example
Sample halogen app that uses a few DSLs within the application's free monad
Stars: ✭ 62 (+244.44%)
Mutual labels:  example
play-scala-chatroom-example
Play chatroom with Scala API
Stars: ✭ 43 (+138.89%)
Mutual labels:  example
bash-streams-handbook
💻 Learn Bash streams, pipelines and redirection, from beginner to advanced.
Stars: ✭ 153 (+750%)
Mutual labels:  example
credit-card-example
An example of credit card made by using Rivets Js
Stars: ✭ 23 (+27.78%)
Mutual labels:  example
tensorflow-example-java
This is a Tensorflow Java example application what uses YOLOv2 model and Gradle for build and dependency management.
Stars: ✭ 49 (+172.22%)
Mutual labels:  example
go-grpc-bidirectional-streaming-example
gRPC bidirectional streaming example written in golang
Stars: ✭ 83 (+361.11%)
Mutual labels:  example
typeorm-example
Example Web API for TypeORM + TypeDI + routing-controllers
Stars: ✭ 27 (+50%)
Mutual labels:  example
babel-codemod-example
An example of how to use babel as a codemod
Stars: ✭ 24 (+33.33%)
Mutual labels:  example
Quarto
A working example of the Quarto board game using Elm and Netlify. An exploration of game development, OSS, and functional programming.
Stars: ✭ 15 (-16.67%)
Mutual labels:  example
cypress-example-circleci-orb
Demo of using the Cypress CircleCI Orb
Stars: ✭ 26 (+44.44%)
Mutual labels:  example
graphql-reason-server-example
An example project to write a GraphQL server using Reason
Stars: ✭ 19 (+5.56%)
Mutual labels:  example
example-orbitdb-todomvc
TodoMVC with OrbitDB
Stars: ✭ 17 (-5.56%)
Mutual labels:  example
todo-graphql-example
Example Todo app on top of json-graphql-server
Stars: ✭ 20 (+11.11%)
Mutual labels:  example
Chat-Server
Simple chatroom in C
Stars: ✭ 74 (+311.11%)
Mutual labels:  example

KSonnet

KSonnet is used to define resources for Kubernetes.

Step 1: Create a deployment

Note how this wraps a container object in a deployment object, specifying the number of replicas. The core.v1.list.new call is used to convert to a Kubernetes resource list.

// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local depl = k.extensions.v1beta1.deployment;

// Define containers
local containers = [
      container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b")
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"});

local resources = [ deployment ];

// Return list of resources.
k.core.v1.list.new(resources)

Step 2: Add environment variables

Notice how the envs array is initialised with environment variables.


// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local depl = k.extensions.v1beta1.deployment;
local env = container.envType;

// Environment variables
local envs = [

    // List of Zookeepers.
    env.new("ZOOKEEPERS", "zk1,zk2,zk3")

];

// Define containers
local containers = [
      container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b") +
      container.env(envs)
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"});

local resources = [ deployment ];

// Return list of resources.
k.core.v1.list.new(resources)

Step 3: Resource specifications

Add resource limits - notice the extra limits and requests references in the container definition.


// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local depl = k.extensions.v1beta1.deployment;
local env = container.envType;

// Environment variables
local envs = [

    // List of Zookeepers.
    env.new("ZOOKEEPERS", "zk1,zk2,zk3")

];

// Define containers
local containers = [
    container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b") +
        container.env(envs) +
        container.mixin.resources.limits({
            memory: "1G", cpu: "1.5"
        }) +
        container.mixin.resources.requests({
            memory: "1G", cpu: "1.0"
        })
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"});

local resources = [ deployment ];

// Return list of resources.
k.core.v1.list.new(resources)

Step 4: Container ports

Notice the containerPort definition which is refered to by a container.ports reference, in order to specify ports on the container.


// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local containerPort = container.portsType;
local depl = k.extensions.v1beta1.deployment;
local env = container.envType;

// Environment variables
local envs = [

    // List of Zookeepers.
    env.new("ZOOKEEPERS", "zk1,zk2,zk3")

];

// Ports used by deployments
local ports = [
    containerPort.newNamed("rest", 8080)
];

// Define containers
local containers = [
    container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b") +
        container.ports(ports) +
        container.env(envs) +
        container.mixin.resources.limits({
            memory: "1G", cpu: "1.5"
        }) +
        container.mixin.resources.requests({
            memory: "1G", cpu: "1.0"
        })
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"});

local resources = [ deployment ];

// Return list of resources.
k.core.v1.list.new(resources)

Step 5: Volumes

Notice the volumeMounts declaration referenced in container.volumeMounts, and the volumes definition which is used in the deployment definition.


// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local containerPort = container.portsType;
local mount = container.volumeMountsType;
local depl = k.extensions.v1beta1.deployment;
local env = container.envType;
local volume = depl.mixin.spec.template.spec.volumesType;
local gceDisk = volume.mixin.gcePersistentDisk;

// Environment variables
local envs = [

    // List of Zookeepers.
    env.new("ZOOKEEPERS", "zk1,zk2,zk3")

];

// Ports used by deployments
local ports = [
    containerPort.newNamed("rest", 8080)
];

// Volume mount points
local volumeMounts = [
    mount.new("data", "/data")
];

// Volumes - this invokes a GCE permanent disk.
local volumes = [
    volume.name("data") + gceDisk.fsType("ext4") +
          gceDisk.pdName("data-disk")
];

// Define containers
local containers = [
    container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b") +
        container.ports(ports) +
        container.env(envs) +
  container.volumeMounts(volumeMounts) +
        container.mixin.resources.limits({
            memory: "1G", cpu: "1.5"
        }) +
        container.mixin.resources.requests({
            memory: "1G", cpu: "1.0"
        })
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"}) +
    depl.mixin.spec.template.spec.volumes(volumes);

local resources = [ deployment ];

// Return list of resources.
k.core.v1.list.new(resources)

Step 6: Add a service

The servicePorts declaration maps the external port 8080 to the container's 8080 port. Then, service defines the service which is added to the resource array.


// Import KSonnet library
local k = import "ksonnet.beta.2/k.libsonnet";

// Specify the import objects that we need
local container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;
local containerPort = container.portsType;
local mount = container.volumeMountsType;
local depl = k.extensions.v1beta1.deployment;
local env = container.envType;
local volume = depl.mixin.spec.template.spec.volumesType;
local gceDisk = volume.mixin.gcePersistentDisk;
local svc = k.core.v1.service;
local svcPort = svc.mixin.spec.portsType;
local svcLabels = svc.mixin.metadata.labels;

// Environment variables
local envs = [

    // List of Zookeepers.
    env.new("ZOOKEEPERS", "zk1,zk2,zk3")

];

// Ports used by deployments
local ports = [
    containerPort.newNamed("rest", 8080)
];

// Volume mount points
local volumeMounts = [
    mount.new("data", "/data")
];

// Volumes - this invokes a GCE permanent disk.
local volumes = [
    volume.name("data") + gceDisk.fsType("ext4") +
        gceDisk.pdName("data-disk")
];

// Define containers
local containers = [
   container.new("gaffer", "gcr.io/trust-networks/gaffer:0.7.4b") +
        container.ports(ports) +
        container.env(envs) +
  container.volumeMounts(volumeMounts) +
        container.mixin.resources.limits({
            memory: "1G", cpu: "1.5"
        }) +
        container.mixin.resources.requests({
            memory: "1G", cpu: "1.0"
        })
];

// Define deployment with 3 replicas
local deployment = 
    depl.new("gaffer", 3, containers, {app: "gaffer"}) +
    depl.mixin.spec.template.spec.volumes(volumes);

// Ports declared on the service.
local servicePorts = [
    svcPort.newNamed("rest", 8080, 8080) + svcPort.protocol("TCP")
];

local service =
    // One service load-balanced across the replicas
    svc.new("gaffer", {app: "gaffer"}, servicePorts) +
    svcLabels({app: "gaffer", component: "gaffer"});

local resources = [ deployment, service ];

// Return list of resources.
k.core.v1.list.new(resources)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].