0
0
Kubernetesdevops~10 mins

Operator SDK basics in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Operator SDK basics
Start: Create Operator Project
Define API & Controller
Build Operator Binary
Deploy Operator to Cluster
Operator Watches Resources
Reconcile Loop Executes
Update Cluster State
End
This flow shows the main steps in using Operator SDK: create project, define API, build, deploy, watch resources, reconcile, and update cluster.
Execution Sample
Kubernetes
operator-sdk init --domain=example.com --repo=github.com/example/memcached-operator
operator-sdk create api --group=cache --version=v1 --kind=Memcached
make install
make run
This sequence initializes an operator project, creates an API for Memcached, installs CRDs, and runs the operator locally.
Process Table
StepCommand/ActionEffectOutput/Result
1operator-sdk init --domain=example.com --repo=github.com/example/memcached-operatorCreates operator project structureProject scaffold created with Go modules and config files
2operator-sdk create api --group=cache --version=v1 --kind=MemcachedGenerates API and controller filesAPI types and controller skeleton generated
3make installInstalls CRDs to clusterCRDs installed, cluster ready to recognize Memcached resources
4make runRuns operator locallyOperator starts, watches Memcached resources, logs events
5Create Memcached CR in clusterTriggers reconcile loopOperator detects new resource and acts accordingly
6Operator updates cluster stateCreates/updates pods or servicesMemcached pods deployed or updated
7Operator continues watchingReconciles on changesCluster state stays in desired condition
8ExitStop operatorOperator process ends
💡 Operator stops when user interrupts or process ends
Status Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Project FilesNoneAPI and controller files createdOperator binary readyOperator running and watchingOperator stopped
Cluster StateNo CRDsCRDs installedNo Memcached resourcesMemcached pods createdPods running as expected
Operator StatusNot runningNot runningRunningReconcilingStopped
Key Moments - 3 Insights
Why do we run 'make install' before running the operator?
Because 'make install' installs the Custom Resource Definitions (CRDs) into the cluster, so the cluster knows about the new resource types the operator manages. Without this, the operator cannot watch or manage those resources (see execution_table step 3).
What happens when we create a Memcached custom resource in the cluster?
The operator detects the new resource and triggers the reconcile loop to create or update the necessary pods or services to match the desired state (see execution_table step 5 and 6).
Why does the operator keep running after deploying resources?
Because it continuously watches for changes in the resources it manages and reconciles the cluster state to keep it as desired (see execution_table step 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the effect of the 'operator-sdk create api' command at step 2?
AInstalls CRDs to cluster
BGenerates API and controller files
CRuns the operator locally
DCreates operator project structure
💡 Hint
Check the 'Effect' column in execution_table row 2
At which step does the operator start watching Memcached resources?
AStep 3
BStep 5
CStep 4
DStep 6
💡 Hint
Look at the 'Output/Result' column in execution_table step 4
If we skip 'make install', what will happen when we run the operator?
AOperator will fail to recognize custom resources
BOperator will run normally and manage resources
COperator will create CRDs automatically
DOperator will install CRDs during runtime
💡 Hint
Refer to key_moments explanation about 'make install' and execution_table step 3
Concept Snapshot
Operator SDK basics:
- Use 'operator-sdk init' to start a project
- 'operator-sdk create api' generates API and controller
- 'make install' installs CRDs to cluster
- 'make run' runs operator locally
- Operator watches custom resources and reconciles
- Keeps cluster state as desired continuously
Full Transcript
The Operator SDK basics start with creating a new operator project using 'operator-sdk init'. Then, you generate the API and controller code with 'operator-sdk create api'. Next, you install the Custom Resource Definitions (CRDs) into your Kubernetes cluster using 'make install' so the cluster understands your new resource types. After that, you run the operator locally with 'make run', which starts watching for your custom resources. When you create a custom resource like Memcached, the operator detects it and runs the reconcile loop to update the cluster state, such as creating pods. The operator keeps running to watch for changes and maintain the desired state. You stop the operator when you want to end the process.