Running a workload on Spot
Next, let's modify our sample retail store application to run the catalog component on the newly created Spot instances. To do so, we'll utilize Kustomize to apply a patch to the catalog
Deployment, adding a nodeSelector
field with eks.amazonaws.com/capacityType: SPOT
.
- Kustomize Patch
- Deployment/catalog
- Diff
apiVersion: apps/v1
kind: Deployment
metadata:
name: catalog
spec:
template:
spec:
nodeSelector:
eks.amazonaws.com/capacityType: SPOT
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/created-by: eks-workshop
app.kubernetes.io/type: app
name: catalog
namespace: catalog
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: service
app.kubernetes.io/instance: catalog
app.kubernetes.io/name: catalog
template:
metadata:
annotations:
prometheus.io/path: /metrics
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
labels:
app.kubernetes.io/component: service
app.kubernetes.io/created-by: eks-workshop
app.kubernetes.io/instance: catalog
app.kubernetes.io/name: catalog
spec:
containers:
- env:
- name: DB_USER
valueFrom:
secretKeyRef:
key: username
name: catalog-db
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: catalog-db
envFrom:
- configMapRef:
name: catalog
image: public.ecr.aws/aws-containers/retail-store-sample-catalog:0.4.0
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 3
name: catalog
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /health
port: 8080
periodSeconds: 5
successThreshold: 3
resources:
limits:
memory: 512Mi
requests:
cpu: 250m
memory: 512Mi
securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
volumeMounts:
- mountPath: /tmp
name: tmp-volume
nodeSelector:
eks.amazonaws.com/capacityType: SPOT
securityContext:
fsGroup: 1000
serviceAccountName: catalog
volumes:
- emptyDir:
medium: Memory
name: tmp-volume
runAsUser: 1000
volumeMounts:
- mountPath: /tmp
name: tmp-volume
+ nodeSelector:
+ eks.amazonaws.com/capacityType: SPOT
securityContext:
fsGroup: 1000
serviceAccountName: catalog
volumes:
Apply the Kustomize patch with the following command.
namespace/catalog unchanged
serviceaccount/catalog unchanged
configmap/catalog unchanged
secret/catalog-db unchanged
service/catalog unchanged
service/catalog-mysql unchanged
deployment.apps/catalog configured
statefulset.apps/catalog-mysql unchanged
Ensure the successful deployment of your app with the following command.
Finally, let's verify that the catalog pods are running on Spot instances. Run the following two commands.
NAME READY STATUS RESTARTS AGE IP NODE
catalog-6bf46b9654-9klmd 1/1 Running 0 7m13s 10.42.118.208 ip-10-42-99-254.us-east-2.compute.internal
NAME STATUS ROLES AGE VERSION
ip-10-42-139-140.us-east-2.compute.internal Ready <none> 16m v1.31-eks-036c24b
ip-10-42-99-254.us-east-2.compute.internal Ready <none> 16m v1.31-eks-036c24b
The first command tells us that the catalog pod is running on node ip-10-42-99-254.us-east-2.compute.internal
, which we verify is a Spot instance by matching it to the output of the second command.
In this lab, you deployed a managed node group that creates Spot instances, and then modified the catalog
deployment to run on the newly created Spot instances. Following this process, you can modify any of the running deployments in the cluster by adding the nodeSelector
parameter, as specified in the Kustomization patch above.