Skip to content

onuryilmaz/k8s-operator-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Example Kubernetes Operator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published