Git Product home page Git Product logo

spring-k8s-workshop's Introduction

Local Kubernetes Development with Java/Spring Boot application (Workshop)

This repository contains sample Spring Boot application, k8s definitions and scaffold setup.

What You will learn

  • How to set up Readiness and liveness probes.
  • How to wait for container lifecycle processes to finish.
  • How to enable graceful shutdown.
  • How to expose metrics.
  • How to configure logstash-logback-encoder.
  • How to debug application running inside k8s.
  • How to use live-reload feature for faster development.
  • How to use common kubectl commands and generate k8s definitions.
  • How to use Skaffold for local Kubernetes development.
  • How to use Cloud Code plugin in IntelliJ.

Getting Started

Prerequisites

  • Java 11
  • Docker
  • Kubernetes

Installation

Build docker image.

./gradlew bootBuildImage

Usage

Kubectl

  • Apply k8s configurations files from a directory.

    kubectl create -f k8s/namespace.yml
    kubectl apply -f k8s/
  • Port forward spring-k8s-workshop service.

    kubectl port-forward svc/spring-k8s-workshop 8080:8080
  • Visit http://localhost:8080/hello resource.

  • Play with kubectl api, see section 'Additional Useful Commands'.

  • [Optionally] Install and play with k9s tool (https://github.com/derailed/k9s). k9s.png

  • Destroy all spring-k8s-workshop components.

    kubectl delete all --all -n spring-k8s-workshop
    kubectl delete ns spring-k8s-workshop

Skaffold

  • Run a pipeline in development mode.

    skaffold dev --port-forward

    *** --port-froward - expose ports.

    *** --trigger=manual - disable auto-build (triggered after file change). Allowed values polling, notify, manual.

  • Visit http://localhost:8080/hello resource.

  • Make some changes inside HelloController class to see live reload feature.

  • Stop skaffold dev (CTRL + C).

  • Run skaffold in debug mode.

    # Similar to `dev`, but configures the pipeline for debugging. Auto-build and sync is disabled by default to prevent
    # accidentally tearing down debug sessions.
    skaffold debug --port-forward
  • Configure remote debugging in Intellij Idea. intellij-skaffold-remote-debug-setup.png

  • Start Debug session in Intellij Idea and create breakpoint inside HelloController.class

Cloud Code

Additional Useful Commands

Create k8s definitions using --dry-run.

# Create secret definition
kubectl create secret generic spring-k8s-workshop-secret --dry-run=client -o=yaml > secret.yaml

# Creating deployment definition
kubectl create deployment deployment_name --image=spring-k8s-workshop:0.0.1-SNAPSHOT --dry-run=client -o=yaml > deployment.yaml

# Create Service definition
kubectl create service clusterip spring-k8s-workshop --tcp=8080:8080 --dry-run=client  -o=yaml >> service.yaml

# Create config map from yml file
kubectl create configmap --dry-run somename --from-file=./src/main/resources/application-dev.yml -o=yaml

Create Secret.

# Create secret and base64 encode it
echo -n "Secret from k8s" | base64

# Create secret, base64 encode it and add it to your clipboard
echo -n "Secret from k8s" | base64 | pbcopy

References

License

Distributed under the MIT License. See LICENSE for more information.

spring-k8s-workshop's People

Contributors

rbiedrawa avatar

Watchers

 avatar

Forkers

skpandey108

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.