5. DEPLOY INVENTORY SERVICE

5.1. Overview

This section provide guideline to deploy nordmart inventory service.

5.2. Deployment Guidelines

5.2.1. Move to a directory containing vanilla manifests for resources:
cd ~/stakater-nordmart-inventory/deployment
1

It will have the following manifests and in the next steps each of these manifests will be deployed one by one.

.
├── dependencies
│   ├── postgresql-inventory.yaml
│   └── postgresql-secret.yaml
├── manifests
│   └── application
│       ├── inventory.yaml
│       └── templates
│           ├── deployment.yaml
│           ├── secret.yaml
│           ├── serviceaccount.yaml
│           └── service.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13

NOTE

While deploying manifests always mention the namespace by typing -n <NAMESPACE_NAME> at the end of the command

5.2.2. "dependencies" directory manifests

It has two manifests:

5.2.2.1. postgresql-secret.yaml: It is a secret containing env variables for postgresql database name, user and password.

5.2.2.2. postgresql-inventory.yaml: It is manifest containing the service and statefulset resource for postgres. Secret created from postgresql-inventory.yaml will be used in this manifest to setup database, user & password.

The next step(5.2.3) is optional to use Sealed Secrets insted of K8s secrets, if you want to ignore it so just apply stakater-nordmart-inventory/deployment/dependencies/postgresql-secret.yaml.

5.2.3 (Optional - Using Sealed Secrets).

We can use Sealed Secrets controller to deploy our secrets, but for this bootcamp, we are using plain Secrets as of now.

5.2.4. (Plain Secrets) Create Secret for Postgresql
kubectl apply -f dependencies/postgresql-secret.yaml -n <NAMESPACE_NAME>
1
5.2.5. Applying `postgresql-inventory.yaml` manifest

postgres-config

Description

  1. Kubernetes resource type.

  2. Name of the service.

  3. It is mapping container's port 5432 on service's port 5432.

  4. It will select all the pods that have a label named app with value postgres.

  5. Kubernetes resource type.

  6. Name of the statefulset.

  7. Label assigned to the statefulset. This label will be used by the service to select it.

  8. It is using the configmap created in the previous step.

  9. It is mounting a volume.

  10. It is creating a volume using the volumeClaim.

Applying manifest

# apply postgres manifest
kubectl apply -f dependencies/postgresql-inventory.yaml -n NAMESPACE_NAME
1
2

Verification


# to get the serivce in a namespace
kubectl get service -n NAMESPACE_NAME

# to get the statefulset in a namespace
kubectl get statefulset -n NAMESPACE_NAME
1
2
3
4
5
6
# to get the value of the service resource
kubectl get service SERVICE_NAME -oyaml -n NAMESPACE_NAME

kubectl get statefulset STATEFUL_SET_NAME -oyaml -n NAMESPACE_NAME
1
2
3
4
5.2.6. "manifests/application" directory manifests

This folder contains a directory and a manifest:

5.2.6.1. inventory.yaml: It is a file containing following resources:

  1. secret
  2. serviceaccount
  3. service
  4. deployment

5.2.6.2. templates: It is a directory containing manifest for these resources:

  1. secret
  2. serviceaccount
  3. service
  4. deployment

In the next steps all the manifests of templates directory will be deployed. We can apply all of them using inventory.yaml file but for understanding we will deploy the manifests of templates directory one by one.

5.2.7. Apply `templates/secret` manifest:

postgres-config

Description

  1. Kubernetes resource name.

  2. Name of the secret

  3. Data stored in a secret.

Applying Manifest

kubectl apply -f manifests/application/templates/secret.yaml -n NAMESPACE_NAME
1

Verification

kubectl get secret -n NAMESPACE_NAME

kubectl get secret SECRET_NAME -n NAMESPACE_NAME -oyaml
1
2
3
5.2.8. Apply `templates/serviceaccount` manifest:

postgres-config

Description

  1. Kubernetes resource type.

  2. Name of the service account.

Applying Manifest

kubectl apply -f manifests/application/templates/serviceaccount.yaml -n NAMESPACE_NAME
1

Verification

kubectl get serviceaccount -n NAMESPACE_NAME

kubectl get serviceaccount SERVICE_ACCOUNT_NAME -n NAMESPACE_NAME -oyaml
1
2
3
5.2.9. Apply `templates/deployment` manifest:

postgres-config

Description

  1. Kubernetes resource type.

  2. Name of the deployment

  3. Container name and image name.

  4. Configuring an environment variable in a container using the secret created is previous step.

  5. Configuring health checks for the pod.

  6. Name of the serviceaccount used by this deployment.

Applying Manifest

kubectl apply -f manifests/application/templates/deployment.yaml -n NAMESPACE_NAME
1

Verification

kubectl get deployment -n NAMESPACE_NAME

kubectl get deployment DEPLOYMENT_NAME -n NAMESPACE_NAME -oyaml
1
2
3
5.2.10. Apply `templates/service` manifest:

postgres-config

Description

  1. Kubernetes resource type.

  2. Name of the service.

  3. Mapping the container port on the service port.

Applying Manifest

kubectl apply -f manifests/application/templates/service.yaml -n NAMESPACE_NAME
1

Verification

kubectl get service -n NAMESPACE_NAME

kubectl get service SERVICE_NAME -n NAMESPACE_NAME -oyaml
1
2
3
5.2.11. To verify it is working, access the url given below
web-NAMESPACE_NAME.DOMAIN/
1

Replace the DOMAIN/ with your cluster's domain.

5.2.13. Once inventory service is available, products inventory will also be available on the dashboard

nordmart-with-inventory