PacktPublishing / Microservices-with-Spring-Boot-and-Spring-Cloud-2E

Microservices-with-Spring-Boot-and-Spring-Cloud-2E, Published by Packt
MIT License
237 stars 260 forks source link

Chapter 17. Implementing Kubernetes Features to Simplify the System Landscape | APPLICATION FAILED TO START | Config data resource 'file [/config-repo/product.yml]' via location 'file:/config-repo/product.yml' does not exist #14

Closed webmakaka closed 2 years ago

webmakaka commented 2 years ago

Hello!

I am trying to create deployment for production and receiving an error:


$ kubectl logs product-7bb8dd5dbb-tnldm


***************************
APPLICATION FAILED TO START
***************************

Description:

Config data resource 'file [/config-repo/product.yml]' via location 'file:/config-repo/product.yml' does not exist

Action:

Check that the value 'file:/config-repo/product.yml' is correct, or prefix it with 'optional:'


I see that container just has no file. Did I miss some step?

Do not want to manually update book sources.

===========================================


My Steps


$ unset KUBECONFIG


$ minikube start \
--profile=handson-spring-boot-cloud \
--memory=10240 \
--cpus=4 \
--disk-size=30g \
--kubernetes-version=v1.20.5 \
--driver=docker \
--ports=8080:80 --ports=8443:443 \
--ports=30080:30080 --ports=30443:30443


$ {
  minikube profile handson-spring-boot-cloud
  minikube addons enable ingress
  minikube addons enable metrics-server
}


$ eval $(minikube docker-env)
$ { 
  docker pull mysql:5.7.32
  docker pull mongo:4.4.2
  docker pull rabbitmq:3.8.11-management
  docker pull openzipkin/zipkin:2.23.2
}


Install the cert-manager


$ helm repo add jetstack https://charts.jetstack.io

$ helm repo update

$ helm install cert-manager jetstack/cert-manager \
--create-namespace \
--namespace cert-manager \
--version v1.3.1 \
--set installCRDs=true \
--wait


$ kubectl get pods --namespace cert-manager


NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-7998c69865-v6jrx              1/1     Running   0          43s
cert-manager-cainjector-7b744d56fb-ptqt5   1/1     Running   0          43s
cert-manager-webhook-7d6d4c78bc-6cztp      1/1     Running   0          43s


// Map minikube.me to the IP address we can use to reach the Minikube instance
$ sudo bash -c "echo $(minikube ip) minikube.me | tee -a /etc/hosts"


$ ./gradlew build && docker-compose build


