GithubHelp home page GithubHelp logo

berton1982 / istio-spring-boot-minikube Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hiteshjoshi1/istio-spring-boot-minikube

0.0 0.0 0.0 11 KB

istio kubernetes docker microservices example

Dockerfile 5.63% Java 94.37%

istio-spring-boot-minikube's Introduction

Spring Boot Microservice example with Istio

This uses Spring webflux but in concepts are same for any REST based on Spring boot.

Based on - https://developer.okta.com/blog/2019/04/01/spring-boot-microservices-with-kubernetes https://github.com/oktadeveloper/okta-spring-boot-microservice-kubernetes

While the blog shows how to deploy in GCE, this implementation is generic and can be used to deploy in any cluster.

My change -

I had to make a few fixes to the charts and I use istio auto injection. I am not sure if google auto enables istio injection. The blog does not show/talk about envoy proxy injection which is the key feature of istio-service mesh. We will use minikube.

TODO- Deploy in AWS.

Enable Istio into your cluster

istioctl manifest apply --set profile=demo

Enable namespace injection

kubectl label namespace default istio-injection=enabled

Install Mongo- by Add mongo manifest

kubectl apply -f deployment-mongo.yml

Edit the application config to point to docker mongo, let your Spring app know where is the datasource

server.port=8000
spring.data.mongodb.host=mongodb
spring.data.mongodb.port=27017

Build

gradle clean build

Once build is complete, Build docker image

docker build -t demo-app:1.0 .

Step 1, 2 ,3 not required if you are just using my image from dockerhub.

  1. Push docker image to repo
docker login
  1. Tag image first(mandatory) -
docker tag demo-app:1.0 hiteshjoshi1/demo-app:1.0
  1. Then push -
docker push hiteshjoshi1/demo-app:1.0

Note - if you are making changes and getting older images, check kuberntes image pull policy in deployment.yml

Deploy using istio - Will deploy a envoy sidecar and the pod

kubectl apply -f <(istioctl kube-inject -f deployment.yml)

Get cluster IP from minikube

export INGRESS_HOST= $(minikube ip)

Any other platform, use

export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}');

Get Ingress IP

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

Then you can access your microservices

curl http://$INGRESS_HOST:$INGRESS_PORT/kayaks

Secured Micro Service with Okta

For non secured MS(starting point) see the branch

Build the App again with Spring security authentication with Okta

docker build -t demo-app-auth:1.0 .

Tag it

docker tag demo-app-auth:1.0 hiteshjoshi1/demo-app-auth:1.0

Push it again

docker push hiteshjoshi1/demo-app-auth:1.0

Change the image name in deployment.yml. Stop any running deployment

kubectl delete deployment <dep_name>

Then run again-

kubectl apply -f <(istioctl kube-inject -f deployment.yml)

Now get the port again

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

Try health check it works as it not blocked by Spring security

curl http://$INGRESS_HOST:$INGRESS_PORT/

Try microservice, should be blocked.

curl http://$INGRESS_HOST:$INGRESS_PORT/kayaks

Get Auth token from OAuth using (Follow main blog if needed**)

http://oidcdebugger.com/

Then make request again with Auth header

curl -H "Authorization: Bearer ${TOKEN}" http://$INGRESS_HOST:$INGRESS_PORT/kayaks

istio-spring-boot-minikube's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.