# Create an hello-operator project that defines the App CR.
$ mkdir -p $HOME/projects/example-inc/
# Create a new hello-operator project
$ cd $HOME/projects/example-inc/
$ operator-sdk new hello-operator --repo github.com/example-inc/hello-operator
$ cd hello-operator
# Add a new API for the custom resource AppService
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
# Add a new controller that watches for AppService
$ operator-sdk add controller --api-version=app.example.com/v1alpha1 --kind=AppService
# Build and push the hello-operator image to a public registry
$ operator-sdk build hub.docker.com/konfortes/hello-operator
# Login to public registry
$ docker login
$ docker tag <built image id> konfortes/hello-operator:latest
# Push image
$ docker push konfortes/hello-operator
# Update the operator manifest to use the built image name
# On OSX use:
$ sed -i "" 's|REPLACE_IMAGE|konfortes/hello-operator:latest|g' deploy/operator.yaml
# 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.example.com_appservices_crd.yaml
# Deploy the hello-operator
$ kubectl create -f deploy/operator.yaml
# Create an AppService CR
# The default controller will watch for AppService objects and create a pod for each CR
$ kubectl create -f deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml
# Verify that a pod is created
$ kubectl get pod -l app=example-appservice
NAME READY STATUS RESTARTS AGE
example-appservice-pod 1/1 Running 0 1m
# Test the new Resource Type
$ kubectl describe appservice example-appservice
Name: example-appservice
Namespace: myproject
Labels: <none>
Annotations: <none>
API Version: app.example.com/v1alpha1
Kind: AppService
Metadata:
Cluster Name:
Creation Timestamp: 2018-12-17T21:18:43Z
Generation: 1
Resource Version: 248412
Self Link: /apis/app.example.com/v1alpha1/namespaces/myproject/appservices/example-appservice
UID: 554f301f-0241-11e9-b551-080027c7d133
Spec:
Size: 3
# Cleanup
$ kubectl delete -f deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml
$ kubectl delete -f deploy/operator.yaml
$ kubectl delete -f deploy/role.yaml
$ kubectl delete -f deploy/role_binding.yaml
$ kubectl delete -f deploy/service_account.yaml
$ kubectl delete -f deploy/crds/app.example.com_appservices_crd.yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
konfortes/hello-operator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
k8s operator using operator-sdk
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published