////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
////
= Quarkus - Deploying on Kubernetes and OpenShift

include::./attributes.adoc[]

This guide covers:

* The deployment of the application to Kubernetes
* The deployment of the application to OpenShift

This guide takes as input the application developed in the link:building-native-image.html[native application guide].
So, you should have been able to package your application as a binary executable, copied it in a Docker image and run this image.

Depending on whether you are a _bare_ Kubernetes user or an OpenShift user, pick the section you need.
The OpenShift section leverages OpenShift _builds_ and _routes_ features which are not available in _bare_ Kubernetes.

== Prerequisites

For this guide you need:

* roughly 10 minutes (20 minutes if you want to deploy the application on both platforms)
* having access to a Kubernetes and/or OpenShift cluster. Minikube and Minishift are valid options.
* being able to package the docker image from the link:building-native-image.html[native application guide]

== Solution

We recommend to follow the instructions in the next sections and build the application step by step.
However, you can go right to the completed example.

Clone the Git repository: `git clone {quickstarts-clone-url}`, or download an {quickstarts-archive-url}[archive].

The solution is located in the `getting-started` directory.

== Deploying the application in Kubernetes

First, you need to _push_ the Docker image (created in the link:building-native-image.html[previous] guide) to the image registry of your Kubernetes cluster.
Depending on your cluster, there are several ways.
For `minikube`, execute:

[source,shell]
----
# For minishift use "eval $(minishift docker-env)" instead
eval $(minikube docker-env)

docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/quickstart .
----

Once the image has been pushed to the Kubernetes image registry, instantiate the application as follows:

[source,shell]
----
kubectl run quarkus-quickstart --image=quarkus-quickstart/quickstart:latest --port=8080 --image-pull-policy=IfNotPresent
kubectl expose deployment quarkus-quickstart --type=NodePort
----

The application is now exposed as an internal service. If you are using `minikube`, you can access it using:

[source,shell]
----
curl $(minikube service quarkus-quickstart --url)/hello
----

== Deploying the application in OpenShift

In this section, we are going to leverage the build mechanism of OpenShift. Run:

[source,shell]
----
# To build the image on OpenShift
oc new-build --binary --name=quarkus-quickstart -l app=quarkus-quickstart
oc patch bc/quarkus-quickstart -p "{\"spec\":{\"strategy\":{\"dockerStrategy\":{\"dockerfilePath\":\"src/main/docker/Dockerfile.native\"}}}}"
oc start-build quarkus-quickstart --from-dir=. --follow

# To instantiate the image
oc new-app --image-stream=quarkus-quickstart:latest

# To create the route
oc expose service quarkus-quickstart

# Get the route URL
export URL="http://$(oc get route | grep quarkus-quickstart | awk '{print $2}')"
echo "Application URL: $URL"
curl $URL/hello && echo
----

Your application is accessible at the printed URL.

== Going further

This guide covered the deployment of a Quarkus application on Kubernetes and OpenShift.
However, there is much more, and the integration with these environments has been tailored to make Quarkus applications execution very smooth.
For instance, the health extension can be used for health check; the configuration support allows mounting the application configuration using config map, the metric extension produces data _scrappable_ by Prometheus and so on.

