Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreswebs/k8s-fleet-fluxcd-template
Template containing intial Kubernetes configuration files for a multi-cluster k8s fleet using FluxCD
https://github.com/andreswebs/k8s-fleet-fluxcd-template
fluxcd kubernetes
Last synced: 4 days ago
JSON representation
Template containing intial Kubernetes configuration files for a multi-cluster k8s fleet using FluxCD
- Host: GitHub
- URL: https://github.com/andreswebs/k8s-fleet-fluxcd-template
- Owner: andreswebs
- License: unlicense
- Created: 2021-05-04T17:55:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T11:47:52.000Z (9 months ago)
- Last Synced: 2024-11-08T02:47:10.205Z (about 2 months ago)
- Topics: fluxcd, kubernetes
- Homepage:
- Size: 77.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# k8s-fleet
## Structure
This repository has the following directory structure:
```
.
├── README.md
├── .gitignore
├── .sourceignore
├── .editorconfig
├── .yamllint
├── applications
│ ├── base
│ └── overlays
├── clusters
│ ├── kind-local
| | ├── flux-system
| | ├── apps.yaml
| | ├── infra-base.yaml
| | ├── infra.yaml
| | ├── secrets.yaml
| | └── sources.yaml
│ └── shared-deployer
├── infrastructure
│ ├── base
│ └── overlays
├── infrastructure-base
│ ├── base
│ └── overlays
├── secrets
│ ├── base
│ └── overlays
└── sources
├── .yaml
├── (...)
└── kustomization.yaml
```### Directories
- `clusters/`: contains the Flux configuration per cluster under
`clusters/`
- `sources/`: source definitions common to all clusters
- `infrastructure-base/`: kustomizations or Helm releases with a custom
configuration per cluster, for Kubernetes add-ons and other base applications
that are dependencies for other apps
- `secrets/`: custom resources managed by the External Secrets Operator, to
handle secrets stored in external platforms
- `infrastructure/`: kustomizations or Helm releases with a custom configuration
per cluster, for Kubernetes add-ons and other base applications that are
dependencies for other apps, and which depend on add-ons from
`infrastructure-base/` and/or resources from `secrets/`
- `applications/`: kustomizations or Helm releases with a custom configuration
per cluster, for any other appsEach cluster in the `clusters` directory has a `flux-system` directory with
automatically-generated configuration (`clusters//flux-system`)
injected by FluxCD on bootstrap (described below).### Order of kustomizations
The `infrastructure-base`, `secrets`, `infrastructure` and `applications`
directories are structured as kustomization directories. These directories are
deployed as FluxCD `Kustomization` resources.Each kustomization directory has a base directory named `/base` and an
overlays directory named `/overlays`. Overlays directories contain one
overlay per cluster, each named `/overlays/`. The `/base`
directories contain common configurations ("bases") used across clusters. The
base directories contain "bases" distributed in subdirectories of the
`/base`. Overlays directories (`/overlays/`) contain patches
per cluster over the defined bases.The `source` directory doesn't contain a base and overlays subdirectories, but
it is also considered a kustomization. It currently doesn't have any
cluster-specific configuration, and is applied without variance to all clusters.
This could be further configured to accomodate cluster differences in sources if
desired, by following the same structure.The set of Kustomization resources in this repository is applied in a defined
order in which each kustomization depends on the previous one.The order is defined implicitly within the Flux configuration directory for each
cluster (`clusters/`). Each `Kustomization` used by a cluster is
defined in a separate file in the cluster directory. Kustomizations declare the
dependencies for that kustomization in their `spec.dependsOn` property.The configured order for this repository is the following (the list uses the
deployed Kustomization resource names):1. sources
2. infra-base
3. secrets
4. infra
5. apps## Example cluster: kind-local
Create a new repository using this template.
To test the configurations in this repo using [Kind](https://kind.sigs.k8s.io/)
(Kubernetes-in-Docker), assuming the `kind` cli is
[install](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)ed, do:```sh
kind create cluster
```And follow the instructions for [FluxCD](https://fluxcd.io)
[installation](https://fluxcd.io/docs/installation/) and
[bootstrap](https://fluxcd.io/docs/get-started/#install-flux-onto-your-cluster),
using your repository as the target.Ensure that the path for the cluster is specified as `clusters/kind-local`.
## Example: Bootstrap Flux with deploy key on GitHub
First generate a deploy key. Assuming the keys to be saved under
`./keys/kind-local`, run:```sh
export KEY_DIR="$(pwd)/keys/kind-local"
``````sh
mkdir -p "${KEY_DIR}"
ssh-keygen -t ed25519 -f "${KEY_DIR}/identity" -q -N "" -C "" < /dev/null
```To get the contents of the public key:
```sh
cat "${KEY_DIR}/identity.pub"
```Add the public key to the GitHub repository (see
[instructions](https://docs.github.com/en/developers/overview/managing-deploy-keys#setup-2)).Bootstrap flux:
```sh
export CLUSTER_NAME="mu"
export GITHUB_OWNER="example-org"
export GITHUB_REPO="example-k8s-fleet"
export GITHUB_BRANCH="main"
``````sh
flux bootstrap git \
--url="ssh://[email protected]/${GITHUB_OWNER}/${GITHUB_REPO}" \
--branch="${GITHUB_BRANCH}" \
--private-key-file="${KEY_DIR}/identity" \
--path="clusters/${CLUSTER_NAME}"
```(Note: add the `--password` flag if the private key has a password.)
## Authors
**Andre Silva** - [@andreswebs](https://github.com/andreswebs)
## License
This project is licensed under the [Unlicense](UNLICENSE.md).