Skip to content

Commit 463154b

Browse files
add the introduction of configuring clientConfig to the resource intrepreter webhook
Signed-off-by: changzhen <[email protected]>
1 parent 8d89d77 commit 463154b

File tree

1 file changed

+100
-16
lines changed

1 file changed

+100
-16
lines changed

Diff for: examples/customresourceinterpreter/README.md

+100-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
1-
# Examples
1+
# Resource Interpreter Webhook
22

3-
## Resource Interpreter
3+
This document uses an example of a resource interpreter webhook to show users its usage. In the example, we process a CustomResourceDefinition(CRD) resource named `Workload`. Users can implement their own resource interpreter webhook component based on their own business, taking `karmada-interpreter-webhook-example` as an example.
44

5-
This example installs a CustomResourceDefinition(CRD), `Workload` in the `karmada-apiserver`, and deploys a deployment `karmada-interpreter-webhook-example` in the Karmada host.
5+
## Document introduction
66

7-
### Install
7+
```
8+
examples/customresourceinterpreter/
9+
10+
├── apis/ # API Definition
11+
│ ├── workload/ # `Workload` API Definition
12+
│ │ ├── v1alpha1 # `Workload` v1alpha1 version API Definition
13+
│ │ | ├── doc.go # API Package Introduction
14+
│ │ | ├── workload_types.go # example `Workload` API Definition
15+
│ │ | ├── zz_generated.deepcopy.go # generated by `deepcopy-gen`
16+
| | | └── zz_generated.register.go # generated by `register-gen`
17+
│ └── └── workload.example.io_workloads.yaml # `Workload` CustomResourceDefinition, generated by `controller-gen crd`
18+
19+
├── webhook/ # demo for `karmada-interpreter-webhook-example` component
20+
21+
├── karmada-interpreter-webhook-example.yaml # component deployment configuration file
22+
├── README.md # README file
23+
├── webhook-configuration.yaml # ResourceInterpreterWebhookConfiguration configuration file
24+
├── workload.yaml # `Workload` resource example
25+
└── workload-propagationpolicy.yaml # `PropagationPolicy` resource example to propagate `Workload` resource
26+
```
827

9-
### Prerequisites
28+
## Install
1029

11-
For Karmada deploy using `hack/local-up-karmada.sh`, there are `karmada-host`, `karmada-apiserver` and three member clusters named `member1`, `member2` and `member3`.
30+
For a Karmada instance, the cluster where the Karmada component is deployed is called `karmada-host` cluster.
31+
32+
This document uses the Karmada instance installed in `hack/local-up-karmada.sh` mode as an example, there are `karmada-host`, `karmada-apiserver` and three member clusters named `member1`, `member2` and `member3`.
1233

1334
> Note: If you use other installation methods, please adapt your installation method proactively.
1435
15-
In the current example, we will deploy `karmada-interpreter-webhook-example` in the Karmada control plane. Since it involves a cluster with Pull mode, the initiator of resource interpreter requests is in `karmada-agent`. Therefore, we create a Service of type `LoadBalancer` for `karmada-interpreter-webhook-example`.
36+
### Prerequisites
37+
38+
Considering that there is a `Pull` type cluster in the cluster, it is necessary to set up a LoadBalancer type Service for `karmada-interpreter-webhook-example` so that all clusters can access the resource interpreter webhook service. In this document, we deploy `MetalLB` to expose the webhook service.
1639

17-
So we need to deploy MetalLB as a Load Balancer to expose the webhook. Please run the following script to deploy MetalLB.
40+
If all your clusters are `Push` type clusters, you can access the webhook service in the `karmada-host` cluster through `Service` without configuring additional `MetalLB`.
41+
42+
Please run the following script to deploy `MetalLB`.
1843

1944
```bash
2045
kubectl --context="karmada-host" get configmap kube-proxy -n kube-system -o yaml | \
@@ -49,15 +74,17 @@ metadata:
4974
EOF
5075
```
5176

52-
#### Step1: Install `Workload` CRD in `karmada-apiserver` and member clusters
77+
### Deploy karmada-interpreter-webhook-example
78+
79+
#### Step1: Install `Workload` CRD
5380

54-
Install CRD in `karmada-apiserver` by running the following command:
81+
Install `Workload` CRD in `karmada-apiserver` by running the following command:
5582

5683
```bash
5784
kubectl --kubeconfig $HOME/.kube/karmada.config --context karmada-apiserver apply -f examples/customresourceinterpreter/apis/workload.example.io_workloads.yaml
5885
```
5986

