apiVersion: v1
kind: Pod
metadata:
  name: podaffinity-for-pod-1
  labels:
    role: cache
spec:
  containers:
    - name: cache
      image: redis
  affinity:
    podAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: role
                operator: In
                values:
                - frontend
            topologyKey: kubernetes.io/hostname