Skip to content

jenting/k8s-crd-example

Repository files navigation

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.

brew install go
export GO111MODULE=on
go mod vendor

Docker

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

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.

brew install kubernetes-cli

Helm

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

brew install kubernetes-helm

Tiller is required. You can install it via command.

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

Draft

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

brew tap azure/draft && brew install draft

Deploy container and helm chart via Draft

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

Test CRD behavior

  1. Apply CRD deployment
kubectl apply -f patch/deploy.yaml
  1. Test default CRD behavior (GET enabled; PUT disabled)
curl -XGET -i 'localhost:8888/health'
curl -XPUT -i 'localhost:8888/health'
  1. Enable PUT method
kubectl replace -f patch/put-on.yaml
  1. Test CRD behavior (GET and enabled)
curl -XGET -i 'localhost:8888/health'
curl -XPUT -i 'localhost:8888/health'
  1. Disable PUT method
kubectl replace -f patch/put-off.yaml
  1. Test CRD behavior (GET enabled; PUT disabled)
curl -XGET -i 'localhost:8888/health'
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

draft delete

Releases

No releases published

Packages

 
 
 

Languages