
Kubernetes, Part 3: Pod, Deployment, Service, Ingress, ConfigMap, and Secret — deploying this application
🌐 Machine-translated from Russian. Show original
In this part:
What we are unfolding#
The small web service podinfo is an open demo application created specifically for Kubernetes training: web pages, health checks /healthz and /readyz, configuration through variable environments. Instead, substitute your image from the Docker series — the manifest structure will be the same.
Keep all manifests in Git in the k8s/ directory — in part 6 it will become the source for automatic deployment.
Step 1. Namespace#
The namespace separates applications from each other: their own objects, rights, quotas.
# k8s/00-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: demo
Step 2. ConfigMap and Secret#
# k8s/10-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: podinfo-config
namespace: demo
data:
PODINFO_UI_MESSAGE: "Привет от Kommit!"
PODINFO_UI_COLOR: "#326ce5"
Do not keep the secret in Git plaintext — create it as a command (in a real application, there will be a database password or API key):
kubectl create secret generic podinfo-secret -n demo \
--from-literal=DB_PASSWORD="$(openssl rand -base64 24)"
💡 Secret in Kubernetes is by default only coded in base64, not encrypted. Access to secrets is restricted by privileges (RBAC). To store secrets securely in Git, use Sealed Secrets, SOPS , or external storage (Vault) through the External Secrets Operator.
Step 3. Deployment#
# k8s/20-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
namespace: demo
spec:
replicas: 2
selector:
matchLabels:
app: podinfo
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: podinfo
spec:
containers:
- name: podinfo
image: ghcr.io/stefanprodan/podinfo:6.17.0
ports:
- name: http
containerPort: 9898
envFrom:
- configMapRef:
name: podinfo-config
- secretRef:
name: podinfo-secret
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
memory: 128Mi
readinessProbe:
httpGet:
path: /readyz
port: http
periodSeconds: 5
livenessProbe:
httpGet:
path: /healthz
port: http
initialDelaySeconds: 5
periodSeconds: 10
What is important here:
| Field | Why |
|---|---|
image with a specific tag | never latest: otherwise, it's unclear what's running, and rollback is impossible |
resources.requests | how many resources to guarantee — the scheduler selects the node |
resources.limits.memory | memory ceiling: when exceeded, the container restarts (OOMKilled) rather than drops the node |
readinessProbe | until the verification passes, traffic to the pod is not coming — the basis of updates without downtime |
livenessProbe | if the application freezes, Kubernetes will restart it |
maxUnavailable: 0 | when updating, old pods are removed only after new |
Step 4. Service#
Pods are mortal, their IPs change. Service gives a permanent podinfo.demo.svc.cluster.local name (inside the namespace — just podinfo) and balances traffic between ready-made pods.
# k8s/30-service.yaml
apiVersion: v1
kind: Service
metadata:
name: podinfo
namespace: demo
spec:
selector:
app: podinfo
ports:
- name: http
port: 80
targetPort: http
| Service type | Where | is available
| --- | --- |
| ClusterIP (default) | only inside the | cluster
| NodePort | on port 30000–32767 of each node |
| LoadBalancer | external IP from the balancer (in k3s — ServiceLB, in the cloud — provider balancer) |
Step 5. Ingress#
Ingress describes which domain and path to send to which service. In k3s, it is handled by Traefik on ports 80/443 of the node.
# k8s/40-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: podinfo
namespace: demo
spec:
ingressClassName: traefik
rules:
- host: podinfo.corp.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: podinfo
port:
name: http
Create a DNS record podinfo.corp.local → 192.168.1.40 (or a string in hosts on your PC for testing). We will add HTTPS in part 5.
i️ Ingress and Gateway API. The popular ingress-nginx controller from the Kubernetes community ceased development in March 2026 and no longer receives security patches. The Ingress object itself continues to be supported, but its functionality is frozen; development is underway in the Gateway API (Gateway and HTTPRoute objects). Traefik in k3s supports both options. For new projects on ingress-nginx, do not start; if you already have one — plan to switch to another controller or the Gateway API (the ingress2gateway utility helps).
Step 6. Applying#
kubectl apply -f k8s/00-namespace.yaml
kubectl apply -f k8s/
kubectl -n demo get all,ingress
kubectl -n demo rollout status deploy/podinfo
curl -H "Host: podinfo.corp.local" http://192.168.1.40/
Step 7. Update, rollback, scaling#
Change the image tag in 20-deployment.yaml and reapply the file — Kubernetes will replace pods one by one without downtime.
kubectl apply -f k8s/20-deployment.yaml
kubectl -n demo rollout status deploy/podinfo
kubectl -n demo rollout history deploy/podinfo
kubectl -n demo rollout undo deploy/podinfo # откат на предыдущую версию
kubectl -n demo scale deploy/podinfo --replicas=4
Changed ConfigMap — pods themselves do not reread environment variables. Restart them without idleness: kubectl -n demo rollout restart deploy/podinfo.
Step 8. Your image from the private registry#
kubectl create secret docker-registry ghcr-pull -n demo \
--docker-server=ghcr.io --docker-username=имя-в-github --docker-password="$GHCR_TOKEN"
Add to spec.template.spec :
imagePullSecrets:
- name: ghcr-pull
Keep the token in the environment variable or secret manager, not in the command history. Use the token for reading packets only.
When something doesn't work#
| Floor status | Common cause of | What to watch |
|---|---|---|
Pending | resources are lacking or there is no suitable | kubectl describe pod → Events |
ImagePullBackOff | typo in the image name, no access to the | Events registry, secret imagePullSecrets |
CrashLoopBackOff | app crashes at startup | kubectl logs --previous |
Running, but 0/1 Ready | does not pass readinessProbe | path and port check, logs, |
| 404 by Traefik | Ingress did not match host/path | kubectl describe ingress |
Next are data undergoing reboots and application packages: Kubernetes, Part 4: Volumes and Storage, StatefulSet, Helm 4, and PostgreSQL via the CloudNativePG operator.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.