Configure the Databases with Affinity
Configure the Databases with Affinity
Configure the Databases with Affinity
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: /mnt/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
apiVersion: postgres.crunchydata.com/v1
kind: Cluster
metadata:
name: my-postgres-cluster
spec:
instances:
- name: my-postgres
replicas: 2
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/worker
operator: Exists
storage:
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
volumeName: postgres-pvc
kubectl apply -f postgres-cluster.yaml
Final Steps
++++++++++++++++++++++++++++++++++++++
Structure of matchExpressions
2. operator: The relationship between the key and the values. Possible
operators include:
o In: The node must have the specified key with one of the values.
o NotIn: The node must not have the specified key with any of the
values.
o Exists: The node must have the specified key (regardless of its
value).
o Gt: The value of the key must be greater than the specified value
(only for numeric values).
o Lt: The value of the key must be less than the specified value
(only for numeric values).
3. values: An array of values that the key is compared against (used with
the In and NotIn operators).
Example of matchExpressions
yaml
Copy code
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "disktype"
operator: In
values:
- "ssd"
- "hdd"
- key: "environment"
operator: NotIn
values:
- "development"
Explanation of Example
The first matchExpression checks if the node has the label disktype
with a value of either ssd or hdd.
The second matchExpression ensures that the node does not have the
label environment set to development.
This configuration ensures that Postgres pods are scheduled on nodes that
meet both criteria.
Summary
When configuring matchExpressions for Crunchy Data Postgres, you can use
them to fine-tune the scheduling of your database pods based on node
labels, ensuring they run in the appropriate environments or on nodes with
specific characteristics.
4o mini
You said:
what are some of the list of keys available in Crunchy Data for Postgres
ChatGPT said:
ChatGPT
In Crunchy Data for Postgres, the specific keys available for node affinity
typically depend on the Kubernetes environment and how the nodes are
labeled. However, some common keys that might be used in configurations
include:
8. tier: Specifies the tier level of the service (e.g., frontend, backend).
Custom Keys
To see the specific labels available in your Kubernetes cluster, you can run:
bash
Copy code
This will list all nodes along with their labels, helping you identify which keys
are applicable for your setup.
4o mini
You said:
ChatGPT said:
ChatGPT
In a Kubernetes cluster, you typically have control plane nodes and worker
nodes, each serving different roles. The labels (or keys) associated with
these nodes can help in managing scheduling, resource allocation, and
service deployment. Here's an overview:
Control plane nodes manage the Kubernetes cluster and usually run
components like the API server, controller manager, and scheduler. Common
labels for control plane nodes might include:
Worker Nodes
Worker nodes run the actual applications (pods). Common labels for worker
nodes might include:
1. node-role.kubernetes.io/worker: Indicates that the node is a
worker.
Example Labels
yaml
Copy code
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "node-role.kubernetes.io/master"
operator: DoesNotExist
- key: "node-role.kubernetes.io/worker"
operator: Exists
Summary