我们再创建在创建好的集群中,里面的app需要对外暴露接口,我们才可以访问,要么你就通过NODEPORT 访问对应节点的IP,要么就通过集群统一的入口ingress代理。
https://kind.sigs.k8s.io/docs/user/ingress/ kind教程中 给我们讲述了3种方法,我尝试了2中,nginx有点坑爹,镜像拉不下来。我只能用上第一种ambassador了。
1.我们首先用kind 建立一个集群,主机端口9980 -- 80 (kind docker 里的端口)
kind配置如下:
kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane kubeadmConfigPatches: - | kind: InitConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "ingress-ready=true" extraPortMappings: - containerPort: 80 hostPort: 9980 protocol: TCP - containerPort: 443 hostPort: 9443 protocol: TCP - role: worker
2.创建好集群后,安装ambassador
(1)kubectl apply -f https://github.com/datawire/ambassador-operator/releases/latest/download/ambassador-operator-crds.yaml
(2)kubectl apply -n ambassador -f https://github.com/datawire/ambassador-operator/releases/latest/download/ambassador-operator-kind.yaml
(3)安装路由配置: kubectl apply -f your_config_name.yml
配置例子如下:
apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: mysqlingress spec: rules: - http: paths: - path: /mysql # 访问路径 backend: serviceName: mysql-svc-ingress # svc的名称 servicePort: 3306 # app再svc上的端口 - path: /adminer backend: serviceName: mysql-svc-ingress servicePort: 8080
(4)生效一下配置: kubectl annotate ingress
mysqlingress kubernetes.io/ingress.class=ambassador
创建一个新的配置后,需要把配置名注册到kubernetes.io/ingress.class=ambassador
2.访问我们的app:主机ip:9980/adminer