k8srequiredprobes
Basic Information
Function
Pods must have readiness or liveness probes.
Policy Example
The following policy instance shows the resource types for which the policy definition takes effect. The parameters area displays probes and probeTypes.
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredProbes
metadata:
name: must-have-probes
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
parameters:
probes: ["readinessProbe", "livenessProbe"]
probeTypes: ["tcpSocket", "httpGet", "exec"]
Resource Definition That Complies with the Policy
The pod contains livenessProbe and readinessProbe, and the probe type is tcpSocket, which complies with the policy instance.
apiVersion: v1
kind: Pod
metadata:
name: test-pod1
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
volumes:
- name: cache-volume
emptyDir: {}
Resource Definition That Does Not Comply with the Policy
The pod contains livenessProbe, but probeType is not defined, which does not comply with the policy instance.
apiVersion: v1
kind: Pod
metadata:
name: test-pod1
spec:
containers:
- name: nginx-1
image: nginx:1.7.9
ports:
- containerPort: 80
livenessProbe:
# tcpSocket:
# port: 80
# initialDelaySeconds: 5
# periodSeconds: 10
volumeMounts:
- mountPath: /tmp/cache
name: cache-volume
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
volumes:
- name: cache-volume
emptyDir: {}
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot