Giter VIP home page Giter VIP logo

spring-cloud-kubernetes-example's Introduction

spring-cloud-kubernetes-example

The Examples for Spring-Cloud-Kubernetes in https://github.com/seongpyoHong/spring-cloud-kubernetes.

Index

1. kubernetes-hello-world-example

Spring Cloud Kubernetes를 통해 스프링 부트 어플리케이션을 쿠버네티스 위에 배포하고, DiscoveryClient를 통해 쿠버네티스에 등록된 서비스를 조회

Result

> curl <External-Ip>:<NodePort>
Hello World!

> curl <External-Ip>:<NodePort>/services
Avaliable list of services

2. kubernetes-circuitbreaker-ribbon-example

  • Netflix Ribbon을 통해 Client-Side Loadbalancing 제공
  • Netfilx Hystrix를 통해 Circuit Breaker Pattern 제공

Execution

  • Build docker image & Push to GCR
./gradlew jib
  • Create k8s resources
kubectl apply -f resources/

result

  • Pods
NAME                              READY   STATUS    RESTARTS   AGE
greeting-service-78b54b56-9495b   1/1     Running   0          6m25s
name-service-1-6f84bbd478-6v69z   1/1     Running   0          3m54s
name-service-1-6f84bbd478-wdzz9   1/1     Running   0          20m
name-service-2-df9b9bf59-wkvvw    1/1     Running   0          20m
  • Get list of service
❯ curl http://34.64.104.57:30411/services
    [greeting-service, kubernetes, name-service-1, name-service-2]
  • Verify loadbalance by calling name-service-1 (replicas=2)
❯ curl http://<External-Ip>:<NodePort>/greeting1
    Hello from name-service-1-6f84bbd478-6v69z! 
❯ curl http://<External-Ip>:<NodePort>/greeting1
    Hello from name-service-1-6f84bbd478-wdzz9!
  • Call name-service-2 (replicas=1)
❯ curl http://<External-Ip>:<NodePort>/greeting2
    Hello from name-service-2-df9b9bf59-wkvvw!
  • Test Circuit Breaker by calling name-service-2(replicas=0)
    • Timeout : 1000 ms
❯ kubectl scale --replicas=0 deployment name-service-2
    deployment.extensions/name-service-2 scaled

❯ curl http://<External-Ip>:<NodePort>/greeting2
    Hello from fallback!

3. kubernetes-reload-example

  • ConfigMap / Secret 변경에 따른 auto-reload 제공

Execution

  • Build docker image & Push to GCR
./gradlew jib
  • Create k8s resources
kubectl apply -f resources/
  • Change ConfigMap
kubectl apply -f src/configMap.yml

Result

Before Changing the ConfigMap

  • ConfigMap

      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: reload-example
      data:
        application.properties: |-
          bean.message=Hello World!
          another.property=value
    
  • Output

      2020-03-11 13:51:21.844  INFO 1 --- [main] c.s.e.KubernetesReloadExampleApplication : Started KubernetesReloadExampleApplication in 8.698 seconds (JVM running for 9.357)
      The first message is: Hello World!
      The other message is: Dummy Message
    

After Changing the ConfigMap

  • ConfigMap

      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: reload-example
      data:
        application.properties: |-
          bean.message=Changed Version!
          another.property=value
    
  • Output

      2020-03-11 13:55:52.554  INFO 1 --- [scheduling-1] o.s.boot.SpringApplication               : Started application in 0.436 seconds (JVM running for 280.067)
      The first message is: Changed Version!
      The other message is: Dummy Message
    

4. kubernetes-leader-election-example

Not yet stater

5. kubernetes-zipkin-example

Not yet stater

spring-cloud-kubernetes-example's People

Contributors

seongpyohong avatar

Watchers

 avatar  avatar

spring-cloud-kubernetes-example's Issues

[2] Health Check Timeout Error

