Springboot service deployed in AKS not working with ingress - spring-boot

I have a simple Springboot service, which works well when I configure Service of type:LoadBalancer. But when I use service of type:ClusterIP and introduce ingress, it does not work
For that matter, I am unable to get Ingress working for any of my deployments in Azure/AKS.
Please suggest what am I missing
Spring code
#RestController
#RequestMapping("/demo")
public class MyController {
#GetMapping("/welcome")
public String welcome() {
return "Hello Welcome";
}
}
LoadBalancer - working code
spring-microservice-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-microservice
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: spring-microservice
template:
metadata:
labels:
app: spring-microservice
spec:
containers:
- name: spring-microservice
image: babaacr.azurecr.io/welcome-service:1.0
resources:
requests:
memory: '256Mi'
cpu: '500m'
limits:
memory: '512Mi'
cpu: '1'
ports:
- name: http
containerPort: 8080
spring-microservice-service.yaml
apiVersion: v1
kind: Service
metadata:
name: spring-microservice
namespace: default
labels:
app: spring-microservice
spec:
selector:
app: spring-microservice
type: LoadBalancer
ports:
- name: http
port: 8080
targetPort: 8080
protocol: TCP
when I access the url http://20.XXX.XX.XX:8080/demo/welcome
message is printed
ingress based which is not working
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-microservice-x
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: spring-microservice-x
template:
metadata:
labels:
app: spring-microservice-x
spec:
containers:
- name: spring-microservice-x
image: babaacr.azurecr.io/welcome-service:1.0
resources:
requests:
memory: '256Mi'
cpu: '500m'
limits:
memory: '512Mi'
cpu: '1'
ports:
- name: http
containerPort: 8080
apiVersion: v1
kind: Service
metadata:
name: spring-microservice-x
namespace: default
labels:
app: spring-microservice-x
spec:
selector:
app: spring-microservice-x
type: ClusterIP
ports:
- name: http
port: 8080
targetPort: 8080
protocol: TCP
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: spring-microservice-ingress
spec:
defaultBackend:
service:
name: spring-microservice-x
port:
number: 8080
when I access the url http://20.YYY.YY.YY:8080/demo/welcome
the page times-out
ingress controller is configured using below
helm install ingress-nginx ingress-nginx/ingress-nginx --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz

Related

linkerd services not showing up

I am running two docker images on my local minikube and this is my deployment file.
Somehow services for this yml file are not being shown in the viz dashboard.
How do I get them on viz dashboard of linkerd?
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mux
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: lux
---
apiVersion: v1
kind: Service
metadata:
name: lux
spec:
type: ClusterIP
selector:
app: lux
ports:
- name: http
port: 9000
targetPort: 8000
---
apiVersion: v1
kind: Service
metadata:
name: mux
spec:
type: ClusterIP
selector:
app: mux
ports:
- name: http
port: 9001
targetPort: 8001
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lux
labels:
app: lux
spec:
replicas: 1
selector:
matchLabels:
app: lux
template:
metadata:
labels:
app: lux
spec:
containers:
- name: lux
image: luxapp:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8000
serviceAccountName: lux
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mux
labels:
app: mux
spec:
replicas: 1
selector:
matchLabels:
app: mux
template:
metadata:
labels:
app: mux
spec:
containers:
- name: mux
image: muxapp:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8001
serviceAccountName: mux
---
I have only two components lux and mux and I want to deploy them on linkerd. When I inject them on linkerd only pods are created. service and service accounts are skipped.But on kubectl services are present.

Istio virtual service subset not able to send request to specific pods

