Now that we have a kubernetes cluster up and running on our local machine, we can now look at creating a deployment.yaml for our comments API.
The deployment.yml will effectively contain everything that Kubernetes needs to know in order to run our application within the cluster as a number of pods.
Let’s dive in and start defining this. We’ll start off by creating a new directly under which this configuration will live called
config and then we’ll create a new
deployment.yml file within this:
--- apiVersion: apps/v1 kind: Deployment metadata: name: api.tutorialedge.net spec: replicas: 3 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 selector: matchLabels: name: api.tutorialedge.net template: metadata: labels: name: api.tutorialedge.net spec: containers: - name: application image: "forbsey/comments-api:latest" imagePullPolicy: Always ports: - containerPort: 8080 env: - name: DB_PORT value: "$DB_PORT" - name: DB_HOST value: "$DB_HOST" - name: DB_PASSWORD value: "$DB_PASSWORD" - name: DB_TABLE value: "$DB_TABLE" - name: DB_USERNAME value: "$DB_USERNAME"