一、修改api-server的selflink

vim /etc/kubernetes/manifests/kube-apiserver.yaml
加入此行
- --feature-gates=RemoveSelfLink=false

在这里插入图片描述
所有节点重启kubelet

`systemctl restart kub`elet

二、开始部署es三个节点
vim elasticsearch-statefulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-cluster
  namespace: kube-logging
spec:
  serviceName: elasticsearch
  replicas: 3
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
      - name: elasticsearch
        image: elasticsearch:7.12.1
        imagePullPolicy: IfNotPresent
        resources:
            limits:
              cpu: 1000m
            requests:
              cpu: 100m
        ports:
        - containerPort: 9200
          name: rest
          protocol: TCP
        - containerPort: 9300
          name: inter-node
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
        env:
          - name: cluster.name
            value: k8s-logs
          - name: node.name
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: discovery.seed_hosts
            value: "es-cluster-0.elasticsearch.kube-loggin.svc.cluster.local,es-cluster-1.elasticsearch,kube-loggin.svc.cluster.local,es-cluster-2.elasticsearch.kube-loggin.svc.cluster.local"
          - name: cluster.initial_master_nodes
            value: "es-cluster-0,es-cluster-1,es-cluster-2"
          - name: ES_JAVA_OPTS
            value: "-Xms512m -Xmx512m"
      initContainers:
      - name: fix-permissions
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
        securityContext:
          privileged: true
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
      - name: increase-vm-max-map
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      - name: increase-fd-ulimit
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c", "ulimit -n 65536"]
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: data
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: do-block-storage
      resources:
        requests:
          storage: 10Gi


部署

 kubectl apply -f elasticsearch-statefulset.yaml 

查看状态

 [root@master elk]# kubectl get pod -n kube-logging -owide 
NAME           READY   STATUS    RESTARTS   AGE     IP                NODE    NOMINATED NODE   READINESS GATES
es-cluster-0   1/1     Running   0          7m37s   192.168.104.15    node2   <none>           <none>
es-cluster-1   1/1     Running   0          7m31s   192.168.104.16    node2   <none>           <none>
es-cluster-2   1/1     Running   1          4h6m    192.168.166.147   node1   <none>           <none>

映射es的端口测试

kubectl port-forward es-cluster-0 9200:9200 --namespace=kube-logging

测试,新开一个终端

[root@master ~]# curl 127.0.0.1:9200
{
  "name" : "es-cluster-0",
  "cluster_name" : "k8s-logs",
  "cluster_uuid" : "3bmtwQgESi-4_Ap3HnGadQ",
  "version" : {
    "number" : "7.12.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "3186837139b9c6b6d23c3200870651f10d3343b7",
    "build_date" : "2021-04-20T20:56:39.040728659Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

查看节点,可以看到es-0是master节点。带有*的是

[root@master ~]# curl http://localhost:9200/_cat/nodes
192.168.104.21 45 19 20 0.36 0.75 0.60 cdfhilmrstw - es-cluster-2
192.168.104.19 53 23 20 0.36 0.75 0.60 cdfhilmrstw - es-cluster-1
192.168.104.20 55 19 22 0.36 0.75 0.60 cdfhilmrstw * es-cluster-0

到此es安装完毕

三、可视化的kibana部署
vim kiban.yaml

apiVersion: v1
kind: Service
metadata:
  name: kibana
  namespace: kube-logging
  labels:
    app: kibana
spec:
  type: NodePort
  ports:
  - port: 5601
    nodePort: 31000
  selector:
    app: kibana
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana
  namespace: kube-logging
  labels:
    app: kibana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
      labels:
        app: kibana
    spec:
      containers:
      - name: kibana
        image: docker.elastic.co/kibana/kibana:7.2.0
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: 1000m
          requests:
            cpu: 100m
        env:
          - name: ELASTICSEARCH_URL
            value: http://elasticsearch.kube-logging.svc.cluster.local:9200
        ports:
        - containerPort: 5601
kubectl apply -f kibana.yaml

查看pod和svc的ip

[root@master elk]# kubectl get pod -n kube-logging 
NAME                      READY   STATUS    RESTARTS   AGE
es-cluster-0              1/1     Running   1          61m
es-cluster-1              1/1     Running   1          61m
es-cluster-2              1/1     Running   0          29m
kibana-66f59798b7-gd6vh   1/1     Running   0          5m19

查看svc

[root@master elk]# kubectl get svc -n kube-logging 
NAME            TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)             AGE
elasticsearch   ClusterIP   None         <none>        9200/TCP,9300/TCP   28h
kibana          NodePort    10.96.24.8   <none>        5601:31000/TCP      2m46s

浏览器登录
http://节点ip:31000

在这里插入图片描述
在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