Skip to main content
Version: Next 🚧

Creating a Deployment

To deploy workloads onto downstream clusters, first create a Git repo, then create a GitRepo resource and apply it.

This tutorial uses the fleet-examples repository.

note

For more details on how to structure the repository and configure the deployment of each bundle see GitRepo Contents. For more details on the options that are available per Git repository see Adding a GitRepo.

Single-Cluster Examples​

All examples will deploy content to clusters with no per-cluster customizations. This is a good starting point to understand the basics of structuring Git repos for Fleet.

An example using Helm. We are deploying the helm example to the local cluster.

The repository contains a helm chart and an optional fleet.yaml to configure the deployment:

fleet.yaml
namespace: fleet-helm-example

# Custom helm options
helm:
# The release name to use. If empty a generated release name will be used
releaseName: guestbook

# The directory of the chart in the repo. Also any valid go-getter supported
# URL can be used there is specify where to download the chart from.
# If repo below is set this value if the chart name in the repo
chart: ""

# An https to a valid Helm repository to download the chart from
repo: ""

# Used if repo is set to look up the version of the chart
version: ""

# Force recreate resource that can not be updated
force: false

# How long for helm to wait for the release to be active. If the value
# is less that or equal to zero, we will not wait in Helm
timeoutSeconds: 0

# Custom values that will be passed as values.yaml to the installation
values:
replicas: 2

To create the deployment, we apply the custom resource to the upstream cluster. The fleet-local namespace contains the local cluster resource. The local fleet-agent will create the deployment in the fleet-helm-example namespace.

kubectl apply -n fleet-local -f - <<EOF
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: helm
spec:
repo: https://github.com/rancher/fleet-examples
paths:
- single-cluster/helm
EOF

Multi-Cluster Examples​

The examples below will deploy a multi git repo to multiple clusters at once and configure the app differently for each target.

An example using Helm. We are deploying the helm example and customizing it per target cluster

The repository contains a helm chart and an optional fleet.yaml to configure the deployment. The fleet.yaml is used to configure different deployment options, depending on the cluster's labels:

fleet.yaml
namespace: fleet-mc-helm-example
targetCustomizations:
- name: dev
helm:
values:
replication: false
clusterSelector:
matchLabels:
env: dev

- name: test
helm:
values:
replicas: 3
clusterSelector:
matchLabels:
env: test

- name: prod
helm:
values:
serviceType: LoadBalancer
replicas: 3
clusterSelector:
matchLabels:
env: prod

To create the deployment, we apply the custom resource to the upstream cluster. The fleet-default namespace, by default, contains the downstream cluster resources. The chart will be deployed to all clusters in the fleet-default namespace, which have a labeled cluster resources that matches any entry under targets:.

gitrepo.yaml
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: helm
namespace: fleet-default
spec:
repo: https://github.com/rancher/fleet-examples
paths:
- multi-cluster/helm
targets:
- name: dev
clusterSelector:
matchLabels:
env: dev

- name: test
clusterSelector:
matchLabels:
env: test

- name: prod
clusterSelector:
matchLabels:
env: prod

By applying the gitrepo resource to the upstream cluster, fleet will start to monitor the repository and create deployments:

kubectl apply -n fleet-default -f gitrepo.yaml