Deploying a First (Stateless) Application

Introduction to Kubernetes

Frank Heilmann

Platform Architect and Freelance Instructor

More on "kubectl"

  • kubectl: main command to interact with Kubernetes objects
  • Objects are, e.g., pod, service, etc.

$$

  • Typical usage patterns:

    • kubectl create -f <Manifest.yml>: create new objects, with -f for "filename"
    • kubectl apply -f <Manifest.yml>: create new objects & change the state of objects
    • kubectl get <object>: overview about objects deployed on Kubernetes
    • kubectl describe <object>: detailed information about an object

    $$

  • Detailed help available via command line option --help

Introduction to Kubernetes

More on Manifests

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 5
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.25.4
        ports:
        - containerPort: 80
  • Remember: Manifests are declarative
  • Typically YAML, but also in JSON format
  • Two important sections:
    • metadata: essential information about the object or resource
    • spec: defines the specifications, or desired state, of the object or resource
  • Sections can be quite deep, depending on the resource to be deployed
Introduction to Kubernetes

Stateless Applications

  • Stateless apps:

    • General concept
    • Not specific to Kubernetes
    • Do not save an internal state, or context of processed data
  • When interrupted, a new replica of the stateless app is recreated and starts operating.

  • Examples:
    • The database frontend querying a database backend
    • A search app querying a full text index
    • A data stream app that converts temperature readings from an IoT sensor from °F to °C
Introduction to Kubernetes

Kubernetes Deployments

  • "Stateless applications" translate to "Kubernetes Deployments"
  • A sample Manifest consists of:
    • apiVersion and kind
    • metadata and spec
  • spec defines number of replicas, a selector, and a template
  • More on selector later
  • template describes details for the creation the pods in the Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: <deployment name>
  labels:
    app: <a label for the application>
spec:
  replicas: <number of initial replicas>
  selector:
    matchLabels:
      app: <matches the label above>
  template:
    metadata:
      labels:
        app: <label to be given to each pod>
    spec:
      containers:
      - name: <container name>
        image: <the image to be used>
        ports:
        - containerPort: <ports for networking>
Introduction to Kubernetes

Deploying to a Kubernetes Cluster

  • kubectl apply -f <manifest.yml> for creating pods and applying changes.
  • Kubernetes Control Plane will schedule the Deployment on Nodes.
    • Then, Pods created is triggered on the Nodes.
  • Pods get a unique, but random (unpredictable) identifier, each Pod is "as good as any other"
Introduction to Kubernetes

Let's practice!

Introduction to Kubernetes

Preparing Video For Download...