当前位置:   article > 正文

云原生 | K8S集群helm部署apisix3.1

helm部署apisix

一.安装helm,添加apisix 仓库

1.当前环境是内网,内网环境手动下载安装

下载地址:https://github.com/kubernetes/helm/releases

  1. tar -zxvf helm-v3.10.2-linux-amd64.tar.gz
  2. mv linux-amd64/helm /usr/local/bin/helm

2.执行helm version命令验证:

目前只能查看到客户端的版本,服务器还没有安装

  1. [root@k8s-master-1 ~]# helm version
  2. version.BuildInfo{Version:"v3.10.2", GitCommit:"50f003e5ee8704ec937a756c646870227d7c8b58", GitTreeState:"clean", GoVersion:"go1.18.8"}

3.添加apisix 仓库

  1. [root@k8s-master-1 kubernetes]#helm repo add apisix https://charts.apiseven.com
  2. [root@k8s-master-1 kubernetes]# helm repo list
  3. NAME URL
  4. apisix https://charts.apiseven.com
  5. [root@k8s-master-1 kubernetes]# helm search repo apisix
  6. NAME CHART VERSION APP VERSION DESCRIPTION
  7. apisix/apisix 1.1.1 3.1.1 A Helm chart for Apache APISIX v3
  8. apisix/apisix-dashboard 0.8.0 3.0.0 A Helm chart for Apache APISIX Dashboard
  9. apisix/apisix-ingress-controller 0.11.3 1.6.0 Apache APISIX Ingress Controller for Kubernetes

二.创建apisix所需namespces

  1. [root@k8s-master-1 kubernetes]# kubectl create ns monitoring
  2. namespace/monitoring created
  3. [root@k8s-master-1 kubernetes]# kubectl create ns ingress-apisix
  4. namespace/ingress-apisix created

三.安装apisix

1.安装apisix,dashboard,controller,直接执行以下命令

helm install apisix apisix/apisix --set gateway.type=LoadBalancer --set ingress-controller.enabled=true --namespace ingress-apisix --set dashboard.enabled=true --set ingress-controller.config.apisix.serviceNamespace=ingress-apisix --set ingress-controller.config.kubernetes.apisixRouteVersion="apisix.apache.org/v2beta3" --set apisix.timezone=Asia/Shanghai --set apisix.serviceMonitor.enabled=true --set apisix.serviceMonitor.namespace=monitoring

2.安装完成后,依次执行以下命令

