remember: deployments creates replica sets which are required for for updating and scaling our application without result in a downtime on upgrading the containers

within the previously created voting-app files we create another one
called voting-app-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: voting-app-deployment
  labels:
    name: voting-app-deployment
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: voting-app-pod
      app: demo-voting-app

  template:
    metadata:
      name: voting-app-pod
      labels:
        name: voting-app-pod
        app: demo-voting-app
    spec: 
      containers:
        - name: voting-app
          image: kodekloud/examplevotingapp_vote:v1
          ports:
            - containerPort: 80

create redis-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deploy
  labels:
    name: redis-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis-pod
      app: demo-voting-app

  template:
    metadata:
      name: redis-pod
      labels:
        name: redis-pod
        app: demo-voting-app
    spec: 
      containers:
        - name: redis
          image: redis
          ports:
            - containerPort: 6379

create postgres-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deploy
  labels:
    name: postgres-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: postgres-pod
      app: demo-voting-app

  template:
    metadata:
      name: postgres-pod
      labels:
        name: postgres-pod
        app: demo-voting-app
    spec: 
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              value: "postgres"
            - name: POSTGRES_PASSWORD
              value: "postgres"

create worker-app-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: worker-app-deploy
  labels:
    name: worker-app-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: worker-app-pod
      app: demo-voting-app

  template:
    metadata:
      name: worker-app-pod
      labels:
        name: worker-app-pod
        app: demo-voting-app
    spec: 
      containers:
        - name: worker-app
          image: kodekloud/examplevotingapp_worker:v1

create result-app-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: result-app-deployment
  labels:
    name: result-app-deployment
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: result-app-pod
      app: demo-voting-app

  template:
    metadata:
      name: result-app-pod
      labels:
        name: result-app-pod
        app: demo-voting-app
    spec: 
      containers:
        - name: result-app
          image: kodekloud/examplevotingapp_result:v1
          ports:
            - containerPort: 80

run deployment

ensure that all previously created resources are removed

# delete services
> kubectl delete service \
  db kubernetes redis result-service voting-service

# delete pods
> kubectl delete pods \
  postgres-pod redis-pod result-app-pod voting-app-pod worker-app-pod

# verify
> kubectl get all
  ---
  NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE                                                     
  service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   99s

apply deployment

# voting-app
> kubectl create -f voting-app-deploy.yaml \
  && kubectl create -f voting-app-service.yaml

# redis
> kubectl create -f redis-deploy.yaml \
  && kubectl create -f redis-service.yaml

# postgres
> kubectl create -f postgres-deploy.yaml \
  && kubectl create -f postgres-service.yaml

# worker-app
> kubectl create -f worker-app-deploy.yaml

# result-app
> kubectl create -f result-app-deploy.yaml \
  && kubectl create -f result-app-service.yaml

check status of deployments and services

> kubectl get deployments.apps,svc
  ---
  NAME                                    READY   UP-TO-DATE   AVAILABLE   AGE
  deployment.apps/postgres-deploy         1/1     1            1           3m53s
  deployment.apps/redis-deploy            1/1     1            1           3m59s
  deployment.apps/result-app-deployment   1/1     1            1           2s
  deployment.apps/voting-app-deployment   1/1     1            1           4m20s
  deployment.apps/worker-app-deploy       1/1     1            1           85s

  NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
  service/db               ClusterIP   10.107.140.120   <none>        5432/TCP       3m53s
  service/kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP        10m
  service/redis            ClusterIP   10.111.7.138     <none>        6379/TCP       3m58s
  service/result-service   NodePort    10.110.56.61     <none>        80:30005/TCP   2s
  service/voting-service   NodePort    10.100.220.46    <none>        80:30004/TCP   4m20s

get minikube cluster url

# voting-service
> minikube service voting-service --url
  ---
  http://192.168.49.2:30004

# voting-service
> minikube service result-service --url
  ---
  http://192.168.49.2:30005

scale deployment

# scale voting-app-deployment
> kubectl scale deployment voting-app-deployment --replicas 3

# get voting-app-deployment
> kubectl get deployments.apps voting-app-deployment           
  ---
  NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
  voting-app-deployment   3/3     3            3           9m35s