ko build --local --platform=linux/$ARCH ./cmd/syncer
Install CLI Plugin (kcp workload edge-sync)
Clone https://github.com/yana1205/kcp and switch branch to emc
Make
The new plugin to generate bootstrap manifests for edge-syncer
$ kubectl kcp workload -h
Manages KCP sync targets
Usage:
kcp workload [flags]
kcp workload [command]
Aliases:
workload, workloads
Available Commands:
cordon Mark sync target as unschedulable
drain Start draining sync target in preparation for maintenance
edge-sync Create a synctarget for Edge MC in kcp with service account and RBAC permissions. Output a manifest to deploy a syncer for the given sync target in a physical cluster.
sync Create a synctarget in kcp with service account and RBAC permissions. Output a manifest to deploy a syncer for the given sync target in a physical cluster.
...
Edge Syncer feasibility verification
Register an edge-syncer on a p-cluster to connect a mailbox workspace specified by name
$ kubectl get Workspace
NAME TYPE REGION PHASE URL AGE
1lkhy98o1f84q2a3-mb-861789a8-5867-402d-9fc4-06f0cc81fe1b universal Ready https://192.168.10.105:6443/clusters/root:edge:1lkhy98o1f84q2a3-mb-861789a8-5867-402d-9fc4-06f0cc81fe1b 21s
Enter the mailbox workspace
$ kubectl kcp ws 1lkhy98o1f84q2a3-mb-861789a8-5867-402d-9fc4-06f0cc81fe1b
Current workspace is "root:edge:1lkhy98o1f84q2a3-mb-861789a8-5867-402d-9fc4-06f0cc81fe1b" (type root:universal).
Run edge-syncer registration command
$ kubectl kcp workload edge-sync pcluster1 --syncer-image $EMC_SYNCER_IMAGE -o /tmp/edge-syncer.yaml
Creating service account "kcp-edge-syncer-pcluster1-1na3tqcd"
Creating cluster role "kcp-edge-syncer-pcluster1-1na3tqcd" to give service account "kcp-edge-syncer-pcluster1-1na3tqcd"
1. write and sync access to the synctarget "kcp-edge-syncer-pcluster1-1na3tqcd"
2. write access to apiresourceimports.
Creating or updating cluster role binding "kcp-edge-syncer-pcluster1-1na3tqcd" to bind service account "kcp-edge-syncer-pcluster1-1na3tqcd" to cluster role "kcp-edge-syncer-pcluster1-1na3tqcd".
Wrote physical cluster manifest to /tmp/edge-syncer.yaml for namespace "kcp-edge-syncer-pcluster1-1na3tqcd". Use
KUBECONFIG=<pcluster-config> kubectl apply -f "/tmp/edge-syncer.yaml"
to apply it. Use
KUBECONFIG=<pcluster-config> kubectl get deployment -n "kcp-edge-syncer-pcluster1-1na3tqcd" kcp-edge-syncer-pcluster1-1na3tqcd
to verify the syncer pod is running.
Deploy the generated bootstrap manifest (/tmp/edge-syncer.yaml) in a p-cluster
$ KUBECONFIG=/tmp/kind-pcluster1/kubeconfig.yaml kubectl apply -f /tmp/edge-syncer.yaml
namespace/kcp-edge-syncer-pcluster1-1na3tqcd created
serviceaccount/kcp-edge-syncer-pcluster1-1na3tqcd created
secret/kcp-edge-syncer-pcluster1-1na3tqcd-token created
clusterrole.rbac.authorization.k8s.io/kcp-edge-syncer-pcluster1-1na3tqcd created
clusterrolebinding.rbac.authorization.k8s.io/kcp-edge-syncer-pcluster1-1na3tqcd created
role.rbac.authorization.k8s.io/kcp-edge-dns-pcluster1-1na3tqcd created
rolebinding.rbac.authorization.k8s.io/kcp-edge-dns-pcluster1-1na3tqcd created
secret/kcp-edge-syncer-pcluster1-1na3tqcd created
deployment.apps/kcp-edge-syncer-pcluster1-1na3tqcd created
Edge Syncer successfully runs and interact with the emailbox workspace
$ KUBECONFIG=/tmp/kind-pcluster1/kubeconfig.yaml kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kcp-edge-syncer-pcluster1-1na3tqcd kcp-edge-syncer-pcluster1-1na3tqcd-7467d4bf7f-7rqnt 1/1 Running 0 31s
...
The namespace from-ws-to-pcluster is successfully downsynced
$ KUBECONFIG=/tmp/kind-pcluster1/kubeconfig.yaml kubectl get ns
NAME STATUS AGE
default Active 13m
from-ws-to-pcluster Active 1s
kcp-edge-syncer-pcluster1-1na3tqcd Active 11m
kube-node-lease Active 13m
kube-public Active 13m
kube-system Active 13m
local-path-storage Active 13m
Deploy Kyverno and its policy from mailbox workspace to p-cluster just by using manifests (generated from Kyverno helm chart) rather than using OLM.
Update EdgeSyncConfig with required resources for Helm install of Kyverno yaml
$ KUBECONFIG=/tmp/kind-pcluster1/kubeconfig.yaml kubectl get pod -n kyverno
NAME READY STATUS RESTARTS AGE
kyverno-9c494576b-dgpjt 1/1 Running 0 78s
Create a sample policy in the mailbox workspace to downsync
$ kubectl apply -f /tmp/kyverno/sample-policy.yaml
policy.kyverno.io/sample-policy created
The policy is distributed to pcluster and the generated policy report is upsynced
On the pcluster
$ KUBECONFIG=/tmp/kind-pcluster1/kubeconfig.yaml kubectl get policy,policyreport
NAME BACKGROUND VALIDATE ACTION READY
policy.kyverno.io/sample-policy true enforce true
NAME PASS FAIL WARN ERROR SKIP AGE
policyreport.wgpolicyk8s.io/pol-sample-policy 0 1 0 0 0 56s
On the emailbox workspace
```
$ kubectl get policy,policyreport
NAME BACKGROUND VALIDATE ACTION READY
policy.kyverno.io/sample-policy true enforce true
NAME PASS FAIL WARN ERROR SKIP AGE
policyreport.wgpolicyk8s.io/pol-sample-policy 0 1 0 0 0 77s
```
See policy reports generated at p-cluster via API Export on workload management workspace.
In the previous case, PolicyReport CRD is deployed as a CRD. In order to share the API across workspaces, we define PolicyReport API as APIBiinding
Go to workload management workspace (edge)
$ kubectl kcp ws root:edge
Current workspace is "root:edge".
Create APIResourceSchema and APIExport for PolicyReport CRD
$ kubectl apply -f /tmp/kyverno/apischema.policyreports.yaml /tmp/kyverno/apiexport.policyreports.yaml
apiresourceschema.apis.kcp.io/v0-0-1.policyreports.wgpolicyk8s.io created
apiexport.apis.kcp.io/policy-report created
Denature PolicyReport CRD in Kyverno Helm chart by replacing following field's value in CustomResourceDefinition for policyreports resource definition:
Replace metadata.name: policyreports.wgpolicyk8s.io with metadata.name: policyreports.wgpolicyk8s.io.denatured
Replace spec.group: wgpolicyk8s.io with spec.group: wgpolicyk8s.io.denatured