Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

Kubernetes - Ingress on docker driver - minikube 1.16

I'm trying to setup ingress on docker driver for minikube 1.16 on windows 10 home (build 19042). Ingress on docker driver wasn't supported before but it is now on minikube 1.16: https://github.com/kubernetes/minikube/pull/9761

I've been trying something by myself but i got ERR_CONNECTION_REFUSED when connecting to the ingress at 127.0.0.1 OR kubernetes.docker.internal

Steps:

  1. minikube start
  2. minikube addons enable ingress
  3. create deployment
  4. create ClusterIP
  5. Ingress config

Here is my configuration:

#cluster ip service
apiVersion: v1
kind: Service
metadata:
  name: client-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: web
  ports:
  - port: 3000
    targetPort: 3000

# not posting deployment code because it's not relevant, but there is a deployment with selector 'component:web' and it's exposing port 3000.


#ingress service
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: kubernetes.docker.internal
      http:
        paths:
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: client-cluster-ip-service
                port:
                  number: 3000

I have dns redirect in hosts file.

I've also tried "minikube tunnel" on another terminal but no luck either.

Thanks!

question from:https://stackoverflow.com/questions/65842876/kubernetes-ingress-on-docker-driver-minikube-1-16

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a mistake in your ingress object definition under rules field:

  rules:
    - host: kubernetes.docker.internal
    - http:
        paths:

The exact problem is the - sing in front the http which makes the host and http separate arrays.

Take a look how your converter yaml looks like in json:

{
  "spec": {
    "rules": [
      {
        "host": "kubernetes.docker.internal"
      },
      {
        "http": {
          "paths": [
            {
              "path": "/?(.*)",
              "pathType": "Prefix",
              "backend": {
---

This is how annotations looks like with your ingress definition.

spec:
  rules:
    - host: kubernetes.docker.internal
      http:
        paths:
          - path: /?(.*)
            pathType: Prefix

And now notice how this yaml converted to json looks like:

{
  "spec": {
    "rules": [
      {
        "host": "kubernetes.docker.internal",
        "http": {
          "paths": [
            {
              "path": "/?(.*)",
              "pathType": "Prefix",
              "backend": {
---

You can easily visualize this even better using yaml-viewer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...