|
1 | 1 | # Kubernetes Pod Specification Good Defaults |
2 | 2 |
|
3 | | -The Pod spec for your apps can be the most complex part of your Kubernetes manifest design, and needs many features enabled to be a save and reasonably secure default |
| 3 | +The Pod spec for your apps can be one of the more complex parts of your Kubernetes manifest design, and needs many features enabled to be a save and reasonably secure default. |
4 | 4 |
|
5 | | -This single-file repo is meant to be a starting point for your Pod specs, to add to Deployments, DaemonSets, StatefulSets, initContainers, etc. |
| 5 | +This single-file repository is meant to be a starting point for your Pod specs, to add to Deployments, DaemonSets, StatefulSets, initContainers, etc. |
| 6 | + |
| 7 | +```yaml |
| 8 | +# generic pod spec that's usable inside a deployment or other higher level k8s spec |
| 9 | +# via https://github.com/BretFisher/podspec |
| 10 | + |
| 11 | +apiVersion: v1 |
| 12 | +kind: Pod |
| 13 | +metadata: |
| 14 | + name: mypod |
| 15 | + |
| 16 | +spec: |
| 17 | + |
| 18 | + containers: |
| 19 | + |
| 20 | + # basic container details |
| 21 | + - name: my-container-name |
| 22 | + # never use reusable tags like latest or stable |
| 23 | + image: my-image:tag |
| 24 | + # hardcode the listening port if Dockerfile isn't set with EXPOSE |
| 25 | + ports: |
| 26 | + - containerPort: 8080 |
| 27 | + protocol: TCP |
| 28 | + |
| 29 | + readinessProbe: # only needed if your pod has a service and listening port |
| 30 | + httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload |
| 31 | + path: /ready |
| 32 | + port: 8080 |
| 33 | + livenessProbe: # only needed if your app becomes unresponsive or you don't have a readinessProbe, but this is up for debate. |
| 34 | + httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload |
| 35 | + path: /ready |
| 36 | + port: 8080 |
| 37 | + |
| 38 | + resources: # Because if limits = requests then QoS is set to "Guaranteed" |
| 39 | + limits: |
| 40 | + memory: "500Mi" # If container uses over 500MB it is killed (OOM) |
| 41 | + cpu: "2" # If container uses over 2 vCPU it is throttled |
| 42 | + requests: |
| 43 | + memory: "500Mi" # Scheduler finds a node where 500MB is available |
| 44 | + cpu: "1" # Scheduler finds a node where 1 vCPU is available |
| 45 | + |
| 46 | + # per-container security context |
| 47 | + # lock down privileges inside the container |
| 48 | + securityContext: |
| 49 | + allowPrivilegeEscalation: false # prevent sudo, etc. |
| 50 | + privileged: false # prevent acting like host root |
| 51 | + |
| 52 | + # per-pod security context |
| 53 | + # enable seccomp and force non-root user |
| 54 | + securityContext: |
| 55 | + |
| 56 | + seccompProfile: |
| 57 | + type: RuntimeDefault # enable seccomp and the runtimes default profile |
| 58 | + |
| 59 | + runAsUser: 1001 # hardcode user to non-root if not set in Dockerfile |
| 60 | + runAsGroup: 1001 # hardcode group to non-root if not set in Dockerfile |
| 61 | + runAsNonRoot: true # hardcode to non-root. Redundant to above if Dockerfile is set USER 1000 |
| 62 | +``` |
0 commit comments