Skip to content

Commit

Permalink
address PR feedback about capitalization of k8s resources, basic exam…
Browse files Browse the repository at this point in the history
…ple at the top, bullet point list of assumptions

Signed-off-by: Paweł Bojanowski <[email protected]>
  • Loading branch information
hidalgopl committed Feb 19, 2025
1 parent 7fcc5d1 commit 5a93651
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 100 deletions.
38 changes: 19 additions & 19 deletions vcluster/_fragments/sync-from-host-configmap-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ You can find your contexts by running `kubectl config get-contexts`
:::


### Enable from host syncing for config map
### Enable from host syncing for ConfigMap

Enable the from host syncing for config maps in your virtual cluster configuration:
Enable the from host syncing for ConfigMap in your virtual cluster configuration:

```yaml title="Enable from host syncing for a config map"
```yaml title="Enable from host syncing for a ConfigMap"
sync:
fromHost:
configMaps:
Expand All @@ -49,20 +49,20 @@ sync:
This configuration:
- Enables from host syncing of the config map named `config` in the namespace `foobar2`.
- Automatically configures RBAC permissions for vCluster, so it can access this config map (you need to re-deploy vCluster for it to take place)
- Makes this config map accessible as `config` in the `my-namespace` in your vCluster.
- Enables from host syncing of the ConfigMap named `config` in the namespace `foobar2`.
- Automatically configures RBAC permissions for vCluster, so it can access this ConfigMap (you need to re-deploy vCluster for it to take place)
- Makes this ConfigMap accessible as `config` in the `my-namespace` in your vCluster.

:::tip create virtual cluster
Create or update a `virtual Cluster` following the [vCluster quick start
guide](/vcluster/#deploy-vcluster).
:::

### Sync config map to virtual and use it in pod
### Sync ConfigMap to virtual and use it in pod

<Flow id="config-maps-from-host-example">
<Step>
First, you create a config map that you want to sync in the host cluster:
First, you create a ConfigMap that you want to sync in the host cluster:

Copy this file and save it locally as `config.json`

Expand All @@ -73,30 +73,30 @@ guide](/vcluster/#deploy-vcluster).
}
```

then, create a config map containing this file in the host cluster:
then, create a ConfigMap containing this file in the host cluster:

```bash title="Create config map in the host"
```bash title="Create ConfigMap in the host"
kubectl --context="${HOST_CTX}" create configmap config \
--namespace=foobar2 \
--from-file=config.json=config.json
```
</Step>

#### Ensure that config map got synced to the vCluster
#### Ensure that ConfigMap got synced to the vCluster

Your config map should be now accessible in the virtual cluster.
Your ConfigMap should be now accessible in the virtual cluster.
Keep in mind, that any edit made in the virtual object is overwritten by the host object data.

<Step>
Check config map in the virtual cluster:
Check ConfigMap in the virtual cluster:

