The workload to be created will be deployed on the same node as the selected affinity workloads.
This section uses Nginx as an example to describe how to create a workload using kubectl.
Prerequisites
The ECS where the kubectl client runs has been connected to your cluster. For details, see Connecting to a Cluster Using kubectl.
Procedure
When using kubectl to create a Deployment or using kubectl to create a StatefulSet, configure workload-workload affinity. The following is an example YAML file for workload-workload affinity.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
imagePullSecrets:
- name: default-secret
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app #workload's label key
operator: In
values:
- test #workload's label value
This method can be used to add, edit, or delete scheduling policies.