Generic Kubernetes manifest for web application deployment

Generic Kubernetes manifest for web application deployment

Deployment name, container registry and service port are externalized, making this manifest general-purpose

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ${APPLICATION_NAME}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ${APPLICATION_NAME}
  template:
    metadata:
      labels:
        app: ${APPLICATION_NAME}
    spec:
      containers:
      - name: ${APPLICATION_NAME}
        image: ${CONTAINER_REGISTRY}/${APPLICATION_NAME}
        imagePullPolicy: Always
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: ${APPLICATION_NAME}
  name: ${APPLICATION_NAME}
spec:
  ports:
  - port: 80
    nodePort: ${SERVICE_PORT}
  selector:
    app: ${APPLICATION_NAME}
  type: LoadBalancer

Reminder: To parse environment variables in a kubernetes manifest file, use the following:

envsubst < deployment.yml | kubectl apply -f -