-
Notifications
You must be signed in to change notification settings - Fork 3k
Create Kubernetes extension #1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec0d170
Implement ap4k + kubernetes integration as the Kubernetes extension
geoand 40c3f7a
Keep only resource generation in the ap4k + kubernetes integration
geoand e134d42
Add runtime module to fix dependencies issue
geoand 0e9c4f9
Use kubernetes resources directory instead of ap4k
geoand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
= {project-name} - Deploying an Application to Kubernetes and OpenShift | ||
|
||
This guide covers: | ||
|
||
* The deployment of the application to Kubernetes | ||
* The deployment of the application to OpenShift (TODO) | ||
|
||
== Prerequisites | ||
|
||
To complete this guide, you need: | ||
|
||
* roughly 15 minutes | ||
* an IDE | ||
* JDK 1.8+ installed with `JAVA_HOME` configured appropriately | ||
* Apache Maven 3.5.3+ | ||
* access to a Kubernetes or OpenShift cluster (Minikube and Minishift are both viable options) | ||
* have the following binaries on your PATH: `docker` (for building and pushing images), `kubectl` (for deploying to Kubernetes) and `oc` (for deploying to OpenShift) | ||
|
||
== Creating the Maven project | ||
|
||
First, we need a new project that contains the kubernetes extension. This can be done using the following command: | ||
|
||
[source, subs=attributes+] | ||
---- | ||
mvn io.quarkus:quarkus-maven-plugin:${quarkus-version}:create \ | ||
-DprojectGroupId=org.acme \ | ||
-DprojectArtifactId=test \ | ||
-DclassName="org.acme.rest.GreetingResource" \ | ||
-Dpath="/greeting" \ | ||
-Dextensions="kubernetes" | ||
---- | ||
|
||
== Enable Kubernetes support | ||
|
||
{project-name} offers the ability to automatically generate Kubernetes resources based on sane defaults and user supplied configuration. The implementation that takes care | ||
of generating the actual Kubernetes resources is provided by https://github.com/ap4k/ap4k/[ap4k]. | ||
|
||
When we added the `kubernetes` extension to the command line invocation above, the following dependency was added to the `pom.xml` | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes</artifactId> | ||
</dependency> | ||
---- | ||
|
||
By adding this dependency, we now have the ability to configure the Kubernetes resource generation and application using the usual `application.properties` approach that {project-name} provides. | ||
The configuration items that are available can be found in: `io.quarkus.kubernetes.deployment.KubernetesConfig` class. | ||
Furthermore, the items provided by `io.quarkus.deployment.ApplicationConfig` affect the Kubernetes resources. | ||
|
||
By using the following configuration for example: | ||
|
||
[source] | ||
---- | ||
quarkus.kubernetes.group=yourDockerUsername # this is optional and defaults to your username if not set | ||
quarkus.application.name=test-quarkus-app # this is also optional and defaults to the project name if not set | ||
---- | ||
|
||
and following the execution of `mvn package` you will notice amongst the other files that are created, two files named | ||
`kubernetes.json` and `kubernetes.yaml` in the `target/wiring-classes/META-INF/ap4k/` directory. | ||
|
||
If you look at either file you will see that it contains both a Kubernetes `Deployment` and a `Service`. | ||
geoand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
The full source of the `kubernetes.json` file looks something like this: | ||
|
||
[source,json] | ||
---- | ||
{ | ||
"apiVersion" : "v1", | ||
"kind" : "List", | ||
"items" : [ { | ||
"apiVersion" : "apps/v1", | ||
"kind" : "Deployment", | ||
"metadata" : { | ||
"labels" : { | ||
"app" : "test-quarkus-app", | ||
"version" : "1.0-SNAPSHOT", | ||
"group" : "yourDockerUsername" | ||
}, | ||
"name" : "test-quarkus-app" | ||
}, | ||
"spec" : { | ||
"replicas" : 1, | ||
"selector" : { | ||
"matchLabels" : { | ||
"app" : "test-quarkus-app", | ||
"version" : "1.0-SNAPSHOT", | ||
"group" : "yourDockerUsername" | ||
} | ||
}, | ||
"template" : { | ||
"metadata" : { | ||
"labels" : { | ||
"app" : "test-quarkus-app", | ||
"version" : "1.0-SNAPSHOT", | ||
"group" : "yourDockerUsername" | ||
} | ||
}, | ||
"spec" : { | ||
"containers" : [ { | ||
"env" : [ { | ||
"name" : "KUBERNETES_NAMESPACE", | ||
"valueFrom" : { | ||
"fieldRef" : { | ||
"fieldPath" : "metadata.namespace" | ||
} | ||
} | ||
} ], | ||
"image" : "yourDockerUsername/test-quarkus-app:1.0-SNAPSHOT", | ||
"imagePullPolicy" : "IfNotPresent", | ||
"name" : "test-quarkus-app" | ||
} ] | ||
} | ||
} | ||
} | ||
} ] | ||
} | ||
---- | ||
|
||
An important thing to note about the `Deployment` is that is uses `yourDockerUsername/test-quarkus-app:1.0-SNAPSHOT` as the Docker image of the `Pod`. | ||
|
||
Also the `Service` is configured to use container port `8080` (which is automatically picked up by the standard Quarkus configuration). | ||
|
||
An important thing to keep in mind is that so far, all {project-name} has done is generate the `Kubernetes` resources, it has not applied them. The next section will walk you through how this can be done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2018 Red Hat, Inc. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-kubernetes-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-kubernetes-deployment</artifactId> | ||
<name>Quarkus - Kubernetes - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-spi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.ap4k</groupId> | ||
<artifactId>kubernetes-annotations</artifactId> | ||
<classifier>noapt</classifier> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.sun</groupId> | ||
<artifactId>tools</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
...ns/kubernetes/deployment/src/main/java/io/quarkus/kubernetes/deployment/DockerConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
|
||
@ConfigGroup | ||
public class DockerConfig { | ||
|
||
/** | ||
* The docker registry to which the images will be pushed | ||
*/ | ||
public String registry = "docker.io"; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ubernetes/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(phase = ConfigPhase.BUILD_TIME) | ||
public class KubernetesConfig { | ||
|
||
/** | ||
* The group of the application. | ||
* This value will be use as: | ||
* - docker image repo | ||
* - labeling resources | ||
*/ | ||
@ConfigItem | ||
public String group; | ||
|
||
/** | ||
* Configuration that is relevant to docker images | ||
*/ | ||
@ConfigItem | ||
public DockerConfig docker; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.