Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.
The above description, from the Kubernetes homepage, is centered on containerized applications. Yet, the Kubernetes metadata, objects, and visualizations (e.g., within Dashboard) are focused on container infrastructure rather than the applications themselves.
The Application CRD (Custom Resource Definition) and Controller in this project aim to change that in a way that's interoperable between many supporting tools.
It provides:
This can be used by:
After creating the Application CRD, you can create Application objects. An Application object provides a way for you to aggregate individual Kubernetes components (e.g. Services, Deployments, StatefulSets, Ingresses, CRDs), and manage them as a group. It provides UIs with a resource that allows for the aggregation and display of all the components in the Application.
This project uses the kubebuilder tool for code generation. kubebuilder provides the same code generation features (and a bit more) for Custom Resource Definitions and Extension API Servers that are provided by the Kubernetes project. Installing kubebuilder is not needed to build the project, but it is needed to do things like adding additional resources.
To generate the manifests and run unit tests:
make
The controller doesn‘t do much at the moment. However, if you’d like to build an image you'll need to install Docker and golang 1.9 or greater. To build the controller into an image named image
use the following command.
make docker-build IMG=<image> make docker-push IMG=<image>
To install the crd and the controller, just run:
make deploy
This will install the controller into the application-system namespace and with the default RBAC permissions.
There is also a sample Application CR in the config/samples folder.
The application CRD can be used both via manifests and programmatically.
The docs directory contains a manifest that shows how to you can integrate the Application CRD with a WordPress deployment.
The Application object shown below declares that the Application is a WordPress installation that uses StatefulSets and Services. It also contains some other relevant metadata described above.
apiVersion: app.k8s.io/v1beta1 kind: Application metadata: name: "wordpress-01" labels: app.kubernetes.io/name: "wordpress-01" app.kubernetes.io/version: "3" spec: selector: matchLabels: app.kubernetes.io/name: "wordpress-01" componentKinds: - group: core kind: Service - group: apps kind: Deployment - group: apps kind: StatefulSet assemblyPhase: "Pending" descriptor: version: "4.9.4" description: "WordPress is open source software you can use to create a beautiful website, blog, or app." icons: - src: "https://example.com/wordpress.png" type: "image/png" type: "wordpress" maintainers: - name: Kenneth Owens email: kow3ns@github.com owners: - "Kenneth Owens kow3ns@github.com" keywords: - "cms" - "blog" - "wordpress" links: - description: About url: "https://wordpress.org/" - description: Web Server Dashboard url: "https://metrics/internal/wordpress-01/web-app" - description: Mysql Dashboard url: "https://metrics/internal/wordpress-01/mysql"
Notice that each Service and StatefulSet is labeled such that Application's Selector matches the labels.
app.kubernetes.io/name: "wordpress-01"
The additional labels on the Applications components come from the recommended application labels and annotations.
You can use the standard kubectl
verbs (e.g. get
, apply
, create
, delete
, list
, watch
) to interact with an Application specified in a manifest.
Kubebuilder provides a client to get, create, update and delete resources and this also works for application resources. This is well documented in the kubebuilder book: https://book.kubebuilder.io/
Create a client:
kubeClient, err := client.New(config)
Get an application resource:
object := &applicationsv1beta1.Application{}
objectKey := types.NamespacedName{
Namespace: "namespace",
Name: "name",
}
err = kubeClient.Get(context.TODO(), objectKey, object)
Create a new application resource:
app := &applicationsv1beta1.Application{
...
}
err = kubeClient.Create(context.TODO(), app)
Go to the CONTRIBUTING.md documentation
Learn how to engage with the Kubernetes community on the community page.
You can reach the maintainers of this project at:
Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.