CodeBlanks Logo Icon CodeBlanks

Challenge - Pod YAML

Write a Pod YAML with specific labels.

Challenge: a production-ready pod

A good pod definition is more than just an image. In this challenge you'll combine the intermediate pod best practices in one definition:

  • Meaningful labels
  • Resource requests and limits
  • Readiness and liveness checks
  • Settings from a ConfigMap, the password from a Secret
resources:
  requests: {cpu: 100m, memory: 128Mi}
  limits:   {cpu: 500m, memory: 256Mi}
readinessProbe:
  httpGet: {path: /saglik, port: 8080}
livenessProbe:
  httpGet: {path: /saglik, port: 8080}
  initialDelaySeconds: 10

Practice The pod's container

Write a pod YAML: name api, label app: api; container named api, image api:1.0; resources.requests cpu: 100m, memory: 128Mi; resources.limits memory: 256Mi.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: v1
kind: Pod
metadata:
  name: api
  labels:
    app: api
spec:
  containers:
    - name: api
      image: api:1.0
      resources:
        requests:
          cpu: 100m
          memory: 128Mi
        limits:
          memory: 256Mi

Expected output

pod/api created

Practice Health checks

Write the health checks for the same container (starting with readinessProbe:): readinessProbe checks /saglik on port 8080 with httpGet; livenessProbe uses the same path and port with initialDelaySeconds: 10.

Starter code

terminal
# buraya yaz

Sample solution

terminal
readinessProbe:
  httpGet:
    path: /saglik
    port: 8080
livenessProbe:
  httpGet:
    path: /saglik
    port: 8080
  initialDelaySeconds: 10

Expected output

pod/api configured
NAME   READY   STATUS    RESTARTS   AGE
api    1/1     Running   0          25s

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 For a pod without requests, what does the scheduler assume?

  • Zero resources; the pod may be placed even on a full node Correct answer
  • All of the node's resources
  • 1 CPU and 1 GiB
  • The pod is rejected

Explanation: With no requests (and no LimitRange), there's no resource guarantee either.

2 Specify the guaranteed resources.

Question
resources:
  ____:
    cpu: 100m
    memory: 128Mi
Answer
resources:
  requests:
    cpu: 100m
    memory: 128Mi

Explanation: requests is the guarantee used in scheduling.

3 Match.

Term Meaning
requests Scheduling guarantee
limits Ceiling that can't be exceeded
readinessProbe Traffic gate
livenessProbe Catches hangs

All lessons in Intermediate