Skip to content

Affinity and Labeling Nodes

Bash
kubectl get nodes --show-labels
Bash
kubectl label nodes <your-node-name> somename=somevalue

Pod

YAML
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: somename
            operator: In
            values:
            - somevalue            
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent

Deployment

YAML
spec:
  replicas: 1
  selector:  
    matchLabels:
      app: xwiki
  template:
    metadata:
      labels:
        app: xwiki
    spec:
      containers:
      - name: xwiki
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - name: durbok-xyz
          mountPath: /some-path-in-a-container
      volumes:
      - name: xwiki
        persistentVolumeClaim:
          claimName: xwiki-pvc
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            preference:
              matchExpressions:
              - key: disktype
                operator: In
                values:
                - 200ssd
Back to top