项目地址:
Install Ingress APISIX on Minikube
下载安装minikube
Install Minikube
下载安装helm
Install Helm
git下载Apisix charts项目
Clone Apache APISIX Charts
开启minikube
minikube start
开启minikube并且创建命名空间ingress-apisix
kubectl create namespace ingress-apisix
*** 查看是否创建成功ingress-apisix命名空间
kubectl get namespace
创建成功后用helm安装Apisix,进入git clone的Apisix charts项目
cd /path/to/apisix-helm-chart
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add apisix https://charts.apiseven.com
# Use `helm search repo apisix` to search charts about apisix
helm repo update
helm install apisix apisix/apisix \
--set admin.allow.ipList="{0.0.0.0/0}" \
--namespace ingress-apisix
kubectl get service --namespace ingress-apisix
创建成功后用helm安装Apisix-ingress-controller
# install apisix-ingress-controller
helm install apisix-ingress-controller apisix/apisix-ingress-controller \
--set image.tag=dev \
--set config.apisix.baseURL=http://apisix-admin:9180/apisix/admin \
--set config.apisix.adminKey=edd1c9f034335f136f87ad84b625c8f1 \
--namespace ingress-apisix
创建成功,查看k8s的dashboard,修改命名空间看到apisix的de ploments创建成功
kubectl dashboard
minikube宿主机执行kubectl查看对应创建的pods
kubectl get pods -n ingress-apisix
测试部署k8s集群内的web服务
创建文件deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin
spec:
replicas: 2
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
spec:
terminationGracePeriodSeconds: 0
containers:
- livenessProbe:
image: "jocatalin/kubernetes-bootcamp:v1"
#image: "kennethreitz/httpbin"
#image: "k8s.gcr.io/echoserver:1.4"
imagePullPolicy: IfNotPresent
name: httpbin
ports:
- containerPort: 80
name: httpbin
protocol: "TCP"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: testbin
spec:
replicas: 2
selector:
matchLabels:
app: testbin
template:
metadata:
labels:
app: testbin
spec:
terminationGracePeriodSeconds: 0
containers:
- livenessProbe:
image: "jocatalin/kubernetes-bootcamp:v1"
imagePullPolicy: IfNotPresent
name: testbin
ports:
- containerPort: 80
name: testbin
protocol: "TCP"
保存本文件后执行创建deployment(注意⚠️deployment的命名空间要和apisix保持一致,本次apisix的命名空间是ingress-apisix)
kubectl apply -f deployment.yaml -n ingress-apisix
%查看是否创建成功deployment服务
kubectl get deployment -n ingress-apisix
展示出对应testbin表示创建成功
之后创建service.yaml文件
apiVersion: v1
kind: Service
metadata:
name: httpbin
spec:
selector:
app: httpbin
ports:
- name: httpbin
port: 80
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: testbin
spec:
selector:
app: testbin
ports:
- name: testbin
port: 80
targetPort: 8080
创建保存文件后执行生成service(注意⚠️service的命名空间也要和apisix保持一致)
kubectl apply -f service.yaml -n ingress-apisix
***查看是否创建成功service服务
kubectl get service -n ingress-apisix
查看是否创建testbin, httpbin服务成功
创建成功后测试一下service直接映射外网看看是否可以访问对应的deployment
minikube service httpbin-service-test --url -n ingress-apisix
minikube会映射本机一个127.0.0.1:****的随机端口,浏览器直接访问查看是否能够访问
浏览器展示“Hello Kubernetes bootcamp! *****”表示映射成功
创建ingress.yaml文件(apisix可以直接创建ApisixRoute替代ingress的功能)
apiVersion: apisix.apache.org/v2alpha1
#apiVersion: apisix.apache.org/v2beta1
kind: ApisixRoute
metadata:
name: httpserver-route
namespace: ingress-apisix
spec:
http:
- name: rule1
match:
# hosts:
# - local.httpbin.org
paths:
- /ip
backend:
serviceName: httpbin
servicePort: 80
- name: rule2
match:
# hosts:
# - local.httpbin.org
paths:
- /testpath
backend:
serviceName: testbin
servicePort: 80
保存成功后当前文件同目录下运行(namespace写在了yaml里,自定义namespace的可以改动yaml的namespace保证和web容器的和apisix的namespace都一样)
kubectl apply -f ingress.yaml
***查看是否创建成功service服务
kubectl get apisixroute -n ingress-apisix
可以查看绑定的路由信息
映射外网
minikube service apisix-gateway --url -n ingress-apisix
访问127.0.0.1:****/ip看看是否能够映射展示页面,浏览器展示“Hello Kubernetes bootcamp! *****”表示映射成功
安装遇到的坑点:
1.ingress-apisix-controller的安装版本,官网上是dev,实例说明上是0.5.0,需要更新最新的1.1.0版本
2.apisix的这一套网管都是安装在默认ingress-apisix的命名空间下的,自己部署的容器服务都是其他命名空间(默认为default),自己写的apisixroute路由文件也需要保持和他们相同的命名空间,命名空间一致才能检测到对应的服务信息,比较坑
3.apisix可以同步ingress文件信息或者直接使用apisixroute文件类型部署,选择一种方式就可以了,不要搞混了