I have following scenario
FastAPI (API Gateway)
Users (gRPC service)
below is the deployment yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: users
labels:
app: users
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: users
version: v1
template:
metadata:
labels:
app: users
version: v1
spec:
containers:
- image: users:v0.0.1
imagePullPolicy: Always
name: svc
ports:
- containerPort: 9090
---
kind: Service
apiVersion: v1
metadata:
name: users
labels:
app: users
spec:
selector:
app: users
ports:
- name: grpc
protocol: TCP
port: 9090
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi
labels:
app: fastapi
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: fastapi
version: v1
template:
metadata:
labels:
app: fastapi
version: v1
spec:
containers:
- image: fastapi:latest
imagePullPolicy: Always
name: web
ports:
- containerPort: 8080
env:
- name: USERS_SVC
value: 'users:9090'
---
kind: Service
apiVersion: v1
metadata:
name: fastapi
labels:
app: fastapi
spec:
selector:
app: fastapi
ports:
- port: 8080
name: http
After this I tried to test virtual service and route to users service (version: v2) when https header is passed. below is the codes for virtual service and destination rules
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: users-service-destination-rule
spec:
host: users
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: users-virtual-service
spec:
hosts:
- users
http:
- match:
- headers:
x-user-testing:
exact: tester
route:
- destination:
host: users
subset: v2
- route:
- destination:
host: users
subset: v1
Below is the deployment for user service (version v2)
apiVersion: apps/v1
kind: Deployment
metadata:
name: users-v2
labels:
app: users
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: users
version: v2
template:
metadata:
labels:
app: users
version: v2
spec:
containers:
- image: users:v0.0.1
imagePullPolicy: Always
name: svc
ports:
- containerPort: 9090
When i passed header value, the request always goes to version v1.
curl -H "x-user-testing: tester" localhost/users
Can anyone help me please.
Thanks in advance

(invalid_token_response) An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 401 Unauthorized: [no body]

I'm creating Microservices that are deployed in docker-desktop Kubernetes cluster for development. I'm using Spring security with Auth0 and the pods are using Kubernetes Native Service Discovery coupled with Spring cloud gateway. When I log in using Auth0, it authenticates just fine but the token that is received appears to be empty based on the error given.
I'm new to Kubernetes and this error only seems to occur when running the application on the kubernetes cluster. If I use Eureka for local testing, Auth0 works completely fine. I've tried to do some research to see if the issue is the token unable to be retrieved in the kubernetes cluster and the only solution I've seem to be able to find is to implement istioctl within the cluster.
FRONTEND deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-interface-app
labels:
app: user-interface-app
spec:
replicas: 1
selector:
matchLabels:
app: user-interface-app
template:
metadata:
labels:
app: user-interface-app
spec:
containers:
- name: user-interface-app
image: imageName:tag
imagePullPolicy: Always
ports:
- containerPort: 8084
env:
- name: GATEWAY_URL
value: api-gateway-svc.default.svc.cluster.local
- name: ZIPKIN_SERVER_URL
valueFrom:
configMapKeyRef:
name: gateway-cm
key: zipkin_service_url
- name: STRIPE_API_KEY
valueFrom:
secretKeyRef:
name: secret
key: stripe-api-key
- name: STRIPE_PUBLIC_KEY
valueFrom:
secretKeyRef:
name: secret
key: stripe-public-key
- name: STRIPE_WEBHOOK_SECRET
valueFrom:
secretKeyRef:
name: secret
key: stripe-webhook-secret
- name: AUTH_CLIENT_ID
valueFrom:
secretKeyRef:
name: secret
key: auth-client-id
- name: AUTH_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: secret
key: auth-client-secret
---
apiVersion: v1
kind: Service
metadata:
name: user-interface-svc
spec:
selector:
app: user-interface-app
type: ClusterIP
ports:
- port: 8084
targetPort: 8084
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: user-interface-lb
spec:
selector:
app: user-interface-app
type: LoadBalancer
ports:
- name: frontend
port: 8084
targetPort: 8084
protocol: TCP
- name: request
port: 80
targetPort: 8084
protocol: TCP
API-GATEWAY deployment.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: gateway-cm
data:
cart_service_url: http://cart-service-svc.default.svc.cluster.local
customer_profile_service_url: http://customer-profile-service-svc.default.svc.cluster.local
order_service_url: http://order-service-svc.default.svc.cluster.local
product_service_url: lb://product-service-svc.default.svc.cluster.local
zipkin_service_url: http://zipkin-svc.default.svc.cluster.local:9411
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-gateway-app
labels:
app: api-gateway-app
spec:
replicas: 1
selector:
matchLabels:
app: api-gateway-app
template:
metadata:
labels:
app: api-gateway-app
spec:
containers:
- name: api-gateway-app
image: imageName:imageTag
imagePullPolicy: Always
ports:
- containerPort: 8090
env:
- name: PRODUCT_SERVICE_URL
valueFrom:
configMapKeyRef:
name: gateway-cm
key: product_service_url
---
apiVersion: v1
kind: Service
metadata:
name: api-gateway-np
spec:
selector:
app: api-gateway-app
type: NodePort
ports:
- port: 80
targetPort: 8090
protocol: TCP
nodePort: 30499
---
apiVersion: v1
kind: Service
metadata:
name: api-gateway-svc
spec:
selector:
app: api-gateway-app
type: ClusterIP
ports:
- port: 80
targetPort: 8090
protocol: TCP

