这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@AymenSegni
Copy link
Owner

@AymenSegni AymenSegni commented Jun 1, 2020

Deploy Springboot and MySQL on Kubernetes

The first step is to obtain the application source code and Dockerfile.
and use them as a starting point for creating a custom yaml manifests to automate the application deployment in a Kubernetes cluster.

I used Minikube to deploy this Springboot application, but it should work with any cloud provider or distribution.

Assumption And Prerequisites

  • You have a Docker environment running.
  • You have an account in a container registry (this project assumes that you are using Docker Hub).
  • You have Minikube installed in your local computer.
  • You have the kubectl command line (kubectl CLI) installed.
  • You have Java JDK v8 installed
  • You have Maven installed on your machine for local deployment
  • You have Helm v3 installed on your machine for deployment (optional)

Run the application on Kubernetes

Build the Application with Maven

$ mvn package

Create Application environment Secrets

$ kubectl create secret generic mysql-root-pass --from-literal=password=password
$ kubectl create secret generic mysql-user-pass --from-literal=username=sa --from-literal=password=password

$ kubectl create secret generic mysql-db-url --from-literal=database=test --from-useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false'

Verfiy secrets creation

$ kubectl get secrets

NAME                  TYPE                                  DATA   AGE
default-token-qw42v   kubernetes.io/service-account-token   3      6m11s
mysql-db-url          Opaque                                2      3m33s
mysql-root-pass       Opaque                                1      5m49s
mysql-user-pass       Opaque                                2      5m18s

Deploy the users-mysql Application on Kubernetes

$ kubectl apply -f k8s-deployment/app-deployment.yaml

Verfiy Deployment

$ kubectl  get pods
NAME                                  READY   STATUS    RESTARTS   AGE
users-mysql-6f9858cfd-ptmjl           1/1     Running   0          94s
users-mysql-6f9858cfd-sngph           1/1     Running   0          94s

$ kubectl  get deployments.apps
NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
users-mysql          2/2     2            2           3m16s

Verify the application's service

$ minikube service list
|-------------|--------------------|----------------------------|-----|
|  NAMESPACE  |        NAME        |        TARGET PORT         | URL |
|-------------|--------------------|----------------------------|-----|
| default     | kubernetes         | No node port               |
| default     | users-mysql        | http://192.168.64.23:30793 |
| kube-system | kube-dns           | No node port               |

Deploy MySQL

$ kubectl apply -f k8s-deployment/mysql.yaml

Verfiy MySQL Deployment : user-mysql-server

$  kubectl get deployments

NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
users-mysql-server   1/1     1            1           61s

Get Application's service url

$ minikube service users-mysql --url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants