What Is a Schema? From Databases to Kubernetes Explained
This article explains the concept of a schema—from its Greek origins and psychological meaning to its role as metadata in databases and Kubernetes—detailing different database schema models, Kubernetes resource definitions, and how to extend and register custom schemas in Go.
Schema originates from the Greek words "form" or "figure"; its precise definition depends on the application context. In Wikipedia it is described as "图式", a psychological structure that organizes categories of information and their relationships.
In psychology, a schema is a mental framework that organizes categories of information and their relationships.
In computing, a schema is a collection of metadata that declares elements and attributes, forming the logical view of a database and defining constraints.
Database Schema
In databases, a schema represents the logical view of the entire database, describing the shape of data and its relationships to other models, tables, and libraries. Schemas are divided into physical schemas (defining actual storage) and logical schemas (defining constraints, integrity, tables, and views).
Star schema
Snowflake schema
Fact constellation schema
Star schema uses denormalized data with a simple fact table and dimension tables. Snowflake schema normalizes dimension tables to save space and reduce redundancy. Fact constellation schema is more complex, with multiple fact tables sharing dimensions.
Kubernetes Schema
In Kubernetes, a schema refers to the metadata of resource objects defined by Group, Version, and Kind (GVK) and mapped to resources (GVR). These definitions reside in files such as staging/src/k8s.io/api/type.go and are represented in YAML manifests.
apiVersion: apps/v1
kind: Deployment
metadata:
name: ngx
namespace: default
spec:
selector:
matchLabels:
app: ngx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: ngx-schema
image: nginx
ports:
- containerPort: 80The corresponding Go structs are TypeMeta, ObjectMeta, and DeploymentSpec. Registration of resource types to the schema is performed in register.go using a SchemeBuilder.
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Deployment{},
&DeploymentList{},
&StatefulSet{},
&StatefulSetList{},
&DaemonSet{},
&DaemonSetList{},
&ReplicaSet{},
&ReplicaSetList{},
&ControllerRevision{},
&ControllerRevisionList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}To extend a resource, such as creating a StateDeployment from Deployment, one must implement deepcopy functions and register the new type.
func (in *StateDeployment) DeepCopyInto(out *StateDeployment) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
func (in *StateDeployment) DeepCopy() *StateDeployment {
if in == nil {
return nil
}
out := new(StateDeployment)
in.DeepCopyInto(out)
return out
}
func (in *StateDeployment) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}The overall flow for extending a resource includes locating the type definition in k8s.io/api/{Group}/types.go, implementing required interfaces from k8s.io/apimachinery/pkg/runtime/interfaces.go, and finally registering the new type in k8s.io/api/apps/v1/register.go.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
