|
1 | 1 | # Getting Started with the Sync Agent
|
2 | 2 |
|
3 | 3 | All that is necessary to run the Sync Agent is a running Kubernetes cluster (for testing you can use
|
4 |
| -[kind][kind]) [kcp][kcp] installation. |
| 4 | +[kind][kind]) and a [kcp][kcp] installation. |
5 | 5 |
|
6 | 6 | ## Prerequisites
|
7 | 7 |
|
@@ -31,7 +31,7 @@ of your choice:
|
31 | 31 | # use the kcp kubeconfig
|
32 | 32 | $ export KUBECONFIG=/path/to/kcp.kubeconfig
|
33 | 33 |
|
34 |
| -# nativagate to the workspace wher the APIExport should exist |
| 34 | +# nativagate to the workspace where the APIExport should exist |
35 | 35 | $ kubectl ws :workspace:you:want:to:create:it
|
36 | 36 |
|
37 | 37 | # create it
|
@@ -59,74 +59,153 @@ $ kubectl create secret generic kcp-kubeconfig \
|
59 | 59 | --from-file "kubeconfig=admin.kubeconfig"
|
60 | 60 | ```
|
61 | 61 |
|
| 62 | +### Helm Chart Setup |
| 63 | + |
62 | 64 | The Sync Agent is shipped as a Helm chart and to install it, the next step is preparing a `values.yaml`
|
63 | 65 | file for the Sync Agent Helm chart. We need to pass the target `APIExport`, a name for the Sync Agent
|
64 | 66 | itself and a reference to the kubeconfig secret we just created.
|
65 | 67 |
|
66 | 68 | ```yaml
|
67 |
| -syncAgent: |
68 |
| - # Required: the name of the APIExport in kcp that this Sync Agent is supposed to serve. |
69 |
| - apiExportName: test.example.com |
70 |
| - |
71 |
| - # Required: this Sync Agent's public name, will be shown in kcp, purely for informational purposes. |
72 |
| - agentName: unique-test |
73 |
| - |
74 |
| - # Required: Name of the Kubernetes Secret that contains a "kubeconfig" key, with the kubeconfig |
75 |
| - # provided by kcp to access it. |
76 |
| - kcpKubeconfig: kcp-kubeconfig |
77 |
| - |
78 |
| - # Create additional RBAC on the service cluster. These rules depend somewhat on the Sync Agent |
79 |
| - # configuration, but the following two rules are very common. If you configure the Sync Agent to |
80 |
| - # only work with cluster-scoped objects, you do not need to grant it permissions to create |
81 |
| - # namespaces, for example. |
82 |
| - rbac: |
83 |
| - createClusterRole: true |
84 |
| - rules: |
85 |
| - # in order to create APIResourceSchemas |
86 |
| - - apiGroups: |
87 |
| - - apiextensions.k8s.io |
88 |
| - resources: |
89 |
| - - customresourcedefinitions |
90 |
| - verbs: |
91 |
| - - get |
92 |
| - - list |
93 |
| - - watch |
94 |
| - # so copies of remote objects can be placed in their target namespaces |
95 |
| - - apiGroups: |
96 |
| - - "" |
97 |
| - resources: |
98 |
| - - namespaces |
99 |
| - verbs: |
100 |
| - - get |
101 |
| - - list |
102 |
| - - watch |
103 |
| - - create |
104 |
| -``` |
| 69 | +# Required: the name of the APIExport in kcp that this Sync Agent is supposed to serve. |
| 70 | +apiExportName: test.example.com |
105 | 71 |
|
106 |
| -In addition, it is important to create RBAC rules for the resources you want to publish. If you want |
107 |
| -to publish the `Certificate` resource as created by cert-manager, you will need to append the |
108 |
| -following ruleset: |
| 72 | +# Required: This Agent's public name, purely for informational purposes. |
| 73 | +# If not set, defaults to the Helm release name. |
| 74 | +agentName: unique-test |
109 | 75 |
|
110 |
| -```yaml |
111 |
| - # so we can manage certificates |
112 |
| - - apiGroups: |
113 |
| - - cert-manager.io |
114 |
| - resources: |
115 |
| - - certificates |
116 |
| - verbs: |
117 |
| - - '*' |
| 76 | +# Required: Name of the Kubernetes Secret that contains a "kubeconfig" key, |
| 77 | +# with the kubeconfig provided by kcp to access it. |
| 78 | +kcpKubeconfig: kcp-kubeconfig |
118 | 79 | ```
|
119 | 80 |
|
120 | 81 | Once this `values.yaml` file is prepared, install a recent development build of the Sync Agent:
|
121 | 82 |
|
122 | 83 | ```sh
|
123 |
| -helm install kcp-api-syncagent oci://github.com/kcp-dev/helm-charts/api-syncagent --version 9.9.9-9fc9a430d95f95f4b2210f91ef67b3ec153b5cab -f values.yaml -n kcp-system |
| 84 | +helm repo add kcp https://kcp-dev.github.io/helm-charts |
| 85 | +helm repo update |
| 86 | +
|
| 87 | +helm install kcp-api-syncagent kcp/api-syncagent \ |
| 88 | + --values values.yaml \ |
| 89 | + --namespace kcp-system |
124 | 90 | ```
|
125 | 91 |
|
126 | 92 | Two `kcp-api-syncagent` Pods should start in the `kcp-system` namespace. If they crash you will need to
|
127 | 93 | identify the reason from container logs. A possible issue is that the provided kubeconfig does not
|
128 | 94 | have permissions against the target kcp workspace.
|
129 | 95 |
|
| 96 | +### Service Cluster RBAC |
| 97 | + |
| 98 | +The Sync Agent usually requires additional RBAC on the service cluster to function properly. The |
| 99 | +Helm chart will automatically allow it to read CRDs, namespaces and Secrets, but depending on how |
| 100 | +you configure your PublishedResources, additional permissions need to be created. |
| 101 | + |
| 102 | +For example, if the Sync Agent is meant to create `Certificate` objects (defined by cert-manager), |
| 103 | +you would need to grant it permissions on those: |
| 104 | + |
| 105 | +```yaml |
| 106 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 107 | +kind: ClusterRole |
| 108 | +metadata: |
| 109 | + name: 'api-syncagent:unique-test' |
| 110 | +rules: |
| 111 | + - apiGroups: |
| 112 | + - cert-manager.io |
| 113 | + resources: |
| 114 | + - certificates |
| 115 | + verbs: |
| 116 | + - get |
| 117 | + - list |
| 118 | + - watch |
| 119 | + - create |
| 120 | + - update |
| 121 | +
|
| 122 | +--- |
| 123 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 124 | +kind: ClusterRoleBinding |
| 125 | +metadata: |
| 126 | + name: 'api-syncagent:unique-test' |
| 127 | +roleRef: |
| 128 | + apiGroup: rbac.authorization.k8s.io |
| 129 | + kind: ClusterRole |
| 130 | + name: 'api-syncagent:unique-test' |
| 131 | +subjects: |
| 132 | + - kind: ServiceAccount |
| 133 | + name: 'kcp-api-syncagent' |
| 134 | + namespace: kcp-system |
| 135 | +``` |
| 136 | + |
| 137 | +**NB:** Even though the PublishedResources might only create/update Certificates in a single namespace, |
| 138 | +due to the inner workings of the Agent they will still be watched (cached) cluster-wide. So you can |
| 139 | +tighten permissions on `create`/`update` operations to certain namespaces, but `watch` permissions |
| 140 | +need to be granted cluster-wide. |
| 141 | + |
| 142 | +### kcp RBAC |
| 143 | + |
| 144 | +The Helm chart is installed on the service cluster and so cannot provision the necessary RBAC for |
| 145 | +the Sync Agent within kcp. Usually whoever creates the `APIExport` is also responsible for creating |
| 146 | +the RBAC rules that grant the Agent access. |
| 147 | + |
| 148 | +The Sync Agent needs to |
| 149 | + |
| 150 | +* manage its `APIExport`, |
| 151 | +* manage `APIResourceSchemas` and |
| 152 | +* access the virtual workspace for its `APIExport`. |
| 153 | + |
| 154 | +This can be achieved by applying RBAC like this _in the workspace where the `APIExport` resides_: |
| 155 | + |
| 156 | +```yaml |
| 157 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 158 | +kind: ClusterRole |
| 159 | +metadata: |
| 160 | + name: api-syncagent-mango |
| 161 | +rules: |
| 162 | + # manage its APIExport |
| 163 | + - apiGroups: |
| 164 | + - apis.kcp.io |
| 165 | + resources: |
| 166 | + - apiexports |
| 167 | + resourceNames: |
| 168 | + - test.example.com |
| 169 | + verbs: |
| 170 | + - get |
| 171 | + - list |
| 172 | + - watch |
| 173 | + - patch |
| 174 | + - update |
| 175 | + # manage APIResourceSchemas |
| 176 | + - apiGroups: |
| 177 | + - apis.kcp.io |
| 178 | + resources: |
| 179 | + - apiresourceschemas |
| 180 | + verbs: |
| 181 | + - get |
| 182 | + - list |
| 183 | + - watch |
| 184 | + - create |
| 185 | + # access the virtual workspace |
| 186 | + - apiGroups: |
| 187 | + - apis.kcp.io |
| 188 | + resources: |
| 189 | + - apiexports/content |
| 190 | + resourceNames: |
| 191 | + - test.example.com |
| 192 | + verbs: |
| 193 | + - '*' |
| 194 | +
|
| 195 | +--- |
| 196 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 197 | +kind: ClusterRoleBinding |
| 198 | +metadata: |
| 199 | + name: api-syncagent-columbo:mango-system |
| 200 | +roleRef: |
| 201 | + apiGroup: rbac.authorization.k8s.io |
| 202 | + kind: ClusterRole |
| 203 | + name: api-syncagent-mango |
| 204 | +subjects: |
| 205 | + - kind: User |
| 206 | + name: api-syncagent-mango |
| 207 | +``` |
| 208 | + |
130 | 209 | ## Publish Resources
|
131 | 210 |
|
132 | 211 | Once the Sync Agent Pods are up and running, you should be able to follow the
|
|
0 commit comments