fabric8:apply goal takes the JSON file generated via mvn fabric8:json located at
target/classes/kubernetes.json and applies it to the current Kubernetes environment and namespace.
For a summary of the options see the Maven Property Reference
Also if you are using a local docker registry, make sure it is network accessible to your Kubernetes cluster.
You can use the maven property
fabric8.domain or the environment variable
$KUBERNETES_DOMAIN to define the DNS host to expose services automatically using OpenShift Routes
The Kubernetes environment and authentication is defined by the kubernetes-api environment variables. In particular:
KUBERNETES_MASTER- the location of the kubernetes master
KUBERNETES_NAMESPACE- the default namespace used on operations
If no configuration is supplied through maven properties or environment variables, the
fabric8:apply goal will try to find the current login token and namespace by parsing the users
This means that if you use the OpenShift command line tool
oc you can login and change projects (namespaces in kubernetes speak) and those will be used by default by the
fabric8:apply goal. e.g.
oc login oc project cheese mvn fabric8:apply
In the above, if there is no
KUBERNETES_NAMESPACE environment variable or maven property called
fabric8.namespace then the
fabric8:apply goal will apply the Kubernetes resources to the
To apply the kubernetes resources generated by the mvn fabric8:json goal use the following goal:
To specify an explicit namespace and domain in recreate mode:
mvn fabric8:apply -Dfabric8.recreate=true \ -Dfabric8.domain=foo.acme.com -Dfabric8.namespace=cheese
You can use the
fabric8.namespace system property to explicitly specify the kubernetes namespace to apply things to...
mvn fabric8:rolling -Dfabric8.namespace=cheese
Or you can use the
fabric8.environment system property to refer to a named environment such as
Production which is then mapped to the physical namespace by using the fabric8.yml file.
mvn fabric8:rolling -Dfabric8.environment=Staging
This lets you keep a level of indirection between the logical environment names for a project and the physical namespaces in kubernetes which probably have team or user prefixes/postfixes. This lets you share the same Jenkinsfiles (Jenkins workflow groovy scripts) across different projects.
e.g. you can have a standard command to apply to the Staging environment and this can be applied to any project which has a
fabric8.yml file generated.
Applying an OpenShift template works the same as a regular
List of Kubernetes resources.
One difference is that you may wish to override some of the template parameter values as you apply the template which you can do on the command line via system properties.
mvn fabric8:apply -Dfabric8.apply.FOO=bar
The above will apply the OpenShift template defined in
target/classes/kubernetes.json overriding the template parameter
FOO with the value
bar before processing the template and creating/updating the resources.
The following maven property values are used to configure the behaviour of the apply goal:
You define the maven properties in the
pom.xml file using the
<properties> tag such as:
<properties> <fabric8.label.container>java</fabric8.label.container> <fabric8.label.group>myapp</fabric8.label.group> <fabric8.iconRef>camel</fabric8.iconRef> </properties>
If you wish to override or add a property from the command line, you can do this by using Java JVM system properties. A property from the command line will override any existing option configured in the
mvn fabric8:apply -Dfabric8.recreate=true
There are many options as listed in the following table:
|fabric8.apply.create||Should we create new resources (not in the kubernetes namespace). Defaults to
|fabric8.apply.servicesOnly||Should only services be processed. This lets you run 2 builds, process the services only first; then process non-services. Defaults to
|fabric8.apply.ignoreServices||Ignore any services in the JSON. This is useful if you wish to recreate all the ReplicationControllers and Pods but not recreate Services (which can cause
|fabric8.apply.createRoutes||If there is a route domain (see
|fabric8.domain||The domain to expose the services as OpenShift Routes. Defaults to
|fabric8.extended.environment.metadata||Whether to try to fetch extended environment metadata during the json, or apply goals. The following ENV variables is supported: BUILD_URI, GIT_URL, GIT_COMMIT, GIT_BRANCH If any of these ENV variable is empty then if this option is enabled, then the value is attempted to be fetched from an online connection to the Kubernetes master. If the connection fails then the goal will report this as a failure gently and continue. This option can be turned off, to avoid any live connection to the Kubernetes master.|
|fabric8.namespace||Specifies the namespace (or OpenShift project name) to apply the kubernetes resources to. If not specified it will use the
|fabric8.recreate||If enabled then all resources that are found are deleted first before being recreated. Defaults to