Pod Preset

Pod Preset is used to inject data into pods at creation time. It allows us to add volumes, secret, configMaps and environmental variables into pods without defining them in the pod template. we use pod preset because it allow us to isolate certain information or data from people who do not need to see them. It makes the application loosely coupled. To use pod preset we must make sure that the feature is enabled in the API configuration and the admission controller exist. We then create a pod preset object and assign pods to the given pod preset using label selectors. Once the label on the pod-preset is matched by the application pod then the given data in the pod preset is injected into the pod. Below is an example of a pod preset and pod manifest that leverages pod preset functionality. We have created a pod preset object that injects environment variable named WEB_PORT and a secret named web-secret.

apiVersion: settings.k8s.io/v1alpha1 
kind: PodPreset
metadata:
  name: web-PodPreset
spec:
  selector:
    matchLabels:
      app: web
  env:
    - name: WEB_PORT 
      value: "80" 
  envFrom:
    - secretKeyRef: 
      name: web-secret
  volumeMounts: 
    - mountPath: /cache
      name: cache-volume
  volumes: 
    - name: cache-volume
      emptyDir: {}
apiVersion: v1
kind: Pod
metadata:
  name: hello-website
  labels:
    app: web
spec:
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80

Leave a Reply

Your email address will not be published. Required fields are marked *