Why Kubernetes Is the Next‑Generation OS and How to Build Your First Operator
This article explains why Kubernetes should be seen as a next‑generation operating system, walks through a simple nginx deployment using declarative YAML, introduces the concepts of CRDs, custom controllers and Operators, and shows how to create and manage resources such as etcd clusters and virtual machines within Kubernetes.
Kubernetes as a declarative operating system
Kubernetes provides a virtually unlimited pool of resources and a declarative, distributed‑system‑native API that can serve as the primary platform for developing, testing, and deploying applications, while traditional Linux/Windows VMs remain as low‑level operating systems.
Simple "Hello World" deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
selector:
matchLabels:
app-name: my-nginx
template:
metadata:
labels:
app-name: my-nginx
spec:
containers:
- name: nginx
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app-name: my-nginx
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80Apply the manifest with kubectl apply -f ./nginx.yaml. Kubernetes creates three nginx pods, a Service that load‑balances traffic, and a stable DNS name for the service.
Benefits of declarative deployment
Automatic replica management – failed pods are recreated.
Service abstraction provides load balancing and DNS without manual configuration.
Rolling updates and scaling are performed by editing the YAML and re‑applying.
Extending Kubernetes with Operators
Operators combine a CustomResourceDefinition (CRD) and a custom controller to encapsulate domain‑specific logic. Example: an etcd cluster operator.
apiVersion: "etcd.database.coreos.com/v1beta2"
kind: "EtcdCluster"
metadata:
name: "example-etcd-cluster"
spec:
size: 3The operator watches these custom resources and creates the required etcd pods automatically.
Operator core reconcile logic (pseudo‑code)
// Reconcile is the main operator loop
func Reconcile(crName string) error {
// Fetch the custom resource submitted by the user
cr := client.getCR(crName)
// Derive the desired Deployment from the CR
desired := getDesiredDeployment(client, cr)
// Get the current Deployment in the cluster
current := client.GetDeployment(crName)
// Update if there is a drift
if diff(desired, current) {
return client.UpdateDeployment(desired)
}
return nil
}Unified API via the Kubernetes API server for all components.
Leverages community‑maintained operators (e.g., MySQL‑operator) to compose complex applications.
Reduces operational burden by handling lifecycle, scaling, and failover automatically.
Community operators
Curated list of high‑quality operators: https://github.com/operator-framework/awesome-operators
Pod as a VM‑like environment
apiVersion: v1
kind: Pod
metadata:
name: my-vm-1
spec:
containers:
- name: vm
image: ubuntuCustom images can be built by adding a Dockerfile to the project and running make image.
Getting started with a cluster
For hands‑on practice, run Minikube locally or provision a Kubernetes cluster from a cloud provider.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
