A CUE Based Approach to Kubernetes Manifest Abstractions #806
Replies: 2 comments 3 replies
-
I think helper functions would be a lot more useful than abstractions. Sometimes it seems like kubernetes resources allow you to specify way too many properties that you don't care about, but you always end up needing to break out and configure one thing or another. I've been doing kubernetes stuff since 1.4 and you definitely want full access to the resource properties. Using helper functions instead of full blown abstractions can help you reduce boilerplate even when you are customizing one thing or another. if abstractions are wanted I think that would be something that should be stored in the repo for each orgs kubernetes setup, that way they can customize those abstractions to be what they need. |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#806. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
-
The below discusses a CUE based approach to generate Kubernetes manifests from one or more abstractions provided to users.
The intention of this is to receive feedback and suggestions from the CUE community.
Goals
The goals of the abstraction framework are:
Future goals of adopting CUE, but are not immediate, may be:
Non-Goals
The abstraction framework does not, at least yet:
Design
Abstractions
Note
Application
The reason this is expressed as an
application
and not aDeployment
is because the result is a set of Kubernetes resources, rather than just a singleDeployment
. The comment in the below example shows which resources are generated.See the appendix for complete examples of how a user would declare an
application
, and what the result would be.It is noted that some of the syntax here may be intimidating to users who are used to configuring Kubernetes in pure YAML. For example, how would a user, just by reading this definition, know how to declare environment variables (especially when using
envSpec
),ports
, orvolumes
.In practice, the configuration a user would write is actually quite simple, but users will rely on good documentation and examples to get started.
The same concerns can also be applied to
Jobs
andCronJobs
, mentioned below.Job
Similarly to an
application
, more than just aJob
resource is generated, but the naming is general enough that this distinction does not matter.See the appendix for complete examples of how a user would declare a job, and what the result would be.
Cron
Similarly to a
Job
, more than just aCronJob
resource is generated. Again, the naming is general enough that this distinction does not matter.A
CronJob
is a superset of aJob
, adding only two additional fields:See the appendix for complete examples of how a user would declare a
cronJob
, and what the result would be.Config Map
The abstraction of a
ConfigMap
exposed to the user is as simple as:A user would then express a
configMap
like so:As a
ConfigMap
can be used by multiple applications within a namespace, there’s no simple way of binding it to a particular application, unless it is bound to all of them. There are also different ways in which aConfigMap
can be used (e.g. as environment variables or a volume mount)As such, the user will have to reference it by the application(s) that require it, how it is intended to be used:
Service
Services are not an abstraction by themself. They are generated according to the ports listed under an
application
’sexpose
field. This way, the user does not need to bind the service to thePod
, and assign ports in the container.A user would express which ports they want to expose the application on:
Which will generate the following:
Beyond Abstractions
While the immediate goal is to provide abstractions, in the future it would be possible to provide CUE as the configuration language for all Kubernetes manifests.
Users would be able to choose from three ways to create their manifests:
While services can access raw Kubernetes directly. Some resource types should be protected, encouraging users to use the resources which have constraints applied, or more preferably, the provided abstractions. The reason for this is for convenience (sensible defaults can be set), and to ensure platform requirements are satisfied.
Providing access to raw Kubernetes manifests would be particularly useful when deploying third-party applications, where not all platform constraints can be applied.
Users may even, in the future, be able to create their own abstraction on top of the provided schemas.
Hierarchy
Our environment is multi-cluster, multi-environment, multi-tenant and our configuration repository reflects this.
It is important to developers to not have to copy all configuration that can be applied across environments and/or clusters. This is currently achieved by patching via Kustomize, where a general base is defined and more specific patches are applied following a standard directory structure.
CUE is able to accommodate the same, leading to a structure similar to the following:
Appendix
Complete Example
Note
Minimal
Consider the following CUE configuration which declares an
application
,job
andcronJob
.This is the absolute minimum configuration required for each resource, and would generate this set of resources.
Customized
Now consider the following CUE configuration which now declares an
application
,job
and aconfigMap
, thecronJob
is a superset of a job, so no need to show a customized version of it.This is not exhaustive of all configuration options, but would generate this set of resources.
Beta Was this translation helpful? Give feedback.
All reactions