PodPreset
The life of a Kubernetes pod can get a lot easier with PodPreset – a stellar utility that enables the injection of additional information such as environment variables and storage volumes into Pods with specified labels. This means that you no longer need to set up repetitive information for each Pod in your templates!
Even better – you can prevent them from being tampered with the PodPreset by adding the annotation podpreset.admission.kubernetes.io/exclude: "true" to your Pods.
Aligning API Versions
v1.6+
settings.k8s.io/v1alpha1
No
Activating PodPreset
Activate API with
kube-apiserver --runtime-config=settings.k8s.io/v1alpha1=trueEnable admission control with
--enable-admission-plugins=..,PodPreset
Diving into PodPreset Examples
Suppose you're using a PodPreset to add environment variables and storage volumes:
kind: PodPreset
apiVersion: settings.k8s.io/v1alpha1
metadata:
name: allow-database
namespace: myns
spec:
selector:
matchLabels:
role: frontend
env:
- name: DB_PORT
value: "6379"
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}And you submit a Pod:
After going through the PodPreset admission control, the Pod automatically acquires additional environment variables and storage volumes:
Checking Out ConfigMap Examples
When dealing with ConfigMaps:
And using PodPresets:
Upon submitting a Pod and applying PodPreset admission control, your Pod now automatically includes ConfigMap environment variables:
Example: Changing Pod Time Zone
This powerful utility even allows you to change the time zone for all Pods labelled tz: shanghai to Shanghai time zone, as shown in the given example:
This demonstrates how PodPreset carries the potential to greatly simplify Kubernetes usage, so it's definitely time to give it a try!
最后更新于