export SERVICE_IP=$(kubectl get svc --namespace ingress-apisix apisix-gateway --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo http://$SERVICE_IP:80

3.查看部署ingress-apisix相关资源

a.查看ns

  1. [root@k8s-master-1 kubernetes]# kubectl get ns
  2. NAME STATUS AGE
  3. ingress-apisix Active 94s
  4. monitoring Active 107s

b.查看pvc是否已绑定

  1. [root@k8s-master-1 kubernetes]# kubectl get pvc -n ingress-apisix
  2. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  3. data-apisix-etcd-0 Bound pvc-6372690f-23ac-48d3-965a-b1eb98c40a0d 8Gi RWO nfs-storage 71s
  4. data-apisix-etcd-1 Bound pvc-173bd000-f46f-46dd-8b7b-05e9e48ecef8 8Gi RWO nfs-storage 71s
  5. data-apisix-etcd-2 Bound pvc-19294e17-b334-4504-8c81-2b2781ccb5a2 8Gi RWO nfs-storage 71s

c.查看apisix的pod是否启动

  1. [root@k8s-master-1 kubernetes]# kubectl get pod -n ingress-apisix
  2. NAME READY STATUS RESTARTS AGE
  3. apisix-597d87c7df-q7rjq 1/1 Running 0 2m32s
  4. apisix-dashboard-5ddf5698df-wb8ww 1/1 Running 3 2m32s
  5. apisix-etcd-0 1/1 Running 0 2m32s
  6. apisix-etcd-1 1/1 Running 0 2m32s
  7. apisix-etcd-2 1/1 Running 0 2m32s
  8. apisix-ingress-controller-65bd744948-v2krz 1/1 Running 0 2m32s

d.查看svc

  1. [root@k8s-master-1 kubernetes]# kubectl get svc -n ingress-apisix
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. apisix-admin ClusterIP 10.98.90.35 <none> 9180/TCP 2m37s
  4. apisix-dashboard ClusterIP 10.99.84.250 <none> 80/TCP 2m38s
  5. apisix-etcd ClusterIP 10.110.154.14 <none> 2379/TCP,2380/TCP 2m37s
  6. apisix-etcd-headless ClusterIP None <none> 2379/TCP,2380/TCP 2m38s
  7. apisix-gateway LoadBalancer 10.105.24.159 <pending> 80:31885/TCP 2m38s
  8. apisix-ingress-controller ClusterIP 10.100.218.33 <none> 80/TCP 2m37s
e.修改apisix-dashboard端口号为:32150和apisix-gateway端口号为:30022
  1. [root@k8s-master-1 kubernetes]# kubectl patch svc apisix-dashboard -p '{"spec":{"type":"NodePort"}}' -n ingress-apisix
  2. service/apisix-dashboard patched
  3. [root@k8s-master-1 kubernetes]# kubectl edit svc apisix-dashboard -n ingress-apisix
  4. service/apisix-dashboard edited
  5. [root@k8s-master-1 kubernetes]# kubectl edit svc apisix-gateway -n ingress-apisix
  6. service/apisix-gateway edited

四.修改apisix的configmap

  1. 开启public-api 插件

  1. 开启jwt-auth认证(任意pod 中执行)

  1. 安装nginx,查看是否启动
  2. [root@k8s-master-1 kubernetes]# kubectl get pod
  3. NAME READY STATUS RESTARTS AGE
  4. nfs-client-provisioner-688fcbdd54-lpxkw 1/1 Running 90 16h
  5. nginx-6799fc88d8-kfx7t 1/1 Running 0 4m15s
  6. 开启public-api 插件
  7. kubectl edit cm/apisix -n ingress-apisix 添加”- public-api” 如下并重启apisix
  8. - proxy-rewrite
  9. - public-api
  10. 开启jwt-auth认证(任意pod 中执行)
  11. curl -X PUT 'http://apisix-admin.ingress-apisix:9180/apisix/admin/routes/get-jwt-sign-route' \
  12. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
  13. -H 'Content-Type: application/json' \
  14. -d '{
  15. "uri": "/get-jwt-sign",
  16. "plugins": {
  17. "public-api": {
  18. "uri": "/apisix/plugin/jwt/sign"
  19. },
  20. "key-auth": {}
  21. }
  22. }'

五.修改访问设置

  1. [root@openresty ~]# cd /usr/local/nginx/conf/vhost
  2. [root@openresty ~]# vim gw-newmmptes443.conf
  3. upstream #访问域名 {
  4. server #nodeip:端口号;
  5. #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
  6. #check_http_send "HEAD / HTTP/1.0\r\n\r\n";
  7. #check_http_expect_alive http_2xx http_3xx;
  8. #session_sticky;
  9. keepalive 6000;
  10. }
  11. server
  12. {
  13. listen #端口号;
  14. server_name #访问域名;
  15. rewrite ^(.*) https://$server_name$ request_uri permanent;
  16. }
  17. server {
  18. listen 443 ssl;
  19. server_name #访问域名;
  20. access_log /usr/local/openresty/nginx/logs/gw-mmptest.access.log;
  21. root html;
  22. index index.html index.htm;
  23. ssl_certificate /root/ssl/myj/214828708690016.pem;
  24. ssl_certificate_key /root/ssl/myj/214828708690016.key;
  25. ssl_session_cache shared:SSL:20m;
  26. ssl_session_timeout 10m;
  27. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv3;
  28. ssl_prefer_server_ciphers on;
  29. # ssl_ciphers 'ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5';
  30. # ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  31. # ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
  32. ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA256:!DHE-RSA-AES128-SHA:!DHE-RSA-AES256-SHA256:!DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
  33. location / {
  34. root html;
  35. index index.html index.htm;
  36. proxy_set_header Host $host;
  37. proxy_set_header X-Real-IP $remote_addr;
  38. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  39. proxy_pass http://#访问域名;
  40. proxy_connect_timeout 6000s;
  41. proxy_send_timeout 6000s;
  42. proxy_read_timeout 6000s;
  43. proxy_buffer_size 64k;
  44. proxy_buffers 4 64k;
  45. proxy_busy_buffers_size 128k;
  46. proxy_temp_file_write_size 128k;
  47. proxy_http_version 1.1;
  48. proxy_set_header Connection "";
  49. }
  50. error_page 404 /50x.html;
  51. error_page 500 502 503 504 /50x.html;
  52. location = /50x.html {
  53. root html;
  54. }
  55. }

