Pods
Pods
Pods are the smallest instance of an object you can deploy into k8s. Pods represent a single instances of an application. Containers are encapsulated into pods.
kubectl run nginx —image nginx
Template
apiVersion: v1
kind: Pod
metadata:
name: ${RESOURCE_NAME}
# namespace: default
labels:
color: blue
spec:
# nodeName: node-01
# volumes:
# - name: volume-name
# hostPath:
# path: /var/lib/dir1
containers:
- name: ${RESOURCE_NAME}-container
image: ${RESOURCE_NAME}:latest
env:
- name: APP_NAME
value: ${RESOURCE_NAME}
# - name: SPECIAL_LEVEL_KEY
# valueFrom:
# configMapKeyRef:
# name: special-config
# key: special.how
# - name: SECRET_SOME_KEY
# valueFrom:
# secretKeyRef:
# name: secret-name
# key: fieldName
# envFrom:
# - configMapRef:
# name: ${RESOURCE_NAME}-config
# - secretRef:
# name: ${RESOURCE_NAME}-secret
envFrom:
- configMapRef:
name: configmap-name
# prefix: CONFIG_
- secretRef:
name: secret-name
# prefix: SECRETVALUE_
# imagePullPolicy: Always
# command: ["sleep"]
# args: ["3600"]
---
Defining Environments
Static set key
env:
- name: ENV_NAME
value: someValue
Read a single key from an external source (configmap, secret, pod field)
env:
- name: ENV_FROM_CONFIGMAP
valueFrom:
configMapKeyRef:
name: config-map-name
key: the-key-in-the-config-map
- name: ENV_FROM_SECRET
valueFrom:
secretKeyRef:
name: secret-name
key: the-key-in-the-secret
- name: ENV_FROM_POD_FIELD
valueFrom:
fieldRef:
fieldPath: # One of metadata.labels['key'], metadata.annotations['key'],
# spec.nodeName, spec.serviceAccountName,
# status.hostIp, status.podIP, status.podIPs
Read multiple fields into the environment
envFrom:
- configMapRef:
name: configmap-name
# prefix: CONFIG_
- secretRef:
name: secret-name
# prefix: SECRETVALUE_
Multiple containers
You CAN run multiple containers in a pod, but not for better availability. Usually this is a helper container, like a logging sidecar.