Giter Club home page Giter Club logo

vk8s's Introduction

vk8s

Setting up a virtual Kubernetes cluster inside a Docker container for integration testing.

Note: A virtual Kubernetes cluster consists of virtual nodes, once newly-created pods are assigned to these nodes, pods will immediately be reported as RUNNING status, but in reality no any container of pods has been created and run, this is a trick achieved by virtual-kubelet.

Examples

Use in Shell

# Run vk8s in background
docker run --name=vk8s -e TTL=300 -d --rm -p 9191:8080 ghcr.io/go-tk/vk8s:v0.2.1

# Ensure vk8s is ready (~15s)
docker exec vk8s ./wait-for-ready.bash

# Create a pod
kubectl -s http://127.0.0.1:9191 apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
EOF

# List pods
kubectl -s http://127.0.0.1:9191 get pods

# Clean up
docker rm -f vk8s

Use in Go

package xxx

import (
        "context"
        "testing"
        "time"

        "github.com/go-tk/vk8s"
        "k8s.io/client-go/kubernetes"
        "k8s.io/client-go/tools/clientcmd"
)

func TestXXX(t *testing.T) {
        kubeConfigData := vk8s.SetUp(context.Background(), 5*time.Minute, t)

        config, err := clientcmd.RESTConfigFromKubeConfig(kubeConfigData)
        if err != nil {
                t.Fatal(err)
        }

        clientset, err := kubernetes.NewForConfig(config)
        if err != nil {
                t.Fatal(err)
        }

        _ = clientset // Do anything you want to do with clientset
}

vk8s's People

Contributors

roy2220 avatar

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.