Commit c5024e91 authored by Nikos Psaromanolakis's avatar Nikos Psaromanolakis
Browse files

Edit README.md

parent e854c64b
Loading
Loading
Loading
Loading
+383 −55
Original line number Diff line number Diff line
# ocm-managed

Helm chart for registering a Kubernetes cluster as an **Open Cluster Management (OCM) managed cluster** with integrated **OpenZiti tunneling**.

## Features

* Retrieves OCM registration information from the hub.
* Executes `clusteradm join`.
* Installs the OCM Klusterlet agents.
* Creates and enrolls an OpenZiti identity for the managed cluster.
* Deploys the OpenZiti `ziti-edge-tunnel`.
* Checks direct connectivity to the hub Kubernetes API.
* Creates a cluster-specific OpenZiti Dial policy when direct hub connectivity is unavailable.
* Cleans up OCM and OpenZiti resources during Helm uninstall.

## Registration Flow

```text
Helm install ocm-managed
        |
        v
OpenZiti bootstrap
        |
        +--> Create cluster1-ziti identity
        +--> Retrieve enrollment JWT
        +--> Enroll identity
        +--> Create Kubernetes identity Secret
        |
        v
Start ziti-edge-tunnel
        |
        v
Read hub API endpoint from supplied hub kubeconfig
        |
        v
Check direct hub connectivity
        |
        +-----------------------------+
        |                             |
     reachable                    unreachable
        |                             |
        |                             v
        |                    Authenticate to OpenZiti
        |                             |
        |                             v
        |                    Create Dial policy
        |                             |
        +-------------+---------------+
                      |
                      v
              clusteradm get token
                      |
                      v
          Create local managed kubeconfig
                      |
                      v
                clusteradm join
                      |
                      v
               Install Klusterlet
                      |
                      v
             Registration CSR -> Hub
                      |
                      v
              Registration accepted
                      |
                      v
              Managed cluster ready
```

## OpenZiti Dependency

The chart includes the OpenZiti tunneler as a Helm dependency:

```yaml
dependencies:
  - name: ziti-edge-tunnel
    version: "1.5.0"
    repository: "https://openziti.io/helm-charts/"
    condition: openziti.enabled
```

Retrieve the dependency with:

```bash
helm dependency update
```

## Configuration

Example `values.yaml`:

```yaml
clusterName: cluster1
hubKubeconfigBase64: ""

openziti:
  enabled: true

## Getting started
  controller:
    url: "https://<OPENZITI-CONTROLLER>:8441"
    username: "<OPENZITI-USERNAME>"
    password: "<OPENZITI-PASSWORD>"

To make it easy for you to get started with GitLab, here's a list of recommended next steps.
  identity:
    name: "cluster1-ziti"
    secretName: "ziti-cluster1-identity"

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
  hubApi:
    serviceName: "ocm-hub-api"

## Add your files
ziti-edge-tunnel:

* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
  image:
    registry: docker.io
    repository: openziti/ziti-edge-tunnel
    tag: "1.1.5"

  secret:
    existingSecretName: "ziti-cluster1-identity"
    keyName: persisted-identity

  tolerations:
    - operator: Exists
```
cd existing_repo
git remote add origin https://labs.etsi.org/rep/osl/hypo/code/addons/ocm-managed.git
git branch -M main
git push -uf origin main

### Configuration Reference

| Value                                        | Description                                                                              |
| -------------------------------------------- | ---------------------------------------------------------------------------------------- |
| `clusterName`                                | Name under which this Kubernetes cluster is registered in OCM.                           |
| `hubKubeconfigBase64`                        | Base64-encoded kubeconfig used to access the OCM hub during registration.                |
| `openziti.enabled`                           | Enables the OpenZiti integration and `ziti-edge-tunnel` dependency.                      |
| `openziti.controller.url`                    | OpenZiti Controller management API endpoint.                                             |
| `openziti.controller.username`               | Username used by the bootstrap and join Jobs to authenticate to the OpenZiti Controller. |
| `openziti.controller.password`               | Password used to authenticate to the OpenZiti Controller.                                |
| `openziti.identity.name`                     | OpenZiti identity created for this managed cluster.                                      |
| `openziti.identity.secretName`               | Kubernetes Secret where the enrolled OpenZiti identity JSON is stored.                   |
| `openziti.hubApi.serviceName`                | Name of the OpenZiti service exposing the OCM hub Kubernetes API.                        |
| `ziti-edge-tunnel.image.*`                   | Container image configuration for the OpenZiti tunneler.                                 |
| `ziti-edge-tunnel.secret.existingSecretName` | Secret mounted by the tunneler. This should match `openziti.identity.secretName`.        |
| `ziti-edge-tunnel.secret.keyName`            | Key inside the Secret containing the OpenZiti identity JSON.                             |

The following values must reference the same Kubernetes Secret:

```text
openziti.identity.secretName
              |
              +----> generated by bootstrap Job

ziti-edge-tunnel.secret.existingSecretName
              |
              +----> consumed by ziti-edge-tunnel
```

## Integrate with your tools
## Hub Kubeconfig

The managed chart requires a kubeconfig that points to the OCM hub Kubernetes API.

