K8s Object

A k8s-objects component embeds a standard Kubernetes entity as a component. This type of component is useful in situations where the existing component definitions do not support a particular type of entity and to facilitate the progressive migration of applications to the Open Application Model specification.

Note that the component will attempt to create the different entities but no previous validation of their structures is made. The following snippet shows an application that uses a k8s-object to create a Secret in Kubernetes. As a side note, creating secrets can be done with the storage trait.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: k8s-objects-app
spec:
  components:
    - name: postgres-required
      type: k8s-objects # Set to k8s-objects
      properties:
        objects:
          # set the k8s manifest
          # Secret
          - apiVersion: v1
            kind: Secret
            metadata:
              name: postgres-secret
            type: Opaque
            data:
              POSTGRES_PASSWORD: cGFzc3dvcmQ=
              POSTGRES_USER: dXNlcg==

Mixing component types is supported in OAM by default, and the k8s-object can also be used in this situation. The following example shows an application that makes use of k8s-object to create a v1.Secret and a webservice OAM component to deploy the component that will use that secret.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: k8s-objects-app
spec:
  components:
    - name: postgres-required
      type: k8s-objects # Set to k8s-objects
      properties:
        objects:
          # set the k8s manifest
          # Secret
          - apiVersion: v1
            kind: Secret
            metadata:
              name: postgres-secret
            type: Opaque
            data:
              POSTGRES_PASSWORD: cGFzc3dvcmQ=
              POSTGRES_USER: dXNlcg==
          # ConfigMap
          - apiVersion: v1
            kind: ConfigMap
            metadata:
              name: postgres-cm
            data:
              POSTGRES_DB: db
    # Component              
    - name: postgres-comp
      type: webservice
      dependsOn:
        - postgres-required
      properties:
        image: docker.io/postgres:9.6.17-alpine 
        replicas: 1
        ports:       
        - port: 5432
          expose: true
        volumeMounts:
          emptyDir:
          - name: postgres-pv
            mountPath: /var/lib/postgresql/data
        env: 
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                name: postgres-secret
                key: POSTGRES_USER
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: postgres-secret
                key: POSTGRES_PASSWORD
          - name: POSTGRES_DB
            valueFrom:
              configMapKeyRef:
                name: postgres-cm
                key: POSTGRES_DB