1.重启服务

[root@openresty vhost]# nginx -s reload 

2.查看端口号

[root@openresty vhost]# netstat -tnlp

六.dashboard 默认 账号和密码是 admin admin

访问方式

  http://ip:32150 

七.添加测试路由进行测试

1.生成默认路由配置文件

vim apisix-default-route.yaml
  1. kind: ApisixRoute
  2. metadata:
  3. name: default-route
  4. namespace: default
  5. spec:
  6. http:
  7. - backends:
  8. - serviceName: httpbin
  9. servicePort: 80
  10. match:
  11. hosts:
  12. - #解析到外网的域名
  13. paths:
  14. - /httpbin*
  15. - /spec.json
  16. name: httpbin-route
  17. plugins:
  18. - config:
  19. regex_uri:
  20. - ^/httpbin(/|$)(.*)
  21. - /$2
  22. enable: true
  23. name: proxy-rewrite

2.生成测试pod

httpbin.yaml
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. labels:
  6. app: httpbin
  7. name: httpbin
  8. namespace: default
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: httpbin
  14. template:
  15. metadata:
  16. labels:
  17. app: httpbin
  18. spec:
  19. containers:
  20. - image: kennethreitz/httpbin
  21. imagePullPolicy: Always
  22. name: httpbin
  23. dnsPolicy: ClusterFirst
  24. restartPolicy: Always
  25. ---
  26. apiVersion: v1
  27. kind: Service
  28. metadata:
  29. labels:
  30. app: httpbin
  31. name: httpbin
  32. namespace: default
  33. spec:
  34. ports:
  35. - port: 80
  36. protocol: TCP
  37. targetPort: 80
  38. selector:
  39. app: httpbin
  40. sessionAffinity: None
  41. type: ClusterIP

3.执行apisix-default-route.yaml和httpbin.yaml

  1. [root@k8s-master-1 apisix-httpbin]# kubectl apply -f apisix-default-route.yaml
  2. Warning: apisix.apache.org/v2beta3 ApisixRoute is deprecated; use apisix.apache.org/v2 ApisixRoute
  3. apisixroute.apisix.apache.org/default-route created
  4. [root@k8s-master-1 apisix-httpbin]# kubectl apply -f httpbin.yaml
  5. deployment.apps/httpbin created
  6. service/httpbin created

4.查看pod是否启动

  1. [root@k8s-master-1 apisix-httpbin]# kubectl get pod
  2. NAME READY STATUS RESTARTS AGE
  3. httpbin-849ccf48fc-rhppx 1/1 Running 0 77s
  4. nfs-client-provisioner-688fcbdd54-lpxkw 1/1 Running 346 2d16h
  5. nginx-6799fc88d8-kfx7t 1/1 Running 0 47h

5.查看路由相关信息

  1. [root@k8s-master-1 apisix-httpbin]# kubectl get ar
  2. NAME HOSTS URIS AGE
  3. default-route ["gw-mmptest.myj.com.cn"] ["/httpbin*","/spec.json"] 104s

八.登录apisix查看默认路由已经启动

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/214225
推荐阅读
相关标签
  

闽ICP备14008679号