CodeBlanks Logo Icon CodeBlanks

Project design

Design the Kubernetes structure for web and database.

Project: a multi-tier application

In this project you'll move an application made of a web front end, an API and a PostgreSQL database to Kubernetes. The plan:

  1. Its own magaza namespace
  2. Database: a single-replica Deployment taking its password from a Secret + a ClusterIP Service
  3. API and web: multi-replica Deployments, settings from a ConfigMap
  4. Only web is exposed outside (NodePort)
k8s/
  00-namespace.yaml
  10-db.yaml
  20-api.yaml
  30-web.yaml
  40-ayar.yaml
kubectl apply -f k8s/

The numbers in the file names keep the order predictable when the folder is applied.

Namespace and context

The first file creates the namespace; all later objects carry metadata.namespace: magaza. While working, the context's namespace is set to avoid writing -n on every command:

# 00-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: magaza

kubectl apply -f k8s/00-namespace.yaml
kubectl config set-context --current --namespace=magaza

Practice Prepare the namespace

Write two commands: create the magaza namespace; set the active context's namespace to magaza.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl create namespace magaza
kubectl config set-context --current --namespace=magaza

Expected output

namespace/magaza created
Context "minikube" modified.

Questions and answers

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

1 In this design, can the database be reached from outside the cluster?

  • Yes, through port 5432
  • Yes, via NodePort
  • Only in Minikube
  • No; ClusterIP is cluster-internal only Correct answer

Explanation: When needed, temporary access is given with kubectl port-forward.

2 Apply all files in the folder.

Question
kubectl apply -f ____
Answer
kubectl apply -f k8s/

Explanation: -f can take a folder.

3 Match the tiers.

Term Meaning
web Exposed with NodePort
api ClusterIP, many replicas
db ClusterIP, single replica
magaza The project's namespace

All lessons in Intermediate