* [Set up project integrations](https://labs.etsi.org/rep/osl/hypo/code/addons/ocm-managed/-/settings/integrations)
The kubeconfig is passed as a base64-encoded value through:

```yaml
hubKubeconfigBase64: ""
```

## Collaborate with your team
Encode the hub kubeconfig with:

* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
```bash
base64 -w0 hub-kubeconfig.yaml
```

## Test and Deploy
During installation, the kubeconfig is stored in a Kubernetes Secret and mounted into the join Job as:

Use the built-in continuous integration in GitLab.
```text
/hub/kubeconfig
```

* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
It is used to communicate with the OCM hub and retrieve the registration token.

***
The chart also creates a temporary kubeconfig for the local managed cluster:

# Editing this README
```text
/tmp/managed-kubeconfig
```

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
The two kubeconfigs have different purposes:

## Suggestions for a good README
```text
/hub/kubeconfig
      |
      +--> OCM hub
      |
      +--> clusteradm get token

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.
/tmp/managed-kubeconfig
      |
      +--> local managed cluster
      |
      +--> clusteradm join
```

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## OpenZiti Bootstrap

During the initial Helm installation, the chart automatically creates the OpenZiti identity required by the managed cluster.

The bootstrap process is:

```text
Authenticate to OpenZiti Controller
        |
        v
Create cluster1-ziti identity
        |
        v
Retrieve enrollment JWT
        |
        v
Enroll identity
        |
        v
Generate identity.json
        |
        v
Create Kubernetes Secret
ziti-cluster1-identity
        |
        v
Start ziti-edge-tunnel
```

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
The generated identity JSON is stored in the Kubernetes Secret under the key:

```text
persisted-identity
```

The `ziti-edge-tunnel` subchart mounts this Secret and starts the OpenZiti tunneler using the enrolled managed-cluster identity.

## Direct Connectivity and OpenZiti Fallback

Before running the OCM registration, the chart checks whether the hub Kubernetes API is directly reachable.

The hub API endpoint is extracted from:

```text
/hub/kubeconfig
```

If direct connectivity works:

```text
Managed Cluster
      |
      +-------- direct --------> Hub API
```

No OpenZiti Dial policy is created.

If direct connectivity is unavailable:

```text
cluster1-ziti
      |
      | Dial
      v
ocm-hub-api
      |
      | Bind
      v
hub-ziti
      |
      v
Hub Kubernetes API
```

The managed chart creates only the cluster-specific Dial policy.

For example:

```text
ocm-hub-api-cluster1-dial
```

The following OpenZiti objects are created and owned by the `ocm-hub` chart:

```text
ocm-hub-api
ocm-hub-api-intercept
ocm-hub-api-host
ocm-hub-api-bind
```

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
The managed chart only creates the Dial permission required for its own OpenZiti identity to consume the hub API service.

After OpenZiti connectivity becomes available, the OCM registration process continues using the same hub API endpoint contained in the kubeconfig.

## OCM Join Process

The join Job retrieves the OCM registration information from the hub:

```bash
clusteradm get token
```

It then executes:

```bash
clusteradm join \
  --hub-token <token> \
  --hub-apiserver <hub-api> \
  --wait \
  --cluster-name <cluster-name>
```

`clusteradm join` installs and configures the OCM Klusterlet on the managed cluster.

The Klusterlet includes the OCM agents responsible for communication with the hub, primarily:

* `registration-agent`
* `work-agent`

The registration agent creates the registration CSR on the hub. The hub-side acceptance CronJob subsequently approves the registration.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
Update Helm dependencies:

```bash
helm dependency update
```

Install the managed chart:

```bash
helm install ocm-managed . \
  -n ocm-managed \
  --create-namespace \
  --set clusterName=cluster1 \
  --set hubKubeconfigBase64="$(base64 -w0 hub-kubeconfig.yaml)" \
  --timeout 10m
```

## Verification

Check the Klusterlet:

```bash
kubectl get klusterlet
```

Check the OCM agents:

```bash
kubectl get pods -n open-cluster-management-agent
```

Check the OpenZiti tunneler:

```bash
kubectl get pods -n ocm-managed \
  -l app.kubernetes.io/name=ziti-edge-tunnel
```

Check the tunneler logs:

```bash
kubectl logs -n ocm-managed \
  -l app.kubernetes.io/name=ziti-edge-tunnel
```

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
Check the tunneler image:

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
```bash
kubectl get pods -n ocm-managed \
  -l app.kubernetes.io/name=ziti-edge-tunnel \
  -o jsonpath='{range .items[*]}{.metadata.name}{" -> "}{.spec.containers[*].image}{"\n"}{end}'
```

## OpenZiti Service Model

The current integration uses OpenZiti to provide connectivity to the OCM hub Kubernetes API when the direct network path is unavailable.

The same model can later be reused for application-to-application connectivity across managed clusters.

For example:

## Contributing
State if you are open to contributions and what your requirements are for accepting them.
```text
Cluster A                         Cluster B

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
frontend                         backend
   |                                ^
   |                                |
   +------ OpenZiti Service --------+
```

The orchestrator can dynamically create the required OpenZiti service, `intercept.v1`, `host.v1`, Bind policy, and Dial policy after workload placement.

This allows connectivity without requiring prior knowledge of:

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
* the remote cluster CNI;
* Pod CIDRs;
* Service CIDRs;
* direct Layer 3 connectivity between clusters.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## Uninstall

```bash
helm uninstall ocm-managed -n ocm-managed
```

## License
For open source projects, say how it is licensed.
The cleanup hook removes:

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
* the Klusterlet;
* OCM agent resources and namespaces;
* the cluster-specific OpenZiti Dial policy, if present;
* the managed-cluster OpenZiti identity;
* the generated identity Secret;
* OpenZiti bootstrap Role and RoleBinding;
* OpenZiti bootstrap ServiceAccount.