Last active
July 18, 2024 14:23
-
-
Save gmaslowski/117f3535173d733e007d0c6c83564888 to your computer and use it in GitHub Desktop.
k8s-cassandra-nodeLabel2pod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: cassandra-rackdc | |
data: | |
cassandra-rackdc.properties: | | |
dc= datacenter | |
rack= RACK | |
--- | |
apiVersion: apps/v1beta1 | |
kind: Deployment | |
metadata: | |
name: node2pod | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
name: node2pod | |
app: node2pod | |
spec: | |
initContainers: | |
- name: node2pod | |
imagePullPolicy: IfNotPresent | |
image: <image-with-k8s-access> | |
command: | |
- "sh" | |
- "-c" | |
- "cp /config/cassandra-rackdc.properties /shared/cassandra-rackdc.properties && \ | |
sed -i.bak s/RACK/$(kubectl get no -Llabel | grep ${NODE_NAME} | awk '{print $6}')/g /shared/cassandra-rackdc.properties" | |
env: | |
- name: NODE_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: spec.nodeName | |
volumeMounts: | |
- name: cassandra-rackdc | |
mountPath: /config/ | |
- name: shared | |
mountPath: /shared/ | |
containers: | |
- name: cassandra | |
image: cassandra | |
volumeMounts: | |
- name: shared | |
mountPath: /etc/cassandra-rackdc.properties | |
subPath: cassandra-rackdc.properties | |
volumes: | |
- name: cassandra-rackdc | |
configMap: | |
name: cassandra-rackdc | |
- name: shared | |
emptyDir: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah maybe a
ClusterRole
,ClusterRoleBinding
andServiceAccount
combo.Pasting for posterity what worked for me while hacking something quick:
Thanks again for the article and the gist!