英文:
Not able to make a folder in elasticsearch pod using yaml file
问题
我想在Elasticsearch的pod中创建一个名为synonyms的文件夹,位于/usr/share/elasticsearch/位置下,使用我的部署YAML文件,我需要做哪些更改才能创建这个文件夹。
以下是我的部署清单文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
namespace: elk
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app-elk
operator: In
values:
- "elastic-tomcat"
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
imagePullPolicy: Always
resources:
requests:
memory: 1Gi
ports:
- containerPort: 9200
protocol: TCP
name: rest
- containerPort: 9300
protocol: TCP
name: inter-node
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
env:
- name: cluster.name
value: elasticsearch-cluster
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.seed_hosts
value: "elasticsearch-cluster-0.elasticsearch"
- name: cluster.initial_master_nodes
value: "elasticsearch-cluster-0"
- name: ES_JAVA_OPTS
value: "-Xms512m -Xmx512m"
- name: network.host
value: "0.0.0.0"
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
securityContext:
privileged: true
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: increase-fd-ulimit
image: busybox
command: ["sh", "-c", "ulimit -n 65536"]
securityContext:
privileged: true
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: elasticsearch-pvc # Create a PVC for data storage
请帮忙,我正在使用Google Kubernetes Engine平台。
英文:
I want to make a folder called synonyms inside the Elasticsearch pod under this location
/usr/share/elasticsearch/ using my deployment YAML file , what changes should I do so that I can create one folder.
here is my deployment manifest file
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
namespace: elk
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app-elk
operator: In
values:
- "elastic-tomcat"
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
imagePullPolicy: Always
resources:
requests:
memory: 1Gi
ports:
- containerPort: 9200
protocol: TCP
name: rest
- containerPort: 9300
protocol: TCP
name: inter-node
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
env:
- name: cluster.name
value: elasticsearch-cluster
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.seed_hosts
value: "elasticsearch-cluster-0.elasticsearch"
- name: cluster.initial_master_nodes
value: "elasticsearch-cluster-0"
- name: ES_JAVA_OPTS
value: "-Xms512m -Xmx512m"
- name: network.host
value: "0.0.0.0"
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
securityContext:
privileged: true
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: increase-fd-ulimit
image: busybox
command: ["sh", "-c", "ulimit -n 65536"]
securityContext:
privileged: true
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: elasticsearch-pvc # Create a PVC for data storage
please help , the platform I am using google kubernetes engine.
答案1
得分: 2
您可以使用init container创建文件夹,并使用您正在运行的command根据需要在主容器中使用它。
此外,您可以运行多个不同的Init容器,您可以使用一个容器来运行多个命令。
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- chown -R 1000:1000 /usr/share/elasticsearch/data
- mkdir /usr/share/elasticsearch/XYZ
- sysctl -w vm.max_map_count=262144
- chmod 777 /usr/share/elasticsearch/data
- chomod 777 /usr/share/elasticsearch/data/node
- chmod g+rwx /usr/share/elasticsearch/data
- chgrp 1000 /usr/share/elasticsearch/data
image: busybox:1.29.2
imagePullPolicy: IfNotPresent
name: set-dir-owner
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
restartPolicy: Always
请注意,这是一个YAML配置示例,用于创建具有多个命令的init容器,并设置文件夹的权限和所有权。
英文:
You can create the folder using init container with command that you are running and utilize it as per requirement later with Main container.
Also, you are running multiple different Init containers you can keep one container with multiple commands
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- chown -R 1000:1000 /usr/share/elasticsearch/data
- mkdir /usr/share/elasticsearch/XYZ
- sysctl -w vm.max_map_count=262144
- chmod 777 /usr/share/elasticsearch/data
- chomod 777 /usr/share/elasticsearch/data/node
- chmod g+rwx /usr/share/elasticsearch/data
- chgrp 1000 /usr/share/elasticsearch/data
image: busybox:1.29.2
imagePullPolicy: IfNotPresent
name: set-dir-owner
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
restartPolicy: Always
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论