docker 部署 apisix

2023年1月5日 4348点热度 0人点赞 2条评论
内容纲要

单机版本

首先创建虚拟网络,以便应用之间通讯:

docker network create apisix-network --driver bridge

创建 etcd 持久化存储卷:

docker volume create --name etcd-data

启动单机版本的 etcd:

docker run -d --name etcd \
  --network apisix-network \
  --volume=etcd-data:/etcd-data \
  -p 2379:2379 \
  -p 2380:2380 \
  -e ALLOW_NONE_AUTHENTICATION=yes \
  -e ETCD_ADVERTISE_CLIENT_URLS=http://127.0.0.1:2379 \
  bitnami/etcd:latest

创建 apisix 配置文件

cat << EOF > /data/apisix/apisix_conf/config.yaml
deployment:
  role: traditional
  role_traditional:
    config_provider: etcd
  admin:
    allow_admin:
      - 0.0.0.0/0  # Please set it to the subnet address you obtained.
                  # If not set, by default all IP access is allowed.
  etcd:
    host:
      - "http://etcd:2379"
    prefix: "/apisix"
    timeout: 30
EOF

部署 apisix:

 docker run -d --name apache-apisix \
  --network apisix-network \
  -p 9080:9080 \
  -p 9180:9180 \
  -v /data/apisix/apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml \
  apache/apisix

测试是否有反应:

curl "http://127.0.0.1:9180/apisix/admin/services/" \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'

编辑 apisix-dashboard 配置文件:

/data/apisix/apisix-dashboard/conf.yaml

配置文件参考:https://github.com/apache/apisix-dashboard/blob/master/api/conf/conf.yaml

conf:
  listen:
    host: 0.0.0.0
    port: 9000
  etcd:
    endpoints:
      - "http://etcd:2379" # etcd 的端口地址
  log:
    error_log:
      level: warn
      file_path:
        logs/error.log
    access_log:
      file_path:
        logs/access.log
authentication:
  secret:
    secret              # secret for jwt token generation.
  expire_time: 3600     # jwt token expire time, in second
  users:                # yamllint enable rule:comments-indentation
    - username: admin   # username and password for login <code>manager api</code>
      password: admin
    - username: user
      password: user

plugins:
  - api-breaker
  - authz-casbin
  - authz-casdoor
  - authz-keycloak
  - aws-lambda
  - azure-functions
  - basic-auth
  # - batch-requests
  - clickhouse-logger
  - client-control
  - consumer-restriction
  - cors
  - csrf
  - datadog
  # - dubbo-proxy
  - echo
  - error-log-logger
  # - example-plugin
  - ext-plugin-post-req
  - ext-plugin-post-resp
  - ext-plugin-pre-req
  - fault-injection
  - file-logger
  - forward-auth
  - google-cloud-logging
  - grpc-transcode
  - grpc-web
  - gzip
  - hmac-auth
  - http-logger
  - ip-restriction
  - jwt-auth
  - kafka-logger
  - kafka-proxy
  - key-auth
  - ldap-auth
  - limit-conn
  - limit-count
  - limit-req
  - loggly
  # - log-rotate
  - mocking
  # - node-status
  - opa
  - openid-connect
  - opentelemetry
  - openwhisk
  - prometheus
  - proxy-cache
  - proxy-control
  - proxy-mirror
  - proxy-rewrite
  - public-api
  - real-ip
  - redirect
  - referer-restriction
  - request-id
  - request-validation
  - response-rewrite
  - rocketmq-logger
  - server-info
  - serverless-post-function
  - serverless-pre-function
  - skywalking
  - skywalking-logger
  - sls-logger
  - splunk-hec-logging
  - syslog
  - tcp-logger
  - traffic-split
  - ua-restriction
  - udp-logger
  - uri-blocker
  - wolf-rbac
  - zipkin
  - elasticsearch-logge
  - openfunction
  - tencent-cloud-cls
  - ai
  - cas-auth

部署管理面板:

docker run -d --name apisix-dashboard \
           --network apisix-network \
           -p 9000:9000        \
           -v /data/apisix/apisix-dashboard/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml \
           apache/apisix-dashboard:2.15.0-centos

docker-conpose

使用 docker-compose 一键部署,参考:
https://github.com/apache/apisix-docker/blob/master/example/docker-compose.yml

helm

首先创建三个 pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: apisi-etcd-pv0
spec:
  capacity:
    storage: 8Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /data/etcd0
    type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: apisi-etcd-pv1
spec:
  capacity:
    storage: 8Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /data/etcd1
    type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: apisi-etcd-pv2
spec:
  capacity:
    storage: 8Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /data/etcd2
    type: DirectoryOrCreate
---
kubectl -n apisix apply -f pv.yaml

命名空间需要按照实际修改。

安装 apisix

helm install apisix apisix/apisix --create-namespace  --namespace apisix

安装 dashboard

helm install apisix-dashboard apisix/apisix-dashboard --create-namespace --namespace apisix

痴者工良

高级程序员劝退师

文章评论

  • 痴者工良

    kubernetes 可以用这个快速部署 https://github.com/zaunist/apisix-on-kubernetes

    2023年5月11日
  • 痴者工良

    国内源比较旧,可以使用 registry.docker.com/apache/apisix:latest 拉取最新的镜像。

    2023年1月6日