How to deploy a simple Hello World program to local Kubernetes cluster

3/11/2020

I have a very simple spring-boot Hello World program. When I run the application locally, I can navigate to http://localhost:8080/ and see the "Hello World" greeting displayed on the page. I have also created a Dockerfile and can build an image from it.

My next goal is to deploy this to a local Kubernetes cluster. I have used Docker Desktop to create a local kubernetes cluster. I want to create a deployment for my application, host it locally on the cluster, and access it from a browser.

I am not sure where to start with this deployment. I know that I will need to create charts, but I have no idea how to ultimately push this image to my cluster...

-- Mike Ippolito
docker
docker-desktop
kubernetes
kubernetes-helm
spring-boot

2 Answers

3/11/2020

you need to define deployment first to start , define docker image and required environment in deployment.

-- ANISH KUMAR MOURYA
Source: StackOverflow

3/11/2020

You need to create a kubernetes deployment and service definitions respectively.

These definitions can be in json or yaml format. Here is example definitions, you can use these definitions as template for your deploy.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-very-first-deployment
  labels:
    app: first-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: first-deployment
  template:
    metadata:
      labels:
        app: first-deployment
    spec:
      containers:
      - name: your-app
        image: your-image:with-version
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: your-service
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30180
      targetPort: 8080
  selector:
    app: first-deployment

Do not forget to update image line in deployment yaml with your image name and image version. After that replacement, save this file with name for example deployment.yaml and then apply this definition with kubectl apply -f deployment.yml command.

Note that, you need to use port 30180 to access your application as it is stated in service definition as nodePort value. (http://localhost:30180)

Links:

Kubernetes services: https://kubernetes.io/docs/concepts/services-networking/service/

Kubernetes deployments: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

-- kadir
Source: StackOverflow