Coder Social home page Coder Social logo

hello-fun's Introduction

hello-fun template repo

This accelerator repo provides a simple Hello web app based on Spring Boot and Spring Cloud Function.

It can be deployed as a standalone web app, as a Kubernetes Deployment and Service, or as a Knative Service.

The code

NOTE: The project is configured for Java 11, if you are using Java 8, then modify the java.version property in pom.xml.

The project contains the following:

.
├── README.md
├── knative-logo.jpg
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── example
    │   │           └── hello
    │   │               └── HelloFunApplication.java
    │   └── resources
    │       └── application.properties
    └── test
        └── java
            └── com
                └── example
                    └── hello
                        └── HelloFunApplicationTests.java

12 directories, 8 files

You can modify the source code using Visual Studio Code:

code .

The Function that is used by this app is located at src/main/java/com/example/helloapp/HelloFunApplication.java

You can build the project using the provided Maven wrapper:

mvn clean package

Standalone app with embedded Netty HTTP server

To run the app using the embedded server you can run this command:

mvn spring-boot:run

You can then access the function using curl:

curl -w'\n' -H 'Content-Type: text/plain' localhost:8080 -d "Fun"

Kubernetes Simple Deployment and Service

This accelerator relies on using the new buildpack support added in Spring Boot version 2.3 to create a container image.

If you are using Minikube you should configure your terminal to use the same Docker environment:

eval $(minikube docker-env)

Step 1: Build the project and create the container image:

mvn clean package spring-boot:build-image

Step 2: Deploy the app to Kubernetes

kubectl apply -f kubernetes/app

Use kubectl get all to verify that the resources created.

Accessing the application's endpoint varies based on the type of Kubernetes cluster you are using. For example, if minikube is being used, look for the endpoint to access using the command minikube service list

The README.md file from the code repository for the appliation should include a few curl commands to exercise the application.

Skaffold build and deploy to Kubernetes

For a local cluster like Minikube or Docker Desktop you can simply run:

skaffold run --port-forward --profile=local --tail

For a remote cluster you need to specify the default-repo which is the registry prefix for the image that is being built. For Docker Hub the prefix would be your Docker ID, for other registries it would typically be the registry URL plus your project.

NOTE: You must specify a registry prefix where you have permission to push images.

You can do this globally by running:

skaffold config set --global default-repo ${REGISTRY_PREFIX}

Or, you can set it for the current Kubernetes context:

skaffold config set default-repo ${REGISTRY_PREFIX}

Finally, you can specify it as part of the run command:

skaffold run --default-repo ${REGISTRY_PREFIX} --port-forward --tail

The skaffold run command will build the container image, deploy the application and port-forward the service to localhost:8080

Open another terminal window to interract with the application or Kubernetes API server.

You can use kubectl get all to verify that the resources were created.

If you leave out the --port-forward option then accessing the application's endpoint varies based on the type of Kubernetes cluster and ingress configuration you are using.

Delete the application

To delete the deployment and the service from your Kubernetes cluster run:

skaffold delete

hello-fun's People

Contributors

jldec avatar

Watchers

 avatar  avatar

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.