Skip to content
Example Kubernetes Operator
Branch: master
Clone or download
Latest commit b8b0aad May 31, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/k8s-operator-example first commit May 9, 2018
config first commit May 9, 2018
deploy refactoring May 31, 2018
pkg refactoring May 31, 2018
tmp first commit May 9, 2018
vendor first commit May 9, 2018
.gitignore refactoring May 31, 2018
Gopkg.lock first commit May 9, 2018
Gopkg.toml first commit May 9, 2018
README.md refactoring May 31, 2018

README.md

Kubernetes Operator Example Docker build

This repository contains the Kubernetes operator code for example custom resource of WeatherReport.

Initialize operator code from scratch

$ cd $GOPATH/src/github.com/onuryilmaz/
$operator-sdk new k8s-operator-example --api-version=k8s.packt.com/v1 --kind=WeatherReport

Build and push

$ operator-sdk build onuryilmaz/k8s-operator-example
$ docker push onuryilmaz/k8s-operator-example

Deploy operator

$ kubectl create -f deploy/crd.yaml
$ kubectl create -f deploy/operator.yaml

Example usage

Create custom resource

$ kubectl create -f deploy/cr.yaml

Describe status

$ kubectl describe weatherreport amsterdam-daily
Name:         amsterdam-daily
Namespace:    default
…
API Version:  k8s.packt.com/v1
Kind:         WeatherReport
Metadata:
…
Spec:
  City:  Amsterdam
  Days:  1
Status:
  Pod:    weather-report-259735700
  State:  Started

Get weather report logs

$ kubectl logs $(kubectl get weatherreport amsterdam-daily -o jsonpath={.status.pod})
 Weather report: Amsterdam, Netherlands

    \  /       Partly cloudy
  _ /"".-.     21 °C          
    \_(   ).   ↘ 19 km/h      
    /(___(__)  10 km          
               0.0 mm 

Cleanup

$ kubectl delete -f deploy/cr.yaml
$ kubectl delete -f deploy/operator.yaml
$ kubectl delete -f deploy/rbac.yaml
You can’t perform that action at this time.