Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit acc161c · 15 days ago

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:

FieldWhy
image with a specific tagnever latest: otherwise, it's unclear what's running, and rollback is impossible
resources.requestshow many resources to guarantee — the scheduler selects the node
resources.limits.memorymemory ceiling: when exceeded, the container restarts (OOMKilled) rather than drops the node
readinessProbeuntil the verification passes, traffic to the pod is not coming — the basis of updates without downtime
livenessProbeif the application freezes, Kubernetes will restart it
maxUnavailable: 0when 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 statusCommon cause ofWhat to watch
Pendingresources are lacking or there is no suitablekubectl describe pod → Events
ImagePullBackOfftypo in the image name, no access to theEvents registry, secret imagePullSecrets
CrashLoopBackOffapp crashes at startupkubectl logs --previous
Running, but 0/1 Readydoes not pass readinessProbepath and port check, logs,
404 by TraefikIngress did not match host/pathkubectl 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 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.