Deploying a Delinkcious microservice

Each Delinkcious microservice has a set of Kubernetes resources defined in YAML manifests in its k8s subdirectory. Here is the link service k8s directory:

]$ tree k8s
k8s
├── db.yaml
└── link_manager.yaml

The link_manager.yaml file contains two resources: the Kubernetes deployment and the Kubernetes service. The Kubernetes deployment is as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
name: link-manager
labels:
svc: link
app: manager
spec:
replicas: 1
selector:
matchLabels:
svc: link
app: manager
template:
metadata:
labels:
svc: link
app: manager
spec:
containers:
- name: link-manager
image: g1g1/delinkcious-link:0.2
ports:
- containerPort: 8080

The Kubernetes service is as follows:

apiVersion: v1
kind: Service
metadata:
name: link-manager
spec:
ports:
- port: 8080
selector:
svc: link
app: manager

The db.yaml file describes the database the link service uses to persist its state. Both can be deployed via kubectl in a single command by passing the k8s directory to kubectl apply:

$ kubectl apply -f k8s
deployment.apps "link-db" created
service "link-db" created
deployment.apps "link-manager" created
service "link-manager" created
The main difference between kubectl create and kubectl apply is that create will return an error if a resource already exists.

Deploying from the command line with kubectl is nice, but our goal is to automate the process. Let's understand this.