```bash title="Get synced config map"
```bash title="Get synced ConfigMap"
kubectl --context="${VCLUSTER_CTX}" get configmap --namespace my-namespace config -o yaml
```

you should see similar output:

```yaml title="config map contents"
```yaml title="ConfigMap contents"
apiVersion: v1
data:
config.json: |
Expand All @@ -120,7 +120,7 @@ guide](/vcluster/#deploy-vcluster).

<Step>

Now, your can create a new pod in the `my-namespace` namespace and specify this config map as a volume and mount it in the container.
Now, your can create a new pod in the `my-namespace` namespace and specify this ConfigMap as a volume and mount it in the container.

Save this pod locally to the file called `pod.yaml`:
```yaml title="pod.yaml"
Expand Down Expand Up @@ -166,7 +166,7 @@ guide](/vcluster/#deploy-vcluster).
```bash title="Check mounted file"
kubectl --context="${VCLUSTER_CTX}" exec -it --namespace my-virtual-namespace my-pod -- cat /tmp/config.json
```
you should see environment successfully injected from the config map:
you should see environment successfully injected from the ConfigMap:

```json title="Config from ConfigMap"
{
Expand All @@ -181,8 +181,8 @@ guide](/vcluster/#deploy-vcluster).
<Step>
#### Summary

From host config map syncing allow you to make specific config map(s) from host clusters accessible inside your virtual clusters. You can make them accessible from different namespaces and/or with different names in the virtual cluster.
They are always synced from host to the virtual, so it is also possible to sync one host config map to the multiple virtual ones.
From host ConfigMap syncing allow you to make specific ConfigMap(s) from host clusters accessible inside your virtual clusters. You can make them accessible from different namespaces and/or with different names in the virtual cluster.
They are always synced from host to the virtual, so it is also possible to sync one host ConfigMap to the multiple virtual ones.
They can also be used as a volume or env source in your workloads.

</Step>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Flow, { Step } from "@site/src/components/Flow";



## From host namespaced custom resource example
## From host namespaced CustomResource example

This guide shows how to sync k8s namespaced custom resources from host cluster.
This guide shows how to sync k8s namespaced CustomResources from host cluster.
Example CRD is used in this guide.

### Prerequisites
Expand Down Expand Up @@ -34,7 +34,7 @@ You can find your contexts by running `kubectl config get-contexts`
:::


### Create custom resource definition in the host
### Create CustomResourceDefinition in the host

Saved following Custom Resource Definition:

Expand Down Expand Up @@ -82,11 +82,11 @@ save this file locally and then apply it in the host cluster:
kubectl --context="${HOST_CTX}" create -f example-crd.yaml
```

### Enable from host syncing for your custom resource
### Enable from host syncing for your CustomResource

Enable the from host syncing for examples custom resources in your virtual cluster configuration:
Enable the from host syncing for Example CustomResources in your virtual cluster configuration:

```yaml title="Enable from host syncing for custom resource"
```yaml title="Enable from host syncing for CustomResource"
sync:
fromHost:
customResources:
Expand All @@ -109,7 +109,7 @@ Create or update a `virtual Cluster` following the [vCluster quick start
guide](/vcluster/#deploy-vcluster).
:::

### Sync namespaced custom resource to vCluster
### Sync namespaced CustomResource to vCluster

<Flow id="namespaced-custom-resources-from-host-example">
<Step>
Expand All @@ -135,15 +135,15 @@ guide](/vcluster/#deploy-vcluster).
```
</Step>

#### Ensure that custom resource got synced to vCluster
#### Ensure that CustomResource got synced to vCluster

Your custom resource should be now accessible in the virtual cluster.
Your CustomResource should be now accessible in the virtual cluster.
Keep in mind, that any edit made in the virtual object is overwritten by the host object data.

<Step>
Check custom resource in the virtual cluster:
Check CustomResource in the virtual cluster:

```bash title="Get synced custom resource"
```bash title="Get synced CustomResource"
kubectl --context="${VCLUSTER_CTX}" et examples.demo.loft.sh --namespace default
```

Expand All @@ -157,7 +157,7 @@ guide](/vcluster/#deploy-vcluster).

</Step>

#### Edit custom resource in the host
#### Edit CustomResource in the host

<Step>

Expand Down
40 changes: 20 additions & 20 deletions vcluster/_fragments/sync-from-host-secret-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Flow, { Step } from "@site/src/components/Flow";



## From host secret sync example
## From host Secret sync example

This guide shows how to sync Kubernetes secret from host clusters and how you can use them in your workload running inside virtual clusters.
This guide shows how to sync Kubernetes Secret from host clusters and how you can use them in your workload running inside virtual clusters.

### Prerequisites

Expand All @@ -35,11 +35,11 @@ You can find your contexts by running `kubectl config get-contexts`
:::


### Enable from host syncing for secret
### Enable from host syncing for Secret

Enable the from host syncing for secrets in your virtual cluster configuration:

```yaml title="Enable from host syncing for a secret"
```yaml title="Enable from host syncing for a Secret"
sync:
fromHost:
secrets:
Expand All @@ -51,44 +51,44 @@ sync:
This configuration:
- Enables from host syncing of the secret `shared-user-env` in the namespace `foobar`.
- Automatically configures RBAC permissions for vCluster, so it can access this secret (you need to re-deploy vCluster for it to take place)
- Makes this secret accessible as `user-env` in the `my-namespace` in your vCluster.
- Enables from host syncing of the Secret `shared-user-env` in the namespace `foobar`.
- Automatically configures RBAC permissions for vCluster, so it can access this Secret (you need to re-deploy vCluster for it to take place)
- Makes this Secret accessible as `user-env` in the `my-namespace` in your vCluster.

:::tip create virtual cluster
Create or update a `virtual Cluster` following the [vCluster quick start
guide](/vcluster/#deploy-vcluster).
:::

### Sync secret to virtual and use it in pod
### Sync Secret to virtual and use it in pod

<Flow id="secrets-from-host-example">
<Step>
First, create a secret which you want to sync in the host cluster:
First, create a Secret which you want to sync in the host cluster:

```bash title="Create secret in the host"
```bash title="Create Secret in the host"
kubectl --context="${HOST_CTX}" create secret generic shared-user-env \
--namespace=foobar \
--from-literal=MY_ENV_1=foo \
--from-literal=MY_ENV_2=bar
```
</Step>

#### Ensure that secret got synced to the vCluster
#### Ensure that Secret got synced to the vCluster

Your secret should be now accessible in the virtual cluster.
Your Secret should be now accessible in the virtual cluster.
Keep in mind, that any edit made in the virtual object is overwritten by the host object data.

<Step>
Check if the secret is accessible in the virtual cluster:
Check if the Secret is accessible in the virtual cluster:

```bash title="Get synced secret"
```bash title="Get synced Secret"
kubectl --context="${VCLUSTER_CTX}" get secrets --namespace my-namespace user-env -o yaml
```

you should see similar output:

```yaml title="secret contents"
```yaml title="Secret contents"
apiVersion: v1
data:
MY_ENV_1: Zm9v
Expand All @@ -110,7 +110,7 @@ guide](/vcluster/#deploy-vcluster).

<Step>

Now, you can create a new pod in the `my-namespace` namespace and specify this secret as a source for environment variables.
Now, you can create a new pod in the `my-namespace` namespace and specify this Secret as a source for environment variables.

Save this pod locally to the file called `pod.yaml`:
```yaml title="pod.yaml"
Expand Down Expand Up @@ -157,9 +157,9 @@ guide](/vcluster/#deploy-vcluster).
```bash title="Check environment variables"
kubectl --context="${VCLUSTER_CTX}" exec -it --namespace my-namespace my-pod -- printenv | grep "MY_ENV"
```
you should see environment successfully injected from the secret:
you should see environment successfully injected from the Secret:

```bash title="Environment variables from secret"
```bash title="Environment variables from Secret"
MY_ENV_1=foo
MY_ENV_2=bar
```
Expand All @@ -169,8 +169,8 @@ guide](/vcluster/#deploy-vcluster).
<Step>
#### Summary

From host secret syncing allow you to make specific secret(s) from host clusters accessible inside your virtual clusters. You can make them accessible from different namespaces and/or with different names in the virtual cluster.
They are always synced from host to the virtual, so it is also possible to sync one host secret to the multiple virtual ones.
From host Secret syncing allow you to make specific Secret(s) from host clusters accessible inside your virtual clusters. You can make them accessible from different namespaces and/or with different names in the virtual cluster.
They are always synced from host to the virtual, so it is also possible to sync one host Secret to the multiple virtual ones.
They can also be used as a volume or env source in your workloads.

</Step>
Expand Down
37 changes: 23 additions & 14 deletions vcluster/configure/vcluster-yaml/sync/from-host/configmaps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,34 @@ import FromHostConfigMapExample from '../../../../_fragments/sync-from-host-conf
By default, this is turned off.

:::info No need to configure RBAC
vCluster automatically adds the required cluster RBAC permissions for retrieving the config maps and syncing the resources from the host to the virtual cluster.
vCluster automatically adds the required cluster RBAC permissions for retrieving the ConfigMaps and syncing the resources from the host to the virtual cluster.
:::

Enabling this allows you to sync ConfigMaps from the specified namespaces in the host to the specified namespaces in the vCluster.
```yaml title="vcluster.yaml"
sync:
fromHost:
configMaps:
enabled: true
selector:
mappings:
# syncs all ConfigMaps from "foo" namespace
# to the "bar" namespace in vCluster. ConfigMaps names are unchanged.
"foo/*": "bar/*"
```
It is also possible to modify the name of the synced resource in the virtual cluster.

There is no option to sync from all namespaces in the host.

Sync is one-directional, from host to virtual. If you modify an object in the host, vCluster syncs the change to virtual object. When you delete a virtual object, vCluster re-creates it if the host object still exist.
When you delete a host object, vCluster deletes the corresponding virtual object.
- It is also possible to modify the name of the synced resource in the virtual cluster.
- There is no option to sync from all namespaces in the host.
- Sync is one-directional, from host to virtual. If you modify an object in the host, vCluster syncs the change to virtual object.
- When you delete a virtual object, vCluster re-creates it if the host object still exist.
- When you delete a host object, vCluster deletes the corresponding virtual object.
Namespaces in the virtual cluster are created automatically during the sync (if they do not exist already).
It is not possible to sync ConfigMaps that were already synced from virtual to host, they are skipped by vCluster.
:::info kube-root-ca configmap is skipped
:::info kube-root-ca ConfigMap is skipped
ConfigMaps named `kube-root-ca.crt` are skipped in the from host sync (even if they match the mappings specified in `vcluster.yaml`).
:::

Expand All @@ -39,7 +49,7 @@ You can use synced ConfigMaps in your workloads as an environment variables sour
All the specified namespaces have to exist in the host at the vCluster startup.


## Sync all config maps from host namespace
## Sync all ConfigMaps from host namespace
To sync all ConfigMaps from a given namespace in the host to the given namespace in the virtual cluster, “namespace/*” wildcard can be used, e.g.:

```yaml
Expand All @@ -54,7 +64,7 @@ sync:
"foo/*": "bar/*"
```

## Sync only specific config maps from host namespace
## Sync only specific ConfigMaps from host namespace
To sync only specific ConfigMaps from namespaces, you need to provide `namespace/name` as the key and value:

```yaml
Expand All @@ -69,7 +79,7 @@ sync:
"foo/cm-name": "bar/cm-name"
```

## Sync all config maps from vCluster's host namespace
## Sync all ConfigMaps from vCluster's host namespace
There is also a handy syntax to sync all ConfigMaps from vCluster’s own host namespace to the virtual namespace. As vCluster’s namespace is not always known upfront (e.g. when vCluster is created by the platform), `""` (empty string) is treated as “vCluster’s own host namespace”.

```yaml
Expand All @@ -84,7 +94,7 @@ sync:
"": "my-virtual"
```

## Sync specific config map from vCluster's host namespace
## Sync specific ConfigMap from vCluster's host namespace
you can also specify only a few ConfigMaps from vCluster’s own host namespace this way:

```yaml
Expand All @@ -99,7 +109,7 @@ sync:
"/my-cm": "my-virtual/my-cm"
```

## Modify synced config map namespace and name in the virtual cluster
## Modify synced ConfigMap namespace and name in the virtual cluster
It’s also possible to modify ConfigMap name during the sync:

```yaml
Expand Down Expand Up @@ -136,7 +146,6 @@ sync:
"default/my-cm": "barfoo2/cm-my"
patches:
- path: metadata.annotations[*]
#expression: '"my-prefix-"+value'
# optional reverseExpression to reverse the change from the host cluster
reverseExpression: "value.startsWith('www.') ? value.slice(4) : value"
```
Expand Down
Loading

0 comments on commit 5a93651

Please sign in to comment.