Add bare pod check to checks.md

image-warning-sha256
Varsha Varadarajan 2019-07-16 14:53:43 -04:00
parent f11c7bd659
commit 1030d9d0ac
3 changed files with 71 additions and 4 deletions

View File

@ -426,3 +426,56 @@ spec:
cpu: 102m
```
###### Bare Pods
Name: `bare-pods`
Group: `basic`
Description: When the node that a Pod is running on reboots or fails, the pod is terminated and will not be restarted. However, a Job will create new Pods to replace terminated ones. For this reason, we recommend that you use a Job, Deployment or StatefulSet rather than a bare Pod, even if your application requires only a single Pod.
Example:
```yaml
# Don't do this
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: test
labels:
name: mypod
spec:
containers:
- name: mypod
image: nginx:1.17.0
```
How to fix:
```yaml
# Configure pods as part of a deployment, job, statefulset
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: test
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
```

View File

@ -45,9 +45,7 @@ func (b *barePodCheck) Description() string {
return "Check if there are bare pods in the cluster"
}
// Run runs this check on a set of Kubernetes objects. It can return warnings
// (low-priority problems) and errors (high-priority problems) as well as an
// error value indicating that the check failed to run.
// Run runs this check on a set of Kubernetes objects.
func (b *barePodCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, error) {
var diagnostics []checks.Diagnostic
for _, pod := range objects.Pods.Items {
@ -57,7 +55,7 @@ func (b *barePodCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, error) {
d := checks.Diagnostic{
Check: b.Name(),
Severity: checks.Error,
Message: fmt.Sprintf("Avoid using bare pods in clusters"),
Message: "Avoid using bare pods in clusters",
Kind: checks.Pod,
Object: &pod.ObjectMeta,
Owners: pod.ObjectMeta.GetOwnerReferences(),

View File

@ -1,3 +1,19 @@
/*
Copyright 2019 DigitalOcean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package basic
import (