简体   繁体   English

Kubernetes-Minikube的入口

[英]Kubernetes - Ingress with Minikube

I am learning kubernetes by playing with minikube. 我通过玩minikube学习kubernetes。

This is my pod deployment file which is fine. 这是我的pod部署文件,很好。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: myapp
          image: myid/myimage

I am exposing the above pods using NodePort. 我正在使用NodePort公开上述容器。 I am able to access using minikube IP at port 30002. 我可以在端口30002上使用minikube IP进行访问。

apiVersion: v1
kind: Service
metadata:
  name: my-ip-service
spec:
  type: NodePort
  externalIPs:
  - 192.168.99.100
  selector:
    component: web
  ports:
    - port: 3000
      nodePort: 30002
      targetPort: 8080

Now i would like to use ingress to access the application at port 80 which will forward the request the ip-service at port 3000. It does NOT work 现在,我想使用入口在端口80上访问应用程序,它将在3000端口转发请求ip服务。它不起作用

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  backend:
    serviceName: my-ip-service
    servicePort: 3000

If i try to access to ingress, address is blank. 如果我尝试访问入口,则地址为空。

NAME           HOSTS   ADDRESS   PORTS   AGE
test-ingress   *                 80      41m

How to use ingress with minikube? 如何在minikube中使用ingress? Or how to bind the minikube ip with ingress service - so that the app can be exposed outside without using nodeport 或如何将minikube ip与入口服务绑定-这样应用程序可以暴露在外部而无需使用nodeport

You can get your minikube node's IP address with: 您可以使用以下命令获取minikube节点的IP地址:

minikube ip

The ingress' IP address will not populate in minikube because minikube lacks a load balancer. 入口的IP地址不会在minikube中填充,因为minikube没有负载均衡器。 If you'd like something that behaves like a load balancer for your minikube cluster, https://github.com/knative/serving/blob/master/docs/creating-a-kubernetes-cluster.md#loadbalancer-support-in-minikube suggests running the following commands to patch your cluster: 如果您想要的行为类似于您的minikube集群的负载均衡器,请https://github.com/knative/serving/blob/master/docs/creating-a-kubernetes-cluster.md#loadbalancer-support-in -minikube建议运行以下命令来修补集群:

sudo ip route add $(cat ~/.minikube/profiles/minikube/config.json | jq -r ".KubernetesConfig.ServiceCIDR") via $(minikube ip)
kubectl run minikube-lb-patch --replicas=1 --image=elsonrodriguez/minikube-lb-patch:0.1 --namespace=kube-system

I think you are missing the ingress controller resource on minikube itself. 我认为您在minikube本身上缺少入口控制器资源。 There are many possible ways to create an ingress-controller resource on K8s , but i think for you the best way to start on minikube is to follow this documentation. 在K8s上创建入口控制器资源的方法有很多种,但我认为对minikube最好的开始方法是遵循文档。

Don't forget to read about Ingress in general once you get this working. 一旦完成这项工作,就不要忘记阅读有关Ingress的一般文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM