{"id":16880030,"url":"https://github.com/anderseknert/podpreset-example","last_synced_at":"2026-05-14T22:32:50.472Z","repository":{"id":109367191,"uuid":"248742493","full_name":"anderseknert/podpreset-example","owner":"anderseknert","description":"Example kubernetes PodPreset admission controller","archived":false,"fork":false,"pushed_at":"2020-03-22T19:10:56.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T20:50:41.747Z","etag":null,"topics":["admission-controller","kubernetes","podpreset"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anderseknert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-20T11:48:48.000Z","updated_at":"2021-02-21T22:10:34.000Z","dependencies_parsed_at":"2023-04-26T08:01:01.175Z","dependency_job_id":null,"html_url":"https://github.com/anderseknert/podpreset-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fpodpreset-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fpodpreset-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fpodpreset-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fpodpreset-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anderseknert","download_url":"https://codeload.github.com/anderseknert/podpreset-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244538585,"owners_count":20468744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["admission-controller","kubernetes","podpreset"],"created_at":"2024-10-13T15:57:01.254Z","updated_at":"2026-05-14T22:32:50.440Z","avatar_url":"https://github.com/anderseknert.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PodPreset example\n\nExample showing the use of the\n[PodPreset](https://kubernetes.io/docs/tasks/inject-data-application/podpreset/)\nadmission controller to control what environment variables (sourced from\n`ConfigMap`s or `Secret`s), volumes and volume mounts are made available inside\nof a pod at the moment of its creation.\n\nUsing pod presets allows for using light weight pod and container definitions,\nadding environment specific configurations based on the labels set on the pod.\n\n# Installing\n\nSince the PodPreset admission controller is a feature in alpha stage it isn't\nenabled by default. In order to enable it you'll need to start the kubernetes\n`api-server` pods with the following flags added to their container config:\n\n```sh\n--runtime-config=settings.k8s.io/v1alpha1=true\n--enable-admission-plugins=PodPreset\n```\n\n## Kops configuration\n\nWhen using kops for cluster provisioning, the flags for\n[the API server](https://github.com/kubernetes/kops/blob/master/docs/cluster_spec.md#kubeapiserver)\nis provided through the cluster spec like below:\n\n```yaml\nkubeAPIServer:\n    runtimeConfig:\n      'settings.k8s.io/v1alpha1': 'true'\n    appendAdmissionPlugins:\n      - PodPreset\n```\n\n# PodPreset config\n\nA PodPreset resource is used to determine what data (secret, config, volumes)\nshould be attached to which pods.\n\n## PodPreset selector\n\nWhich pods are selected is determined by the label selector:\n\n```yaml\napiVersion: settings.k8s.io/v1alpha1\nkind: PodPreset\nmetadata:\n  name: common-podpreset\nspec:\n  selector:\n    matchExpressions:\n      - {key: app, operator: Exists}\n```\nThe above selector will have the podpreset applied to any pod with an `app`\nlabel, regardless of its value.\n\n## Injecting configuration\n\n### envFrom\n\nWith a selector marking all our apps for injection of common config, we may\nnow specify which config to inject. Environment variables can either be fetched\nfrom `ConfigMap`s, `Secret`s or provided directly in the `PodPreset` resource\ndefinition. To include all variables in a configmap or secret, use `envFrom`\nattribute to point to the `ConfigMap` or `Secret` of interest:\n\n```yaml\nspec:\n  envFrom:\n    - configMapRef:\n        name: common-env-vars\n    - secretRef:\n        name: common-env-secrets\n```\n\nThe snippet above would take all key/value pairs from the `common-env-vars`\nconfigmap and the `common-env-secrets` secret and inject them as environment\nvariables in any pod matching the `app` label previously specified.\n\n### env\n\nWhile injecting everything from a `ConfigMap` or `Secret` works in many cases,\nsometimes you'll find yourself wanting to expose only a few named variables or\nsecrets inside of your pod. This can be done with the `env` attribute combined\nwith either a `name`/`value` pair for defining variables directly, or by\nreferring to single attribute inside of your configmaps or secrets with\n`valueFrom`:\n\n```yaml\nspec:\n  env:\n    - name: MY_VAR\n      value: 'hello world'\n    - name: SINGLE_VAR_FROM_CONFIGMAP\n      valueFrom:\n        configMapKeyRef:\n          name: common-env-vars\n          key: DATACENTER_NAME\n    - name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY_SPECIFIC\n      valueFrom:\n        secretKeyRef:\n          name: common-env-secrets\n          key: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY\n```\n\n### Volumes and volume mounts\n\nFinally, just as with environment variables, volumes and volume mounts may\nbe injected inside any pod matching the selector:\n\n```yaml\nspec:\n  volumeMounts:\n  - name: localtime\n    mountPath: /etc/localtime\n  volumes:\n  - name: localtime\n    hostPath:\n      path: /etc/localtime\n```\n\n## Caveats\n\nPodpresets are applied to each container in the pod - there is no way of\npointing specific configuration or volumes to specific containers inside\nof the pod.\n\nSee `podpreset/common-podpreset.yaml` for the full example.\n\n## Further reading\n\nhttps://kubernetes.io/docs/concepts/workloads/pods/podpreset/\nhttps://kubernetes.io/docs/tasks/inject-data-application/podpreset/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderseknert%2Fpodpreset-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanderseknert%2Fpodpreset-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderseknert%2Fpodpreset-example/lists"}