apiVersion: v1
kind: Service
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
spec:
ports:
- port: 9200
protocol: TCP
targetPort: db
selector:
k8s-app: elasticsearch-logging
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
spec:
replicas: 3
template:
metadata:
labels:
k8s-app: elasticsearch-logging
spec:
containers:
- name: elasticsearch-logging
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
resources:
limits:
cpu: 1000m
memory: 2048Mi
requests:
cpu: 100m
memory: 200Mi
ports:
- containerPort: 9200
name: db
protocol: TCP
- containerPort: 9300
name: db
protocol: TCP
volumeMounts:
- name: elasticsearch-logging
mountPath: /usr/share/elasticsearch/data
env:
- name: "NAMESPACE"
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "NODE_NAME"
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: "CLUSTER_NAME"
value: "k8s-logs"
- name: "NUM_SHARDS"
value: "1"
- name: "HEAP_SIZE"
value: "256m"
- name: "FS_TYPE"
value: ""
volumes:
- name: elasticsearch-logging
emptyDir: {}
这个示例展示了如何在Kubernetes中部署一个Elasticsearch高可用性集群。它使用Deployment来确保集群的副本数,并且使用Service来暴露集群服务。集群配置通过环境变量来设置,并且使用了emptyDir作为存储卷来保证数据的临时性。这个配置适用于学习和测试,并非生产环境下的推荐配置。在生产环境中,你需要使用外部存储,并且配置更多的安全和监控特性。