문제 상황
Spring Application을 수행시킬 때 걸리는 시간이 14초 정도 걸렸는데, fabric8에서 default로 가지는 liveness와 readiness timeout 시간이 10초여서 app이 시작되기도 전에 k8s가 실패로 간주하여 다음과 같은 에러 발생

Events:
  Type     Reason          Age                  From                     Message
  ----     ------          ----                 ----                     -------
  Normal   Scheduled       129m                 default-scheduler        Successfully assigned default/example-bc9bb5fb7-fr64q to docker-desktop
  Normal   Pulled          129m                 kubelet, docker-desktop  Container image "spring-cloud-k8s/example:latest" already present on machine
  Normal   Created         129m                 kubelet, docker-desktop  Created container spring-boot
  Normal   Started         129m                 kubelet, docker-desktop  Started container spring-boot
  Warning  Unhealthy       128m (x2 over 128m)  kubelet, docker-desktop  Readiness probe failed: Get http://10.1.0.225:8080/actuator/health: dial tcp 10.1.0.225:8080: connect: connection refused
  Warning  FailedMount     15m                  kubelet, docker-desktop  MountVolume.SetUp failed for volume "default-token-crld9" : couldn't propagate object cache: timed out waiting for the condition
  Normal   SandboxChanged  15m                  kubelet, docker-desktop  Pod sandbox changed, it will be killed and re-created.
  Normal   Pulled          102s (x2 over 15m)   kubelet, docker-desktop  Container image "spring-cloud-k8s/example:latest" already present on machine
  Normal   Created         102s (x2 over 15m)   kubelet, docker-desktop  Created container spring-boot
  Normal   Started         101s (x2 over 15m)   kubelet, docker-desktop  Started container spring-boot
  Warning  Unhealthy       84s (x5 over 15m)    kubelet, docker-desktop  Readiness probe failed: Get http://10.1.0.231:8080/actuator/health: dial tcp 10.1.0.231:8080: connect: connection refused
  Normal   Killing         6s                   kubelet, docker-desktop  Stopping container spring-boot

[3] ImagePullBackOff error

문제 상황
Fabric8의 Zero-config를 사용하여 배포할 경우, local docker registry에 도커 이미지가 push 된다. 하지만, GKE에서 생성된 pod는 이미지를 GCR에서 가져오기 때문에 이미지를 찾지 못한다.

Events:
  Type     Reason          Age                   From                                      Message
  ----     ------          ----                  ----                                      -------
  Normal   Scheduled       22m                   default-scheduler                         Successfully assigned default/kubernetes-hello-world-example-8549c6f8c5-xn6v7 to gke-sphong-pool-1-04373eea-9lr3
  Normal   SandboxChanged  22m                   kubelet, gke-sphong-pool-1-04373eea-9lr3  Pod sandbox changed, it will be killed and re-created.
  Normal   BackOff         21m (x6 over 22m)     kubelet, gke-sphong-pool-1-04373eea-9lr3  Back-off pulling image "sphong/kubernetes-hello-world-example:latest"
  Normal   Pulling         20m (x4 over 22m)     kubelet, gke-sphong-pool-1-04373eea-9lr3  Pulling image "sphong/kubernetes-hello-world-example:latest"
  Warning  Failed          20m (x4 over 22m)     kubelet, gke-sphong-pool-1-04373eea-9lr3  Failed to pull image "sphong/kubernetes-hello-world-example:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for sphong/kubernetes-hello-world-example, repository does not exist or may require 'docker login'
  Warning  Failed          20m (x4 over 22m)     kubelet, gke-sphong-pool-1-04373eea-9lr3  Error: ErrImagePull
  Warning  Failed          2m16s (x88 over 22m)  kubelet, gke-sphong-pool-1-04373eea-9lr3  Error: ImagePullBackOff

fabric8io/fabric8-maven-plugin

[1] Health Check Path Error

문제 상황
Fabric8을 통해 k8s resource를 생성할 경우, liveness와 readiness를 check하는 defualt경로가 /health 이다. 하지만, 해당 경로를 인식하지 못해서 health check 시 실패가 발생

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.