项目作者: hsiaoairplane

项目描述 :
Kubernetes CRD example
高级语言: Go
项目地址: git://github.com/hsiaoairplane/k8s-crd-example.git
创建时间: 2019-01-22T20:50:56Z
项目社区:https://github.com/hsiaoairplane/k8s-crd-example

开源协议:

下载


Kubernetes Custom Resource Definition

What is this?

An example of a custom Kubernetes controller that with HTTP router endpoint /health, by default GET method supports. But the HTTP method could be changed via Custom Resource Definition to enable/disable other HTTP method on endpoint /health.

Development environment

Golang

Ensure you got Go 1.11 installed with go mod support.

  1. brew install go
  2. export GO111MODULE=on
  3. go mod vendor

Docker

Docker is required. You may download and install the installation package, or install it via Homebrew Cask.

  1. brew cask install docker

Kubernetes cluster

kubernetes is required. You may setup a K8s cluster by docker-for-desktop or minikube

Kubectl

kubectl is required. You could install kubectl, or install it via Homebrew.

  1. brew install kubernetes-cli

Helm

Helm is required. You may download and install the binary releases, or install it via Homebrew.

  1. brew install kubernetes-helm

Tiller is required. You can install it via command.

  1. kubectl -n kube-system create sa tiller
  2. kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
  3. helm init --service-account tiller

Draft

Draft is required. You may download and install the binary releases, or install it via Homebrew.

  1. brew tap azure/draft && brew install draft

Deploy container and helm chart via Draft

  1. Set up draft (after Development environment are prepared)
  1. draft init
  1. To deploy the application to a Kubernetes dev sandbox, accessible using draft connect over a secured tunnel
  1. draft up
  1. Show information
  1. helm list
  2. kubectl get all

Test CRD behavior

  1. Apply CRD deployment
  1. kubectl apply -f patch/deploy.yaml
  1. Test default CRD behavior (GET enabled; PUT disabled)
  1. curl -XGET -i 'localhost:8888/health'
  2. curl -XPUT -i 'localhost:8888/health'
  1. Enable PUT method
  1. kubectl replace -f patch/put-on.yaml
  1. Test CRD behavior (GET and enabled)
  1. curl -XGET -i 'localhost:8888/health'
  2. curl -XPUT -i 'localhost:8888/health'
  1. Disable PUT method
  1. kubectl replace -f patch/put-off.yaml
  1. Test CRD behavior (GET enabled; PUT disabled)
  1. curl -XGET -i 'localhost:8888/health'
  2. curl -XPUT -i 'localhost:8888/health'
  1. You could try other HTTP method on/off behavior with patch/xxx-on.yaml or patch/xxx-off.yaml

Clean k8s enviroment

  1. draft delete