GithubHelp home page GithubHelp logo

selectel / mks-go Goto Github PK

View Code? Open in Web Editor NEW
6.0 7.0 8.0 150 KB

Go SDK for Managed Kubernetes Service

License: Apache License 2.0

Makefile 0.07% Go 99.66% Shell 0.27%
go mks kubernetes go-sdk selectel-k8s

mks-go's Introduction

mks-go: Go SDK for Managed Kubernetes Service

Go.dev reference Go Report Card Build Status Coverage Status

Package mks-go provides Go SDK to work with the Selectel Managed Kubernetes Service.

Documentation

The Go library documentation is available at go.dev.

What this library is capable of

You can use this library to work with the following objects of the Selectel Managed Kubernetes Service:

Getting started

Installation

You can install needed mks-go packages via go get command:

go get github.com/selectel/mks-go/pkg/v1/cluster github.com/selectel/mks-go/pkg/v1/task

Authentication

To work with the Selectel Managed Kubernetes Service API you first need to:

Endpoints

Selectel Managed Kubernetes Service currently has the following API endpoints:

URL Region
https://ru-1.mks.selcloud.ru/v1 ru-1
https://ru-2.mks.selcloud.ru/v1 ru-2
https://ru-3.mks.selcloud.ru/v1 ru-3
https://ru-7.mks.selcloud.ru/v1 ru-7
https://ru-8.mks.selcloud.ru/v1 ru-8
https://ru-9.mks.selcloud.ru/v1 ru-9
https://uz-1.mks.selcloud.ru/v1 uz-1

You can also retrieve all available API endpoints from the Identity catalog.

Usage example

package main

import (
	"context"
	"fmt"
	"log"

	v1 "github.com/selectel/mks-go/pkg/v1"
	"github.com/selectel/mks-go/pkg/v1/cluster"
	"github.com/selectel/mks-go/pkg/v1/kubeversion"
	"github.com/selectel/mks-go/pkg/v1/nodegroup"
	"github.com/selectel/mks-go/pkg/v1/task"
)

func main() {
	// Token to work with Selectel Cloud project.
	token := "gAAAAABeVNzu-..."

	// MKS endpoint to work with.
	endpoint := "https://ru-3.mks.selcloud.ru/v1"

	// Initialize the MKS V1 client.
	mksClient := v1.NewMKSClientV1(token, endpoint)

	// Prepare empty context.
	ctx := context.Background()

	// Get supported Kubernetes versions.
	kubeVersions, _, err := kubeversion.List(ctx, mksClient)
	if err != nil {
		log.Fatal(err)
	}
	if len(kubeVersions) == 0 {
		log.Fatal("There are no available Kubernetes versions")
	}

	// Use the first version in list.
	kubeVersion := kubeVersions[0]

	// Nodegroup with nodes based on network volumes for root partition.
	firstNodegroup := &nodegroup.CreateOpts{
		Count:            3,
		CPUs:             1,
		RAMMB:            2048,
		VolumeGB:         50,
		VolumeType:       "fast.ru-3a",
		AvailabilityZone: "ru-3a",
	}

	// Nodegroup with nodes based on local volumes for root partition.
	secondNodegroup := &nodegroup.CreateOpts{
		Count:            2,
		CPUs:             2,
		RAMMB:            4096,
		VolumeGB:         20,
		LocalVolume:      true,
		AvailabilityZone: "ru-3a",
	}

	// Build final options for a new cluster.
	createOpts := &cluster.CreateOpts{
		Name:        "test-cluster",
		KubeVersion: kubeVersion.Version,
		Region:      "ru-3",
		Nodegroups: []*nodegroup.CreateOpts{
			firstNodegroup,
			secondNodegroup,
		},
	}

	// Create a cluster.
	newCluster, _, err := cluster.Create(ctx, mksClient, createOpts)
	if err != nil {
		log.Fatal(err)
	}

	// Print cluster fields.
	fmt.Printf("Created cluster: %+v\n", newCluster)

	// Get cluster tasks.
	tasks, _, err := task.List(ctx, mksClient, newCluster.ID)
	if err != nil {
		log.Fatal(err)
	}

	// Print cluster tasks.
	for _, t := range tasks {
		fmt.Printf("Cluster task: %+v\n", t)
	}
}

mks-go's People

Contributors

bablzz avatar dkder3k avatar dstdfx avatar kolsean avatar ozerovandrei avatar pavelpereyma avatar tawr1024 avatar yaroslaver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mks-go's Issues

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.