Share
Embed
Developing Kubernetes Operators with Golang and Operator SDK
GoKonf; November23rd, 2024
Aykut Bulgu
November 23, 2024
Transcript
69 slides
-
X: @systemcraftsman | 🦋: @systemcraftsman.com Developing Kubernetes Operators with Golang
and Operator SDK Aykut M. Bulgu Principal Software Engineer @ Red Hat @SystemCraftsman -
X: @systemcraftsman | 🦋: @systemcraftsman.com About Me #oc apply -f
aykutbulgu.yaml apiVersion: redhat/v6 kind: Principal Software Engineer metadata: name: Aykut Bulgu namespace: Red Hat Ansible Engineering (previously Kafka) annotations: twitter: @SystemCraftsman bsky: @SystemCraftsman.com email: - [email protected] - [email protected] ex-organizer: Software Craftsmanship Turkey founder: System Craftsman labels: married: yes children: 2 interests: - basketball/nba/rockets - gamification - stoicism spec: replicas: 1 containers: - image: aykut:latest -
X: @systemcraftsman | 🦋: @systemcraftsman.com Schedule • What is Kubernetes?
◦ Container Orchestration ◦ Kubernetes Architecture ◦ The Controller Pattern • Extending Kubernetes ◦ Controllers ◦ Operators • Developing Operators ◦ Kubernetes Clients ◦ Operator Development Frameworks • Developing Operators with Golang ◦ Kubebuilder ◦ Operator SDK • Demo: KubeGame -
X: @systemcraftsman | 🦋: @systemcraftsman.com $ docker build -t app:v1
. $ docker run app:v1 Container Orchestration -
X: @systemcraftsman | 🦋: @systemcraftsman.com $ docker run app/frontend:v1 link-to-backend
$ docker run app/frontend:v1 link-to-backend $ docker run app/backend:v1 link-to-db-cache-messaging $ docker run app/backend:v1 link-to-db-cache-messaging $ docker run app/database:v1 $ docker run app/cache:v1 link-to-db $ docker run app/messaging:v1 Container Orchestration -
X: @systemcraftsman | 🦋: @systemcraftsman.com We need more than just
containers kubernetes ? Scheduling Decide where to deploy containers Lifecycle and health Keep containers running despite failures Discovery Find other containers on the network Monitoring Visibility into running containers Security Control who can do what Scaling Scale containers up and down Persistence Survive data beyond container lifecycle Aggregation Compose apps from multiple containers -
X: @systemcraftsman | 🦋: @systemcraftsman.com What is Kubernetes? Kubernetes is
an open-source system for automating deployment, operations, and scaling of containerized applications across multiple hosts kubernetes -
X: @systemcraftsman | 🦋: @systemcraftsman.com Kubernetes Architecture and a quick
look at the concepts. -
X: @systemcraftsman | 🦋: @systemcraftsman.com The Control Loop In robotics
and automation, a control loop is a non-terminating loop that regulates the state of a system. In Kubernetes, controllers are control loops that watch the state of your cluster, then make or request changes where needed. -
X: @systemcraftsman | 🦋: @systemcraftsman.com The Controller Pattern Actual Desired
Action 2 replicas 3 replicas Scale up v1.0 v2.0 Update Object Deleted Delete Observe Analyze Act -
X: @systemcraftsman | 🦋: @systemcraftsman.com Extending Kubernetes 1. Kubectl plugins
2. API Access extensions 3. API extensions 4. Scheduling extensions 5. Controllers and Operators 6. Network plugins 7. Device and Storage plugins https://kubernetes.io/docs/concepts/extend-kubernetes/ -
X: @systemcraftsman | 🦋: @systemcraftsman.com Controllers apiVersion: apps/v1 kind: Deployment
metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80 -
X: @systemcraftsman | 🦋: @systemcraftsman.com Developing Controllers You can develop
Controllers with any language, such as: To manage Kubernetes resources by using: • Labels • Annotations • ConfigMaps -
X: @systemcraftsman | 🦋: @systemcraftsman.com A Controller Written in Bash
apiVersion : apps/v1 kind: Deployment ... name: config-watcher-controller ... spec: serviceAccountName : config-watcher-controller containers : - name: kubeapi-proxy image: k8spatterns/kubeapi-proxy - name: config-watcher image: k8spatterns/curl-jq env: - name: WATCH_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace command: - "sh" - "/watcher/config-watcher-controller.sh" volumeMounts : ... https://k8spatterns.io/ -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operators Operator extends Controller •
Labels • Annotations • ConfigMaps Custom Resources -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operators apiVersion: apps/v1 kind: Deployment
metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80 Prometheus YAML ? ? -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operators’ Controller apiVersion: apps/v1 kind:
Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80 Prometheus YAML Prometheus Controller -
X: @systemcraftsman | 🦋: @systemcraftsman.com Options for Developing Operators •
Calling the API directly • Using the Clients • Using Operator Development Frameworks -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operator Development Frameworks • Kubebuilder
• Operator SDK • Metacontroller • Charmed Operator SDK • KubeOps -
X: @systemcraftsman | 🦋: @systemcraftsman.com Golang is faster than the
fastest! https://medium.com/swlh/cloud-native-java-vs-golang-2a72c0531b05 -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operator Development Tools for Golang
• Kubebuilder • Operator SDK • Metacontroller • Charmed Operator SDK • KubeOps -
X: @systemcraftsman | 🦋: @systemcraftsman.com Kubebuilder $ kubebuilder init …
Kubebuilder is a framework for building Kubernetes APIs using custom resource definitions (CRDs). -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operator SDK • Ansible •
Helm • Go • Java (Quarkus) Java Operator SDK (with Quarkus Extension) -
X: @systemcraftsman | 🦋: @systemcraftsman.com Operator SDK $ operator-sdk init
… … --plugins helm … --plugins ansible … --plugins quarkus -
X: @systemcraftsman | 🦋: @systemcraftsman.com Why Use Operator SDK? •
Built-in Scaffolding • Leverages Kubebuilder • Rich CLI • Operator Lifecycle Manager (OLM) Integration • Built-in Testing and Validation • Helm, Ansible, and Java (Quarkus) Support • Comprehensive Documentation and Community -
X: @systemcraftsman | 🦋: @systemcraftsman.com Key Benefits for Golang Developers
• Rapid Development: ◦ Faster project setup with less boilerplate code. • Reusability: ◦ Scaffolded code aligns with Kubernetes best practices, reducing maintenance overhead • Improved Debugging and Testing: ◦ Pre-built utilities for simulating Kubernetes clusters locally. • Production-ready Features: ◦ OLM integration and packaging make it easier to distribute Operators. -
X: @systemcraftsman | 🦋: @systemcraftsman.com KubeGame: A Gamification Operator oasis-postgres
Oasis oasis-postgres • Archaide • Chthonia • Incipio • Middle-earth -
X: @systemcraftsman | 🦋: @systemcraftsman.com Thank You! Xwitter: @systemcraftsman 🦋Bluesky:
@systemcraftsman.com Email: [email protected] Linkedin: https://www.linkedin.com/in/mabulgu/ Website: https://www.systemcraftsman.com/ GitHub: https://github.com/mabulgu