Skip to content

sample for setup kubernetes cluster ,deploy spring cloud and debug via telepresence

Notifications You must be signed in to change notification settings

shawnliujw/spring-boot-kubernetes

Repository files navigation

Quick sample for building microservice with Spring Boot + Kubernetes and debug remotely

This project will show you how to setup kubernetes cluster by kubeadm , deploy spring boot micro service, and how to debug your code

Setup Kubernetes Cluster

See Setup Kubernetes By Kubeadm

Preparation

  • create cluster role
    kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default
  • Init mongodb
    kubectl apply -f kubernetes/mongodb

How To Deploy

  • build projects mvn clean install
  • build docker images
    bash build.sh
  • push docker images
    bash push.sh Please skip this step if you run locally
  • deploy to cluster
    kubectl apply -f kubernetes/projects
  • deploy ingress
    kubectl apply -f kubernetes/ingress.yaml
  • configure host
    run kubectl cluster-info to get cluster_ip
    add host to /etc/hosts with: <cluster_ip> micro.info

How To Test

  • Init Data:
    curl -d '{"id":1,"id":1,"name":"company name","address":"company address"}' -H 'Content-Type:application/json' shawn.info/organization/

    curl -d '{"organizationId":1,"id":1,"name":"department name"}' -H 'Content-Type:application/json' shawn.info/department/

    curl -d '{"organizationId":1,"departmentId":1,"id":1,"name":"employee"}' -H 'Content-Type:application/json' shawn.info/employee/ .

  • check result:

    curl micro.info/employee/1 .

    curl micro.info/department/1 .

    curl micro.info/department/organization/1/with-employees

How To Debug With Telepresence

Install Telepresence

OS X

brew cask install osxfuse
brew install datawire/blackbird/telepresence

Ubuntu 16.04 or later

curl -s https://packagecloud.io/install/repositories/datawireio/telepresence/script.deb.sh | sudo bash
sudo apt install --no-install-recommends telepresence

for other OS, See More

Configure

  • generate env.json
    telepresence --swap-deployment <service in k8s> --env-json service.env.json
  • load env in IDEA
    you will need to install the Env File plugin. load the service.env.json generated above
  • debug your code as usual
    Refer To: Using Telepresence with IntelliJ

Serverless(Kubeless)

Click Here to check the samples

Monitor(Prometheus,Grafana,Alert)

Click Here