60-
Create a `ClusterPropagationPolicy` resource object to propagate `Workload` CRD to member clusters:
87+
And then, create a `ClusterPropagationPolicy` resource object to propagate `Workload` CRD to all member clusters:
6188

6289
<details>
6390

@@ -86,9 +113,63 @@ spec:
86113
kubectl --kubeconfig $HOME/.kube/karmada.config --context karmada-apiserver apply -f workload-crd-cpp.yaml
87114
```
88115

89-
#### Step2: Deploy webhook configuration in karmada-apiserver
116+
#### Step2: Deploy webhook configuration in `karmada-apiserver`
117+
118+
We can tell Karmada how to access the resource interpreter webhook service by configuring `ResourceInterpreterWebhookConfiguration`. The configuration template is as follows:
119+
120+
```yaml
121+
apiVersion: config.karmada.io/v1alpha1
122+
kind: ResourceInterpreterWebhookConfiguration
123+
metadata:
124+
name: examples
125+
webhooks:
126+
- name: workloads.example.com
127+
rules:
128+
- operations: [ "InterpretReplica","ReviseReplica","Retain","AggregateStatus", "InterpretHealth", "InterpretStatus", "InterpretDependency" ]
129+
apiGroups: [ "workload.example.io" ]
130+
apiVersions: [ "v1alpha1" ]
131+
kinds: [ "Workload" ]
132+
clientConfig:
133+
url: https://{{karmada-interpreter-webhook-example-svc-address}}:443/interpreter-workload
134+
caBundle: {{caBundle}}
135+
interpreterContextVersions: [ "v1alpha1" ]
136+
timeoutSeconds: 3
137+
```
138+
139+
If you only need to access the resource interpreter webhook service in the `Karmada-host` cluster, you can directly configure `clientConfig` with the Service domain name in the cluster:
140+
141+
```yaml
142+
clientConfig:
143+
url: https://karmada-interpreter-webhook-example.karmada-system.svc:443/interpreter-workload
144+
caBundle: {{caBundle}}
145+
```
146+
147+
Alternatively, you can also define service in clientConfig, which requires you to deploy a Service of type ExternalName in `Karmada-apiserver`:
148+
149+
```yaml
150+
clientConfig:
151+
caBundle: {{caBundle}}
152+
service:
153+
namespace: karmada-system
154+
name: karmada-interpreter-webhook-example
155+
port: 443
156+
path: /interpreter-workload
157+
```
158+
159+
Deploy the Service in `karmada-apiserver`.
90160

91-
Execute below script:
161+
```yaml
162+
apiVersion: v1
163+
kind: Service
164+
metadata:
165+
name: karmada-interpreter-webhook-example
166+
namespace: karmada-system
167+
spec:
168+
type: ExternalName
169+
externalName: karmada-interpreter-webhook-example.karmada-system.svc.cluster.local
170+
```
171+
172+
In the example of this article, you can directly run the following script to deploy ResourceInterpreterWebhookConfiguration:
92173

93174
<details>
94175

@@ -114,17 +195,18 @@ rm -rf "${temp_path}"
114195

115196
```bash
116197
chmod +x webhook-configuration.sh
117-
118198
./webhook-configuration.sh
119199
```
120200

121-
#### Step3: Deploy karmada-interpreter-webhook-example in karmada-host
201+
#### Step3: Deploy `karmada-interpreter-webhook-example` in karmada-host
202+
203+
Run the following command:
122204

123205
```bash
124206
kubectl --kubeconfig $HOME/.kube/karmada.config --context karmada-host apply -f examples/customresourceinterpreter/karmada-interpreter-webhook-example.yaml
125207
```
126208

127-
> Note: karmada-interpreter-webhook-example is just a demo for testing and reference. If you plan to use the interpreter webhook, please implement specific components based on your business needs.
209+
> Note: `karmada-interpreter-webhook-example` is just a demo for testing and reference. If you plan to use the interpreter webhook, please implement specific components based on your business needs.
128210

129211
In the current example, the interpreter webhook is deployed under the namespace `karmada-system`. If you are trying to deploy the interpreter webhook in a namespace other than the default karmada-system namespace, and use the domain address of Service in the URL. Such as (take the `test` namespace as an example):
130212

@@ -157,6 +239,8 @@ We recommend that you deploy the interpreter webhook component and Karmada contr
157239

158240
The relevant problem description has been recorded in [#4478](https://github.com/karmada-io/karmada/issues/4478), please refer to it.
159241

242+
At this point, you have successfully installed the `karmada-interpreter-webhook-example` service and can start using it.
243+
160244
### Usage
161245

162246
Create a `Workload` resource and propagate it to the member clusters:

0 commit comments

Comments
 (0)