DickChesterwood / k8s-fleetman

MIT License
342 stars 816 forks source link

Api Gateway Keeps on Restarting #48

Closed harsh242002 closed 1 year ago

harsh242002 commented 1 year ago

Api Gateway Key on Restarting when ever try to connect to api gateway using 30020 how to fix this

DickChesterwood commented 1 year ago

Hi sorry can you clarify what's happening here? Not sure what you mean by key? Do you mean "keeps on restarting"?

Let me know your k8s environment (minikube? desktop?) and output from "kubectl get all".

harsh242002 commented 1 year ago

bro it got fix when I removed the resource limit from container spec. but I want my container should have limit and it shouldn't exceed specified limit can you help me with it

DickChesterwood commented 1 year ago

Can you post up the yaml? I'm interested mainly in what the limit you set was? It's a tiny spring boot app but there's a good chance I didn't tune it very well on this version of the course so it's possibly using a lot of RAM when it doesn't need it.

In fact, I think that's the reason.

When I rebuilt the system for the follow on Istio course, I was more careful and limited the heap size - check out the dockerfile here:

https://github.com/DickChesterwood/istio-fleetman/blob/6/istio-fleetman-api-gateway/src/main/docker/Dockerfile

Line 11 is the key line, limiting the heap to 50Mb.

If you are able to rebuild the API gateway image using a similar Dockerfile then you should fine the container limit works better.

(IIRC this isn't needed in later java versions (9+) as Java knows it is running in a container. I'd suggesting changing the base image to use a more recent Java, but that will cause all kinds of compilation errors, so maybe not a good idea).

harsh242002 commented 1 year ago
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-gateway
spec:
  selector:
    matchLabels:
      app: api-gateway
  replicas: 1
  template: 
    metadata:
      labels:
        app: api-gateway
    spec:
      containers:
      - name: api-gateway
        image: richardchesterwood/k8s-fleetman-api-gateway:release2
        resources:  
        limits:  
          memory: "512Mi"  
          cpu: "500m"
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: production-microservice  

this was the yaml defination when it api gateway crashing. After the removal of resource every it good and running ok

harsh242002 commented 1 year ago

this was fix by removing resource from api gateway yaml defination

resources:  
        limits:  
          memory: "512Mi"  
          cpu: "500m"

this was not their in original video yaml defination it was added by me after reading the k8s doc