0

I have built a process using a series of docker containers to spool up quick and easy flutter apps into a kubernetes cluster (so I can use the rest of the cluster to run background worker type processes). I have been able to get it deployed to my microk8s but I'm really having trouble getting it all working without running the command:

kubectl port-forward service/flutterapp 8080:8080

When I do that, it runs an interactive console that I can see in my terminal and then am able to access the service on localhost:8080. I'm trying to set it to use localhost:80 though, so I've attempted to use various different ingress preconfigs I've found (such as istio, ha-proxy, ingress) but I will admit I'm a bit of a noob when it comes to k8s and networking in general. This is what I've come up with thus far (I've used a dummy image from one of the tutorials I have been reading to try to wrap my head around this). This is my basic yml:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: flutterapp
  name: flutterapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: flutterapp
  template:
    metadata:
      labels:
        app: flutterapp
    spec:
      containers:
        - name: flutterapp
          image: gcr.io/kuar-demo/kuard-amd64:blue
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: http-flutterapp
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: flutterapp
spec:
  ports:
    - port: 8080
      protocol: TCP
      targetPort: http-flutterapp
  selector:
    app: flutterapp
  sessionAffinity: None
  type: LoadBalancer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: flutterapp
spec:
  rules:
  - http:
      paths:
      - path: /flutterapp
        pathType: Prefix
        backend:
          service:
            name: flutterapp
            port:
              number: 8080

I assume I'm doing something stupid and obviously wrong, but some of the articles I read for this stuff are using extensions/v1beta1 or other various apis and I'm struggling to keep them all strait.

Any suggestions?

Xanderu
  • 747
  • 1
  • 8
  • 30

1 Answers1

0

I was able to get this working using this and metallb in microk8s (using the host IP as the metallb range):

  apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: app
    name: app
  spec:
    replicas: 2
    selector:
      matchLabels:
        app: app
    template:
      metadata:
        labels:
          app: app
      spec:
        containers:
          - name: app
            image: docker.io/app:latest
            imagePullPolicy: Never
            ports:
              - containerPort: 4040
                name: http-app
                protocol: TCP
            resources:
              requests:
                cpu: 250m
                memory: 750Mi
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: app
  spec:
    ports:
      - port: 80
        protocol: TCP
        targetPort: 4040
    selector:
      app: app
    sessionAffinity: None
    type: LoadBalancer
  ---
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: app
  spec:
    ingressClassName: nginx
    rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: app
              port:
                number: 80
Xanderu
  • 747
  • 1
  • 8
  • 30