Deploy to Kubernetes (Helm)
Useful Links¶
Deploying scala sbt microservice to Kubernetes
Deployment of a sbt
-built app on Kubernetes (MiniKube)¶
Test packaging without Kubernetes first¶
- Stage all Play files in a local directory and verify
- For direct deployment, create a distribution in
target/universal
The dist
task builds a binary version of your application that you can deploy to a server without any dependency on SBT, the only thing the server needs is a Java installation.
Deploy a Helm chart to Kubernetes¶
Prerequisites: minikube
, kubectl
, docker
client and helm
should be installed
- Generate the Dockerfile and environment prepared for creating a Docker image
-
Verify the output under
target/docker
-
Start
minikube
- Enable Ingress
Also consider enabling heapster
- List available nodes to verify that
kubectl
is properly configured
It should return one node.
- Connect the Docker client to the Docker daemon in the K8s VM
Just make sure you tag your Docker image with something other than ‘latest’ and use that tag while you pull the image.
Otherwise, if you do not specify version of your image, it will be assumed as :latest
, with pull image policy of Always
correspondingly, which may eventually result in ErrImagePull as you may not have any versions of your Docker image out there in the default docker registry (usually DockerHub) yet.
-
If needed, remove previously built images from the local Docker server with
sbt docker:clean
ordocker rmi <image>
. To view the list of Docker images, rundocker images
-
Build the Docker image and publish it to Kubernetes' Docker server.
- Deploy the Helm chart
and if that looks OK
or specify a release name:
- Verify the Helm deployment to
minikube
More details via:
- Test the deployment by forwarding a local port to a port on the pod
kubectl get pods
kubectl port-forward <pod name> 8080:<target port on pod>
curl -v https://localhost:8080/api
kubectl port-forward
also allows using resource name, such as a service name, to select a matching pod to port forward to
- When needed, delete the release with
If you want to deploy / not deploy an Ingress¶
- Update
values.yaml
in the Helm chart root folder
- If true, make sure the minikube Ingress add-on is enabled
- Deploy on Kubernetes as above
See Blog
SSL Termination (TO DO)¶
- Generate a x509, pem encoded, RSA 2048 certificate with OpenSSL
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ${KEY_FILE} -out ${CERT_FILE} -subj "/CN=${HOST}/O=${HOST}"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=john-cd.com"
Note: To find myhost.com for minikube, run the following commands:
- Create a Kubernetes secret
kubectl create secret tls ${CERT_NAME} --key ${KEY_FILE} --cert ${CERT_FILE}
kubectl create secret tls my-secret --key tls.key --cert tls.crt
Add under spec:
in
Find and delete all nginx pods to force the nginx.conf
to update and reflect the ingress changes. Find the ingress pods with the following: