You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,11 @@ The Pod spec for your apps can be one of the more complex parts of your Kubernet
4
4
5
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
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
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).
10
8
11
-
apiVersion: v1
12
-
kind: Pod
13
-
metadata:
14
-
name: mypod
9
+
## The spec from `[./pod.yaml](./pod.yaml)`
15
10
11
+
```yaml
16
12
spec:
17
13
18
14
containers:
@@ -30,9 +26,9 @@ spec:
30
26
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
31
27
path: /ready
32
28
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
34
30
httpGet: # Lots of timeout values with defaults, be sure they are ideal for your workload
35
-
path: /ready
31
+
path: /alive
36
32
port: 8080
37
33
38
34
resources: # Because if limits = requests then QoS is set to "Guaranteed"
@@ -49,6 +45,9 @@ spec:
49
45
allowPrivilegeEscalation: false # prevent sudo, etc.
50
46
privileged: false # prevent acting like host root
51
47
48
+
49
+
terminationGracePeriodSeconds: 600# default is 30, but you may need more time to gracefully shutdown (HTTP long polling, user uploads, etc)
50
+
52
51
# per-pod security context
53
52
# enable seccomp and force non-root user
54
53
securityContext:
@@ -60,3 +59,11 @@ spec:
60
59
runAsGroup: 1001# hardcode group to non-root if not set in Dockerfile
61
60
runAsNonRoot: true # hardcode to non-root. Redundant to above if Dockerfile is set USER 1000
62
61
```
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).
0 commit comments