liveBook · Manning

Kubernetes resource

As explained in Developer Experience on Kubernetes

A Kubernetes resource is an API-managed object representing a workload, service, configuration, or other desired state in a Kubernetes cluster.

A Kubernetes resource is an API-managed object created in a cluster to express part of an application's desired deployment state. Resources are declared in YAML manifests and created or updated by applying those manifests with kubectl. section 3.3.3

A containerized application exposed outside a cluster commonly needs these resources:

  • Deployment — manages the lifecycle of a stateless replicated application; each replica is a Pod representing the application container. section 3.3.3
  • Service — makes a Deployment reachable for network calls, usually within the cluster. section 3.3.3
  • Ingress — makes a Service reachable from outside the cluster. section 3.3.3
  • ConfigMap or Secret — can supply application properties or credentials. Secret data is usually Base64-encoded, which is not encryption. section 3.3.3

Resources make deployment declarative, but they add work to the local development loop. After a code change, developers typically build an image, load it into the local cluster, update manifests, and apply them to create or update resources. This can slow feedback and shift attention away from application logic. section 3.3.2

Appointments application deployment

An Appointments service can use a Deployment manifest with labels, a container image, and environment values read from a database Secret. A PostgreSQL database can itself be provisioned as a Cluster resource through the CloudNativePG operator; the application resources can then be applied from a configuration directory. section 3.3.3

Listing 3.1 Deployment configuration for a cloud native application.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appointments #A
  labels:
    app: appointments
spec:
  selector:
    matchLabels:
      app: appointments
  template:
    metadata:
      labels:
        app: appointments
    spec:
      containers:
        - name: appointments #B
          image: ko.local/appointments:0.0.1-SNAPSHOT #C
          env: #D
            - name: POSTGRES_HOST
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: host
            - name: POSTGRES_PORT
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: port
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: dbname
            - name: POSTGRES_USERNAME
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: username
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: password
          ...

Inspect the Deployment manifest to see an API version, resource kind, metadata, pod template, container image, and Secret-backed environment configuration in one resource definition. section 3.3.3

How Developer Experience on Kubernetes covers it

How deep it goes
Explains manifest-based creation and the roles of Deployment, Pod, Service, Ingress, ConfigMap, and Secret without API internals.
Examples
Uses an Appointments service Deployment and a CloudNativePG PostgreSQL Cluster resource as deployment artifacts.
What it assumes
Assumes a Kubernetes cluster and a packaged container image before resource manifests are applied.
What you can do after
Operate/configure it by defining YAML manifests and applying them with kubectl to create or update cluster resources.
How it connects
Connects Kubernetes resources with manifests, kubectl, container images, Deployments, Pods, Services, Ingresses, ConfigMaps, and Secrets.

Also explained in

Compare how 6 books explain Kubernetes resource →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Developer Experience on Kubernetes. The section links point to the parts of the book it draws on.