Giter Club home page Giter Club logo

kube-crd's Introduction

Kubernetes Custom Resources (CRD) Tutorial

Tutorial for building Kubernetes Custom Resources (CRD) extensions you can see the full tutorial documentation in: The New Stack

Note: CustomResourceDefinition (CRD) is the successor of the deprecated ThirdPartyResource.

this example is based on Kubernetes apiextensions-apiserver example

Organization

the example contain 3 files:

  • crd - define and register our CRD class
  • client - client library to create and use our CRD (CRUD)
  • kube-crd - main part, demonstrate how to create, use, and watch our CRD

Running

# assumes you have a working kubeconfig, not required if operating in-cluster
go run *.go -kubeconf=$HOME/.kube/config

kube-crd

kube-crd demonstrates the CRD usage, it shoes how to:

  1. Connect to the Kubernetes cluster
  2. Create the new CRD if it doesn't exist
  3. Create a new custom client
  4. Create a new Example object using the client library we created
  5. Create a controller that listens to events associated with new resources

The example CRD is in the following structure:

type Example struct {
      meta_v1.TypeMeta   `json:",inline"`
      meta_v1.ObjectMeta `json:"metadata"`
      Spec               ExampleSpec   `json:"spec"`
      Status             ExampleStatus `json:"status,omitempty"`
}
type ExampleSpec struct {
      Foo string `json:"foo"`
      Bar bool   `json:"bar"`
      Baz int    `json:"baz,omitempty"`
}

type ExampleStatus struct {
      State   string `json:"state,omitempty"`
      Message string `json:"message,omitempty"`
}
  • The Metadata part contain standard Kubernetes properties like name, namespace, labels, and annotations
  • The Spec contain the desired resource configuration
  • The Status part is usually filled by the controller in response to Spec updates

kube-crd's People

Contributors

yaronha avatar pavius avatar

Watchers

James Cloos avatar wangweihong avatar  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.