// Resolving Helm chart dependencies
$ for f in kubernetes/helm/components/*; do helm dep up $f; done
$ for f in kubernetes/helm/environments/*; do helm dep up $f; done
$ helm dep ls kubernetes/helm/environments/prod-env/


NAME                VERSION REPOSITORY                                  STATUS
common              1.0.0   file://../../common                         ok    
auth-server         1.0.0   file://../../components/auth-server         ok    
product             1.0.0   file://../../components/product             ok    
recommendation      1.0.0   file://../../components/recommendation      ok    
review              1.0.0   file://../../components/review              ok    
product-composite   1.0.0   file://../../components/product-composite   ok    
zipkin-server       1.0.0   file://../../components/zipkin-server       ok


$ kubectl config set-context $(kubectl config current-context) --namespace=hands-on


$ docker-compose up -d mongodb mysql rabbitmq


$ {
  docker tag hands-on/auth-server hands-on/auth-server:v1
  docker tag hands-on/product-composite-service hands-on/product-composite-service:v1
  docker tag hands-on/product-service hands-on/product-service:v1
  docker tag hands-on/recommendation-service hands-on/recommendation-service:v1
  docker tag hands-on/review-service hands-on/review-service:v1
}


$ helm install hands-on-prod-env \
kubernetes/helm/environments/prod-env \
-n hands-on --create-namespace \
--wait


$ kubectl get pods
NAME                                 READY   STATUS             RESTARTS   AGE
auth-server-6b7cf86b66-thnsl         0/1     CrashLoopBackOff   8          20m
product-7bb8dd5dbb-tnldm             0/1     CrashLoopBackOff   8          20m
product-composite-85fc98c8bf-s5j5v   0/1     CrashLoopBackOff   8          20m
recommendation-7c9bbd76f8-qbjcx      0/1     CrashLoopBackOff   8          20m
review-7b48469995-5jbqc              0/1     CrashLoopBackOff   8          20m
zipkin-server-6b9b4d988f-g78hq       1/1     Running            0          20m

=================


Environment

$ cat /etc/os-release | grep 'VERSION='
VERSION="20.04.4 LTS (Focal Fossa)"


$ java -version
java version "17.0.2" 2022-01-18 LTS


$ docker -v
Docker version 20.10.15, build fd82621

I updated gradle to work with JDK17

magnus-larsson commented 2 years ago

Hello and thanks for reporting this problem!

My first guess is that you have run into some problems with the symbolic links that makes the config-repo available in the components' Helm charts. For Chapter 17, this is explained on page 503, with a reference to the explanation in Chapter 16 on page 475.

For the product microservice, see:

Can you run the following command to see if this might be the problem?

ls -l $BOOK_HOME/Chapter17/kubernetes/helm/components/product/config-repo

It should respons with something similar to:

... application.yml -> ../../../../../config-repo/application.yml
... product.yml -> ../../../../../config-repo/product.yml

Regards, Magnus.

webmakaka commented 2 years ago

Hi, @magnus-larsson!

Your answer helped me to solve my issue!

Thanks!

==========================

My solution!

Previously, I download sources as zip. Symbolic links are lost.

To solve the issue.

I made "config-repo" for each microservice.

then


// auth-server

$ cd kubernetes/helm/components/auth-server/config-repo/


$ {
  ln -s ../../../../../config-repo/application.yml  application.yml
  ln -s ../../../../../config-repo/auth-server.yml auth-server.yml
}


// product-composite

$ cd kubernetes/helm/components/product-composite/config-repo/


$ {
  ln -s ../../../../../config-repo/application.yml  application.yml
  ln -s ../../../../../config-repo/product-composite.yml product-composite.yml
}


// product

$ cd kubernetes/helm/components/product/config-repo/


$ {
  ln -s ../../../../../config-repo/application.yml  application.yml
  ln -s ../../../../../config-repo/product.yml product.yml
}


// recommendation

$ cd kubernetes/helm/components/recommendation/config-repo/


$ {
  ln -s ../../../../../config-repo/application.yml  application.yml
  ln -s ../../../../../config-repo/recommendation.yml recommendation.yml
}


// review

$ cd kubernetes/helm/components/review/config-repo/


$ {
  ln -s ../../../../../config-repo/application.yml  application.yml
  ln -s ../../../../../config-repo/review.yml review.yml
}


and the result is


$ kubectl get pods
NAME                                 READY   STATUS    RESTARTS   AGE
auth-server-6b7cf86b66-f896w         1/1     Running   0          74s
product-7bb8dd5dbb-2ctsn             1/1     Running   0          74s
product-composite-85fc98c8bf-qjghd   1/1     Running   1          74s
recommendation-7c9bbd76f8-xrgsx      1/1     Running   0          74s
review-7b48469995-zq6fv              1/1     Running   0          74s
zipkin-server-6b9b4d988f-g9tzg       1/1     Running   0          74s


$ HOST=minikube.me PORT=443 USE_K8S=true ./test-em-all.bash
Start Tests: Mon 13 Jun 2022 07:35:19 PM MSK
HOST=minikube.me
PORT=443
USE_K8S=true
SKIP_CB_TESTS=false
Wait for: curl -k https://minikube.me:443/actuator/health... DONE, continues...
ACCESS_TOKEN=eyJraWQiOiI5NzY5NmRmMi1jYmEwLTQ5YWEtOTY4OS05ZWE3ZDM4YzQ0MjUiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ3cml0ZXIiLCJhdWQiOiJ3cml0ZXIiLCJuYmYiOjE2NTUxMzgxMTksInNjb3BlIjpbInByb2R1Y3Q6d3JpdGUiLCJvcGVuaWQiLCJwcm9kdWN0OnJlYWQiXSwiaXNzIjoiaHR0cDpcL1wvYXV0aC1zZXJ2ZXIiLCJleHAiOjE2NTUxNDE3MTksImlhdCI6MTY1NTEzODExOSwianRpIjoiNjViMTk4MzEtMmEzOS00MzAzLTg3NWMtYmJhNmJkZTJhOWQzIn0.1XRhG0YpBYLSZU_6KPXxyWQ7ATcnSrIrmhV3HoqybsvSLy_dGCbIDl2L9y3iutuFX9m1BLSaYtnLmpi0x3WKrY0KVtPhfSVIuUSk3rEkyQiS3jOJ17wv_CKDVtDhlGya9e4ALeae-o4rF6L_4Fw-UBQuEHi-EUOEH8KbQvb7VknqNMHhc2QPn-0mYnclcxwV0e49nLpidXuqOhfEsBTinhHygUs_s-gJJRWoxwLBfu-wNSSbYe9ayLAfTSzd5UCdSdC9HUlL9zxyXV3oz7wFh0JFP6K6XcOYdFsRSolbo-50kqwTxWBDzx0GjYpOSzDP1VvtmlHIX8Ie5cuzIsLiMQ
Test OK (HTTP Code: 202, )
Test OK (actual value: 202)
Test OK (HTTP Code: 202, )
Test OK (actual value: 202)
Test OK (HTTP Code: 202, )
Test OK (actual value: 202)
Wait for messages to be processed... 
Test OK (HTTP Code: 200)
Test OK (actual value: 1)
Test OK (actual value: 3)
Test OK (actual value: 3)
All messages are now processed!
Test OK (HTTP Code: 200)
Test OK (actual value: 1)
Test OK (actual value: 3)
Test OK (actual value: 3)
Test OK (HTTP Code: 404, {"timestamp":"2022-06-13T16:35:23.190627979Z","path":"/product-composite/13","message":"No product found for productId: 13","status":404,"error":"Not Found"})
Test OK (actual value: No product found for productId: 13)
Test OK (HTTP Code: 200)
Test OK (actual value: 113)
Test OK (actual value: 0)
Test OK (actual value: 3)
Test OK (HTTP Code: 200)
Test OK (actual value: 213)
Test OK (actual value: 3)
Test OK (actual value: 0)
Test OK (HTTP Code: 422, {"timestamp":"2022-06-13T16:35:23.640115193Z","path":"/product-composite/-1","message":"Invalid productId: -1","status":422,"error":"Unprocessable Entity"})
Test OK (actual value: "Invalid productId: -1")
Test OK (HTTP Code: 400, {"timestamp":"2022-06-13T16:35:23.713+00:00","path":"/product-composite/invalidProductId","status":400,"error":"Bad Request","message":"Type mismatch.","requestId":"55307164-3"})
Test OK (actual value: "Type mismatch.")
Test OK (HTTP Code: 401, )
READER_ACCESS_TOKEN=eyJraWQiOiI5NzY5NmRmMi1jYmEwLTQ5YWEtOTY4OS05ZWE3ZDM4YzQ0MjUiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJyZWFkZXIiLCJhdWQiOiJyZWFkZXIiLCJuYmYiOjE2NTUxMzgxMjMsInNjb3BlIjpbIm9wZW5pZCIsInByb2R1Y3Q6cmVhZCJdLCJpc3MiOiJodHRwOlwvXC9hdXRoLXNlcnZlciIsImV4cCI6MTY1NTE0MTcyMywiaWF0IjoxNjU1MTM4MTIzLCJqdGkiOiI3OTAyY2NjMC1iYTZiLTQzNjItOTE4ZS0zMTkwZGE4ODAxZWIifQ.KP6Gv8KofI-0N3wXflaidSV2ckZBVQhEuz8WX8aPZ_5YUXRwwp5n-8Zu1aRutrDUpUjgN1z-TohLBbYcDTac8buQBl25aMw5ZlZnXTEnQjWVC56FC-dWOLXE6mG7yUGtRk9kZI-OQAcQSudoqEHV7GmFWN6W5OkEn8G4VzlBzQqc4HJwHWOuP6aaIVs6C2TqGiclsOFysHTdqOr3LGOnp7bCN6LvEriuSZIV20COem-GjnVycHHfYBEIJ2EPkC4pVXwoWT1N0I2G7KUYYV4e_v46PJoMCceOnvdfXr1Yw2UYdDUyu0kiYToQ4MsG10rRivnxdk4PFo4TNuFX_kz49w
Test OK (HTTP Code: 200)
Test OK (HTTP Code: 403, )
Swagger/OpenAPI tests
Test OK (HTTP Code: 302, )
Test OK (HTTP Code: 200)
Test OK (HTTP Code: 200)
Test OK (HTTP Code: 200)
Test OK (actual value: 3.0.1)
Test OK (HTTP Code: 200)
Start Circuit Breaker tests!
Test OK (actual value: CLOSED)
Test OK (HTTP Code: 500, {"timestamp":"2022-06-13T16:35:26.936+00:00","path":"/product-composite/1","status":500,"error":"Internal Server Error","message":"Did not observe any item or terminal signal within 2000ms in 'onErrorResume' (and no fallback has been configured)","requestId":"b701ee1e-6"})
Test OK (actual value: Did not observe any item or terminal signal within 2000ms)
Test OK (HTTP Code: 500, {"timestamp":"2022-06-13T16:35:29.008+00:00","path":"/product-composite/1","status":500,"error":"Internal Server Error","message":"Did not observe any item or terminal signal within 2000ms in 'onErrorResume' (and no fallback has been configured)","requestId":"445c4b92-6"})
Test OK (actual value: Did not observe any item or terminal signal within 2000ms)
Test OK (HTTP Code: 500, {"timestamp":"2022-06-13T16:35:31.091+00:00","path":"/product-composite/1","status":500,"error":"Internal Server Error","message":"Did not observe any item or terminal signal within 2000ms in 'onErrorResume' (and no fallback has been configured)","requestId":"9ae530f7-8"})
Test OK (actual value: Did not observe any item or terminal signal within 2000ms)
Test OK (actual value: OPEN)
Test OK (HTTP Code: 200)
Test OK (actual value: Fallback product1)
Test OK (HTTP Code: 200)
Test OK (actual value: Fallback product1)
Test OK (HTTP Code: 404, {"timestamp":"2022-06-13T16:35:31.58276681Z","path":"/product-composite/13","message":"Product Id: 13 not found in fallback cache!","status":404,"error":"Not Found"})
Test OK (actual value: Product Id: 13 not found in fallback cache!)
Will sleep for 10 sec waiting for the CB to go Half Open...
Test OK (actual value: HALF_OPEN)
Test OK (HTTP Code: 200)
Test OK (actual value: product name C)
Test OK (HTTP Code: 200)
Test OK (actual value: product name C)
Test OK (HTTP Code: 200)
Test OK (actual value: product name C)
Test OK (actual value: CLOSED)
Test OK (actual value: CLOSED_TO_OPEN)
Test OK (actual value: OPEN_TO_HALF_OPEN)
Test OK (actual value: HALF_OPEN_TO_CLOSED)
End, all tests OK: Mon 13 Jun 2022 07:35:42 PM MSK


Thanks again!