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
Related
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.
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
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
I deployed Istion on my local Kubernetes cluster running in my Mac. I created this VirtualService, DestinationRule and Gateway.
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: code-gateway
namespace: code
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "gateway.code"
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: codemaster
namespace: code
spec:
hosts:
- master.code
- codemaster
gateways:
- codemaster-gateway
- code-gateway
http:
- route:
- destination:
host: codemaster
subset: v1
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: codemaster-gateway
namespace: code
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "master.code"
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: codemaster
namespace: code
spec:
host: codemaster
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
- apiVersion: "v1"
kind: "Service"
metadata:
labels:
app: "codemaster"
group: "code"
name: "codemaster"
namespace: "code"
spec:
ports:
- name: http-web
port: 80
targetPort: 80
selector:
app: "codemaster"
group: "code"
type: "ClusterIP"
- apiVersion: "apps/v1"
kind: "Deployment"
metadata:
labels:
app: "codemaster"
group: "code"
env: "production"
name: "codemaster"
namespace: "code"
spec:
replicas: 2
selector:
matchLabels:
app: "codemaster"
group: "code"
template:
metadata:
labels:
app: "codemaster"
version: "v1"
group: "code"
env: "production"
spec:
containers:
- env:
- name: "KUBERNETES_NAMESPACE"
valueFrom:
fieldRef:
fieldPath: "metadata.namespace"
- name: "SPRING_DATASOURCE_URL"
value: "jdbc:postgresql://host.docker.internal:5432/code_master"
- name: "SPRING_DATASOURCE_USERNAME"
value: "postgres"
- name: "SPRING_DATASOURCE_PASSWORD"
value: "postgres"
image: "kzone/code/codemaster:1.0.0"
imagePullPolicy: "IfNotPresent"
name: "codemaster"
ports:
- containerPort: 80
name: "http"
protocol: "TCP"
apiVersion: "v1"
kind: "List"
items:
- apiVersion: "apps/v1"
kind: "Deployment"
metadata:
labels:
app: "codemaster"
group: "code"
env: "canary"
name: "codemaster-canary"
namespace: "code"
spec:
replicas: 1
selector:
matchLabels:
app: "codemaster"
group: "code"
template:
metadata:
labels:
app: "codemaster"
version: "v2"
group: "code"
env: "canary"
spec:
containers:
- env:
- name: "KUBERNETES_NAMESPACE"
valueFrom:
fieldRef:
fieldPath: "metadata.namespace"
- name: "SPRING_DATASOURCE_URL"
value: "jdbc:postgresql://host.docker.internal:5432/code_master"
- name: "SPRING_DATASOURCE_USERNAME"
value: "postgres"
- name: "SPRING_DATASOURCE_PASSWORD"
value: "postgres"
image: "kzone/code/codemaster:1.0.1"
imagePullPolicy: "IfNotPresent"
name: "codemaster"
ports:
- containerPort: 80
name: "http"
protocol: "TCP"
These are the services running in code namespace,
codemaster ClusterIP 10.103.151.80 <none> 80/TCP 18h
gateway ClusterIP 10.104.154.57 <none> 80/TCP 18h
I deployed 2 spring-boot microservices in ton k8s. One is a spring-boot gateway.
These are the pods running in code namespace,
codemaster-6cb7b8ddf5-mlpzn 2/2 Running 0 7h3m
codemaster-6cb7b8ddf5-sgzt8 2/2 Running 0 7h3m
codemaster-canary-756697d9c8-22qb2 2/2 Running 0 7h3m
gateway-5b5c8697f4-jpb4q 2/2 Running 0 7h3m
When I send a request to http://master.code/version(the gateway created for codemaster service) it always goes to the correct subset.
But when I send a request via spring-boot gateway (http://gateway.code/codemaster/version) request doesn't go to subset v1 only, requests go in round-robin to all the 3 pods. This is what I see in Kiali,
I want to apply traffic shifting between the gateway and other services.
Istio relies on the Host header of a request to apply the traffic rules. Since you are using spring boot gateway to make the request ribbon hits the pod IP directly instead of hitting the service. So to avoid it provide static server list to the
route /version as http://master.code.cluster.local
in your spring boot gateway config -> to avoid ribbon dynamic endpoint discovery. This should fix the problem.
After doing some search I found that there is no CNI in Docker for Mac k8s. Because of that traffic shifting doesn't not work on Docker for Mac K8s
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