记录k8s安装es

Posted uglyliu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了记录k8s安装es相关的知识,希望对你有一定的参考价值。

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: elasticsearch-pdb
  namespace: test
spec:
  selector:
    matchLabels:
      app: elasticsearch
  maxUnavailable: 1
---
apiVersion: apps/v1 
kind: StatefulSet
metadata:
  name: elasticsearch
  namespace: test 
spec:
  serviceName: elasticsearch-hs
  replicas: 3
  selector:
    matchLabels:
      app: elasticsearch
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: elasticsearch 
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                    - elasticsearch
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: elasticsearch
        image: 172.168.27.239/devops/elasticsearch:7.7.0        #支持7.7.0,7.3.0,6.4.2
        resources:
            limits:
              cpu: 1
              memory: 2Gi
            requests:
              cpu: 0.01
              memory: 1Gi
        ports:
        - containerPort: 9200 
          name: rest 
          protocol: TCP
        - containerPort: 9300 
          name: inter-node 
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
        - name: plugins
          mountPath: /usr/share/elasticsearch/plugins
        env:
          - name: cluster.name 
            value: k8s-logs 
          - name: node.name
            valueFrom:
              fieldRef:
                fieldPath: metadata.name 
          - name: discovery.zen.ping.unicast.hosts
            value: "elasticsearch-0.elasticsearch-hs,elasticsearch-1.elasticsearch-hs,elasticsearch-2.elasticsearch-hs"
          - name: discovery.zen.minimum_master_nodes
            value: "2"
          - name: cluster.initial_master_nodes    #此参数es7以上才能设置
            value: elasticsearch-0,elasticsearch-1
          - name: ES_JAVA_OPTS
            value: "-Xms1536m -Xmx1536m"
          - name: TZ
            value: "Asia/Shanghai"
      initContainers:
      - name: fix-permissions-data
        image: 172.168.27.239/devops/busybox:1.28.3
        command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
        securityContext:
          privileged: true
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
      - name: fix-permissions-plugins
        image: 172.168.27.239/devops/busybox:1.28.3
        command: ["sh", "-c", "rm -fr /usr/share/elasticsearch/plugins/lost+found && chown -R 1000:1000 /usr/share/elasticsearch/plugins"]
        securityContext:
          privileged: true
        volumeMounts:
        - name: plugins
          mountPath: /usr/share/elasticsearch/plugins
      - name: increase-vm-max-map
        image: 172.168.27.239/devops/busybox:1.28.3
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      - name: increase-fd-ulimit
        image: 172.168.27.239/devops/busybox:1.28.3
        command: ["sh", "-c", "ulimit -n 65536"]
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: data
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: ceph-rbd-gd-1
      resources:
        requests:
          storage: 5Gi
  - metadata:
      name: plugins
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: ceph-rbd-gd-1
      resources:
        requests:
          storage: 200Mi
---
kind: Service
apiVersion: v1
metadata:
  name: elasticsearch-hs
  namespace: test
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  clusterIP: None
  ports:
    - port: 9300
      targetPort: 9300
---
kind: Service
apiVersion: v1
metadata:
  name: elasticsearch-cs
  namespace: test
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  ports:
    - port: 9200
      targetPort: 9200
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: elasticsearch-ingress
  namespace: test
spec:
  rules:
  - host: elasticsearch.gdcattsoft2.com
    http:
      paths:
      - path: /
        backend:
          serviceName: elasticsearch-cs
          servicePort: 9200

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kibana
  namespace: test
spec:
  rules:
  - host: kibana.gdcattsoft2.com
    http:
      paths:
      - path: /
        backend:
          serviceName: kibana
          servicePort: 5601
---
apiVersion: v1
kind: Service
metadata:
  name: kibana
  namespace: test
  labels:
    app: kibana
spec:
  ports:
  - port: 5601
    targetPort: 5601
  selector:
    app: kibana
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana 
  namespace: test
  labels:
    app: kibana
spec:
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
      labels:
        app: kibana
    spec:
      containers:
      - name: kibana 
        image: 172.168.27.239/devops/kibana:7.7.0    #支持7.7.0,7.3.0,6.4.2
        resources:
          limits:
            cpu: 1
            memory: 1Gi
          requests:
            cpu: 0.1
            memory: 256Mi
        env:
          #- name: ELASTICSEARCH_URL                     #7以下版本配置URL 
          #  value: http://elasticsearch-cs:9200
          - name: ELASTICSEARCH_HOSTS			 #7以上版本配置HOSTS
            value: http://elasticsearch-cs:9200
          - name: TZ
            value: "Asia/Shanghai"
        ports:
        - containerPort: 5601 

以上是关于记录k8s安装es的主要内容,如果未能解决你的问题,请参考以下文章

2022-02-12:k8s安装es,yaml如何写?

ES7-Es8 js代码片段

“ES7 React/Redux/GraphQL/React-Native 片段”不适用于 javascript 文件。除了安装它,我还需要配置其他东西吗?

k8s1.4.3安装实践记录-k8s安装

docker 搭建es+es基本使用

ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段