Configure spring cloud config uri in a kubernetes cluster

I'm deploying my config server and application which uses it to initalize properties.
The following problem I encounter now is the URI to specify where the config-server is located.
Before it was easy like this:
spring.config.import=optional:configserver:https://localhost:8888/
Now in the cluster I try to specify it like this
spring.config.import=optional:configserver:centralconfig-service:8888/
This the service name of the config-server (deployment name is 'centralconfig').
Whenever I try this URL i get an Invalid Url exception.
Invalid URL: centralconfig-service:8888/
I've set up an internal network so they should be able to communicate with eachother.
Anyone knows how to specify the correct URI in the kubernetes-environment?
centralconfig-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: central-config
labels:
app: central-config
spec:
replicas: 1
selector:
matchLabels:
app: central-config
strategy: {}
template:
metadata:
labels:
app: central-config
spec:
containers:
- name: central-config
image: "central-config:latest"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8888
resources: {}
restartPolicy: Always
serviceAccountName: ""
volumes: null
status: {}
centralconfig.service.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: central-config
labels:
app: central-config
spec:
replicas: 1
selector:
matchLabels:
app: central-config
strategy: {}
template:
metadata:
labels:
app: central-config
spec:
containers:
- name: central-config
image: "central-config:latest"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8888
resources: {}
restartPolicy: Always
serviceAccountName: ""
volumes: null
status: {}
endpoints:
Thanks in advance
I suspect that missing the "http://" or "https://" prefix is the actual cause of the problem.
So give this one a try:
spring.config.import=optional:configserver:https://centralconfig-service:8888/

Istio - GKE - gRPC config stream closed; upstream connect error or disconnect/reset before headers. reset reason: connection failure

I am trying to my spring boot micro service in GKE Cluster with istio 1.1.5 latest version as of now. It throws error and pod never spins up. If I run it as a separate service in Kubernetes engine it works perfectly but with isito, it does not work. The purpose for using istio is to host multiple microservices and to use the feature istio provides. Here is my yaml file:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: revenue
spec:
replicas: 1
template:
metadata:
labels:
app: revenue-serv
tier: backend
track: stable
spec:
containers:
- name: backend
image: "gcr.io/finacials/revenue-serv:latest"
imagePullPolicy: Always
ports:
- containerPort: 8081
livenessProbe:
httpGet:
path: /
port: 8081
initialDelaySeconds: 15
timeoutSeconds: 30
readinessProbe:
httpGet:
path: /
port: 8081
initialDelaySeconds: 15
timeoutSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: revenue-serv
spec:
ports:
- port: 8081
#targetPort: 8081
#protocol: TCP
name: http
selector:
app: revenue-serv
tier: backend
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gateway
annotations:
kubernetes.io/ingress.class: "istio"
spec:
rules:
- http:
paths:
- path: /revenue/.*
backend:
serviceName: revenue-serv
servicePort: 8081
Thanks for your valuable feedback.
I have found the issue. I removed readynessProbe and livenessProbe and created ingressgateway and virtual service. It worked.
deployment & service:
#########################################################################################
# This is for deployment - Service & Deployment in Kubernetes ################
# Author: Arindam Banerjee ################
#########################################################################################
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: revenue-serv
namespace: dev
spec:
replicas: 1
template:
metadata:
labels:
app: revenue-serv
version: v1
spec:
containers:
- name: revenue-serv
image: "eu.gcr.io/rcup-mza-dev/revenue-serv:latest"
imagePullPolicy: Always
ports:
- containerPort: 8081
---
apiVersion: v1
kind: Service
metadata:
name: revenue-serv
namespace: dev
spec:
ports:
- port: 8081
name: http
selector:
app: revenue-serv
gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: worldcup-serv-gateway
namespace: dev
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
virtual-service.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: revenue-serv-virtualservice
namespace: dev
spec:
hosts:
- "*"
gateways:
- revenue-serv-gateway
http:
- route:
- destination:
host: revenue-serv

Resources