Skip to content

Commit 70f35fc

Browse files
committed
more details
1 parent cd8920a commit 70f35fc

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ The Pod spec for your apps can be one of the more complex parts of your Kubernet
44

55
This single-file repository is meant to be a starting point for your Pod specs, to add to Deployments, DaemonSets, StatefulSets, initContainers, etc.
66

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
7+
It's based on years of consulting, the Kubernetes courses and workshops I do, and [this tweet when I first had the idea](https://twitter.com/BretFisher/status/1550326044577730560).
108

11-
apiVersion: v1
12-
kind: Pod
13-
metadata:
14-
name: mypod
9+
## The spec from `[./pod.yaml](./pod.yaml)`
1510

11+
```yaml
1612
spec:
1713

1814
containers:
@@ -30,9 +26,9 @@ spec:
3026
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
3127
path: /ready
3228
port: 8080
33-
livenessProbe: # only needed if your app becomes unresponsive or you don't have a readinessProbe, but this is up for debate.
29+
livenessProbe: # only needed if your app tends to go unresponsive or you don't have a readinessProbe, but this is up for debate
3430
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
35-
path: /ready
31+
path: /alive
3632
port: 8080
3733

3834
resources: # Because if limits = requests then QoS is set to "Guaranteed"
@@ -49,6 +45,9 @@ spec:
4945
allowPrivilegeEscalation: false # prevent sudo, etc.
5046
privileged: false # prevent acting like host root
5147

48+
49+
terminationGracePeriodSeconds: 600 # default is 30, but you may need more time to gracefully shutdown (HTTP long polling, user uploads, etc)
50+
5251
# per-pod security context
5352
# enable seccomp and force non-root user
5453
securityContext:
@@ -60,3 +59,11 @@ spec:
6059
runAsGroup: 1001 # hardcode group to non-root if not set in Dockerfile
6160
runAsNonRoot: true # hardcode to non-root. Redundant to above if Dockerfile is set USER 1000
6261
```
62+
63+
## Additional factors and suggestions that affect pod spec
64+
65+
- You can remove `runAsUser/runAsGroup` if you are using a Dockerfile that sets the user/group to non-root (or ko or buildpacks, thanks [@e_k_anderson](https://twitter.com/e_k_anderson/status/1550485281261817856)), but some teams will still require these values hardcoded in the manifest (or in admission controller) to enforce at the server-side.
66+
- If `runAsNonRoot` is true (as it should be), you may get error `CreateContainerConfigError: Error: container has runAsNonRoot and image has non-numeric user (username), cannot verify user is non-root.` if your Dockerfile `USER` isn't an ID. Kubernetes wants it as an ID (not friendly username like `node`) to ensure it's not just a user mapping to UID 0 (root). I think this can be avoided if you hardcode the user as well in the manifest (`runAsUser`), but I haven't tested that.
67+
- If you have over ~1,000 services in a namespace, maybe set `pod.spec.enableServiceLinks: false` to avoid [minor container startup and TCP round-trip delays](https://github.com/knative/serving/issues/8498) thanks [@e_k_anderson](https://twitter.com/e_k_anderson/status/1550486493868826630).
68+
- You can likely avoid needing `pod.spec.containers.imagePullPolicy` because the [defaults are smart and tend to do the right thing](https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting).
69+
- `pod.spec.containers.securityContext.readOnlyRootFilesystem` is a good idea if possible, but usually doesn't work out-of-the-box with monoliths and traditional apps. [YMMV](https://en.wiktionary.org/wiki/your_mileage_may_vary).

pod.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ spec:
2323
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
2424
path: /ready
2525
port: 8080
26-
livenessProbe: # only needed if your app becomes unresponsive or you don't have a readinessProbe, but this is up for debate.
26+
livenessProbe: # only needed if your app tends to go unresponsive or you don't have a readinessProbe, but this is up for debate
2727
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
28-
path: /ready
28+
path: /alive
2929
port: 8080
3030

3131
resources: # Because if limits = requests then QoS is set to "Guaranteed"
@@ -41,6 +41,8 @@ spec:
4141
securityContext:
4242
allowPrivilegeEscalation: false # prevent sudo, etc.
4343
privileged: false # prevent acting like host root
44+
45+
terminationGracePeriodSeconds: 600 # default is 30, but you may need more time to gracefully shutdown (HTTP long polling, user uploads, etc)
4446

4547
# per-pod security context
4648
# enable seccomp and force non-root user

0 commit comments

Comments
 (0)