Skip to content

This is a simple example of a blue/green deployment. It depends on springboot2, builds by maven, deploys by kubernetes.

Notifications You must be signed in to change notification settings

SoulSong/springboot-kube-bluegreen-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Background

This is a simple example of a blue/green deployment. It depends on springboot2, builds by maven, deploys by kubernetes.

How To Use

Change Version

Change the project version in pom.xml as follow:

    <groupId>com.shf.example</groupId>
    <artifactId>springboot-kube-sample</artifactId>
    <version>Blue</version>

It will be read in VersionController:

@Slf4j
@RestController
public class VersionController {

    @Autowired(required = false)
    private BuildProperties buildProperties;

    @GetMapping("/version")
    public String version() {
        if (null == buildProperties) {
            return "UnKnow";
        }
        return buildProperties.getVersion();
    }

}

Build image

Dockerfile is in ./docker folder, just input mvn clean install command. Then we could get two images:

  • local-dtr.com/springboot-kube-sample:Blue
  • local-dtr.com/springboot-kube-sample:Green

Deploy into kubernetes cluster

In ./kubernetes folder, you will find all yaml-files for kubernetes.

Create namespace

  • kubectl create namespace blue-green

Create deployment

  • kubectl apply -f deployment-blue.yaml
  • kubectl apply -f deployment-green.yaml

Create service(blue)

  • kubectl apply -f service-blue.yaml

Create ingress

  • kubectl apply -f ingress.yaml -n blue-green

Modify hosts file

Add hosts configuration into your **/etc/hosts file, the domains which defined in ingress.yaml

127.0.0.1	shf.sample.com

Check Version

INPUT

curl -i http://shf.sample.com/sample-service/version

OUTPUT

Blue

Change service version(green)

  • kubectl apply -f service-green.yaml

ReCheck Version

INPUT

curl -i http://shf.sample.com/sample-service/version

OUTPUT

Green

About

This is a simple example of a blue/green deployment. It depends on springboot2, builds by maven, deploys by kubernetes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published