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
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
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>
5.2.5. Applying `postgresql-inventory.yaml` manifest
Description
Kubernetes resource type.
Name of the service.
It is mapping container's port
5432
on service's port5432
.It will select all the pods that have a label named
app
with valuepostgres
.Kubernetes resource type.
Name of the statefulset.
Label assigned to the statefulset. This label will be used by the service to select it.
It is using the configmap created in the previous step.
It is mounting a volume.
It is creating a volume using the volumeClaim.
Applying manifest
# apply postgres manifest
kubectl apply -f dependencies/postgresql-inventory.yaml -n NAMESPACE_NAME
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
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
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:
- secret
- serviceaccount
- service
- deployment
5.2.6.2. templates
: It is a directory containing manifest for these resources:
- secret
- serviceaccount
- service
- 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:
Description
Kubernetes resource name.
Name of the secret
Data stored in a secret.
Applying Manifest
kubectl apply -f manifests/application/templates/secret.yaml -n NAMESPACE_NAME
Verification
kubectl get secret -n NAMESPACE_NAME
kubectl get secret SECRET_NAME -n NAMESPACE_NAME -oyaml
2
3
5.2.8. Apply `templates/serviceaccount` manifest:
Description
Kubernetes resource type.
Name of the service account.
Applying Manifest
kubectl apply -f manifests/application/templates/serviceaccount.yaml -n NAMESPACE_NAME
Verification
kubectl get serviceaccount -n NAMESPACE_NAME
kubectl get serviceaccount SERVICE_ACCOUNT_NAME -n NAMESPACE_NAME -oyaml
2
3
5.2.9. Apply `templates/deployment` manifest:
Description
Kubernetes resource type.
Name of the deployment
Container name and image name.
Configuring an environment variable in a container using the secret created is previous step.
Configuring health checks for the pod.
Name of the serviceaccount used by this deployment.
Applying Manifest
kubectl apply -f manifests/application/templates/deployment.yaml -n NAMESPACE_NAME
Verification
kubectl get deployment -n NAMESPACE_NAME
kubectl get deployment DEPLOYMENT_NAME -n NAMESPACE_NAME -oyaml
2
3
5.2.10. Apply `templates/service` manifest:
Description
Kubernetes resource type.
Name of the service.
Mapping the container port on the service port.
Applying Manifest
kubectl apply -f manifests/application/templates/service.yaml -n NAMESPACE_NAME
Verification
kubectl get service -n NAMESPACE_NAME
kubectl get service SERVICE_NAME -n NAMESPACE_NAME -oyaml
2
3
5.2.11. To verify it is working, access the url given below
web-NAMESPACE_NAME.DOMAIN/
Replace the DOMAIN/ with your cluster's domain.