Skip to content
my first kubernetes operator
Branch: master
Clone or download
Latest commit ff882b2 Apr 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build init Apr 11, 2019
cmd/manager refactor Apr 24, 2019
deploy refactor Apr 24, 2019
examples examples Apr 24, 2019
pkg refactor Apr 24, 2019
vendor refactor Apr 24, 2019
version init Apr 11, 2019
.gitignore init Apr 11, 2019
.project add samples Apr 11, 2019
Gopkg.lock init Apr 11, 2019
Gopkg.toml init Apr 11, 2019
README.md docu Apr 25, 2019

README.md

about Centos k8s controllers

CRDs are only a mean to specify a configuration, though. The cluster still needs controllers to monitor its state and reconcile the resource to match with the configuration (make consistent with another).Operators are controllers working in association with custom resources to perform tasks that generally… “human operators” have to take care of. Operators are the CRDs associated with controllers which observe and act upon changes in the configuration or changes in the state of the cluster The etcd operator manages etcd clusters deployed to Kubernetes and automates tasks related to operating an etcd cluster.

how this project was created

log on to katacoda k8s course site

install go

install dep

install sdk

Bootstrapping the Go project

  • git config --global user.email robert.rong@agile-solutions.ch
  • git config --global user.name agilesolutions
  • mkdir -p $GOPATH/src/github.com/agilesolutions/
  • cd $GOPATH/src/github.com/agilesolutions/
  • operator-sdk new podset-operator
  • tree -I vendor

Add a new API for the custom resource PodSet

  • cd podset-operator
  • operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=PodSet

Add a new controller that watches for PodSet

  • operator-sdk add controller --api-version=app.example.com/v1alpha1 --kind=PodSet

build the Docker image using the Operator SDK

  • operator-sdk build agilesolutions/podset-operator
  • docker login -u agilesolutions
  • docker push agilesolutions/podset-operator

to run this stuff

Setup Service Account

  • kubectl create -f deploy/service_account.yaml

Setup RBAC

  • kubectl create -f deploy/role.yaml
  • kubectl create -f deploy/role_binding.yaml

Setup the CRD

  • kubectl create -f deploy/crds/app_v1alpha1_podset_crd.yaml

Deploy the podset-operator

  • kubectl create -f deploy/operator.yaml

check the CRD

  • kubectl get crd podsets.app.example.com

check the operator controller

  • kubectl get pods

check if there's a CR using the CRD fullname...

  • kubectl get podsets.app.example.com

create our PodSet resource configured with 4 replicas

  • kubectl apply -f examples/replicas4.yaml
  • kubectl get pods -l app=example-podset
  • kubectl delete pods -l app=example-podset
  • kubectl get pods -l app=example-podset
  • kubectl apply -f examples/replicas2.yaml
  • kubectl get pods -l app=example-podset
  • kubectl describe podset/example-podset
  • kubectl delete podset example-podset
  • kubectl get pods -l app=example-podset

more reading on this

writing operators

relevant KUBECTL commands

  • kubectl cluster-info
  • kubectl get nodes
  • kubectl config set-context $(kubectl config current-context) --namespace=default
  • kubectl config view | grep namespace:
  • kubectl get nodes
  • kubectl get deployment componenta -o=custom-columns=:.metadata.annotations.contact --no-headers- kubectl get pods -l app=sa-log --show-labels
  • kubectl get pods --all-namespaces
  • kubectl get pods -n default
  • kubectl get namespaces
  • kubectl get svc -n istio-system -l istio=ingressgateway
  • kubectl get svc -n istio-system -l istio=ingressgateway -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
  • kubectl get pods -o wide
  • kubectl get -f pod.yaml -o json
  • kubectl get rc,services
  • kubectl run first-deployment --image=katacoda/docker-http-server --port=80 --replicas=1
  • kubectl expose deployment first-deployment --port=80 --type=NodePort
  • export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')
  • kubectl apply -f /opt/kubernetes-dashboard.yaml
  • kubectl get deployments
  • kubectl describe deployment http
  • kubectl run httpexposed --image=katacoda/docker-http-server:latest --replicas=1 --port=80 --hostport=8001
  • kubectl scale --replicas=3 deployment http
  • kubectl create -f deployment.yaml
  • kubectl get deployment
  • Get a Shell to a Running Container
  • Istio traffic management
You can’t perform that action at this time.