11.2. Django Deployment#
In this lab I walk you through updating the nginx deployment from the previous lab to use your Django pod template. With the new deployment you will be able to scale your application easily. At the end of the lab we will redo the load testing from 8.2. Stress Testing with Locust.
Step 1: Carefully Copy and Paste#
One thing that is really challenging with YAML is copy/paste. That’s because indentation matters so it’s easy to inadvertently change the meaning of things when you copy and paste. Here are some guidelines for how to get it right:
When you copy always start from the left most column.
After you paste you can adjust the indentation by pressing
Tabto move to the left andShift+Tabto move to the right.
Your nginx deployment should look like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Cut out everything under the spec.template.spec key:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
And paste everything under the spec: key in your pod below. It should look
something like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
...
Step 2: Remove the Database Volume#
You don’t need the database volume anymore. Remove these two segments from your pod template inside of the deployment:
The volume mount:
volumeMounts:
- name: db
mountPath: /data
The volumes:
volumes:
- name: db
persistentVolumeClaim:
claimName: mysite-data
Step 3: Remove Unused Files#
You now have a pod.yaml and a pvc.yaml file that aren’t used anymore. Delete
them.
Step 4: Load Testing#
Repeat the load test procedure with 1, 2 and 3 replicas. Are there new bottlenecks?