Kubernetes1.21部署apisix网关

目录

1、安装nfs-subdir-external-provisioner

2、helm安装apisix

3、Prometheus使用kubesphere内置的

4、创建ServiceMonitor

5、安装Grafana   grafana.yaml kubectl apply -f grafana.yaml(参照官网)

6、配置Grafana ,添加Prometheus数据源

 7、部署whoami或者httpbin,配置网关,进行访问

8、创建Grafana Dashboard,选择import,效果如下

9、运行pod

 10、应用访问,加上gateway的端口号



1、安装nfs-subdir-external-provisioner

helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner  -f values.yaml     -n default

docker pull k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
下载地址nfs-subdir-external-provisioner安装文件资源-CSDN文库

2、helm安装apisix

helm repo add apisix https://charts.apiseven.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

helm install apisix apisix/apisix  \
--set ingress-controller.enabled=true \
--set dashboard.enabled=true \
--set gateway.tls.enabled=true \
--set etcd.volumePermissions.enabled=true \
--set etcd.persistence.storageClass="nfs-client" \
--set etcd.persistence.size="22Gi" \
--set ingress-controller.config.apisix.adminKey="edd1c9f034335f136f87ad84b625c8f1" \
--set admin.credentials.admin="edd1c9f034335f136f87ad84b625c8f1" \
--set admin.credentials.viewer="4054f7cf07e344346cd3f287985e76a2" \
--set ingress-controller.config.apisix.serviceNamespace=apisix  --namespace apisix --create-namespace

安装完成,查看网关的打印地址

export NODE_PORT=$(kubectl get --namespace apisix -o jsonpath="{.spec.ports[0].nodePort}" services apisix-gateway)
export NODE_IP=$(kubectl get nodes --namespace apisix -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

3、Prometheus使用kubesphere内置的

使用第二步安装的apisix service 端口未暴露,需要修改暴露出来

Kubernetes1.21部署apisix网关_第1张图片

4、创建ServiceMonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: apisix
  namespace: apisix
spec:
  endpoints:
    - scheme: http
      targetPort: monitor
      path: /apisix/prometheus/metrics
      interval: 15s
  namespaceSelector:
    matchNames:
      - apisix
  selector:
    matchLabels:
      app.kubernetes.io/name: apisix
      app.kubernetes.io/version: 3.3.0
      helm.sh/chart: apisix-2.0.0 

5、安装Grafana   grafana.yaml kubectl apply -f grafana.yaml(参照官网)

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
  namespace: apisix
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: apisix
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      securityContext:
        fsGroup: 472
        supplementalGroups:
          - 0
      containers:
        - name: grafana
          image: grafana/grafana:9.1.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
              name: http-grafana
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /robots.txt
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 2
          livenessProbe:
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 3000
            timeoutSeconds: 1
          resources:
            requests:
              cpu: 250m
              memory: 750Mi
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-pv
      volumes:
        - name: grafana-pv
          persistentVolumeClaim:
            claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: apisix
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-grafana
  selector:
    app: grafana
  sessionAffinity: None
  type: LoadBalancer

prometheus获取apisix的信息可能会初选拒绝连接的情况,默认apisix暴露的地址是本地的,需要修改下配置

Kubernetes1.21部署apisix网关_第2张图片

 正常情况,看到信息应该如下图

Kubernetes1.21部署apisix网关_第3张图片

6、配置Grafana ,添加Prometheus数据源

地址是:http://prometheus-operated.kubesphere-monitoring-system.svc:9090

Kubernetes1.21部署apisix网关_第4张图片

 7、部署whoami或者httpbin,配置网关,进行访问

Kubernetes1.21部署apisix网关_第5张图片

Kubernetes1.21部署apisix网关_第6张图片

8、创建Grafana Dashboard,选择import,效果如下

Kubernetes1.21部署apisix网关_第7张图片

 Kubernetes1.21部署apisix网关_第8张图片

9、运行pod

Kubernetes1.21部署apisix网关_第9张图片

 10、应用访问,加上gateway的端口号

httpbin.org (liebe.com.cn)

Kubernetes1.21部署apisix网关_第10张图片

你可能感兴趣的:(kubernetes)