Propagate dependencies

Deployment, Job, Pod, DaemonSet and StatefulSet dependencies (ConfigMaps and Secrets) can be propagated to member clusters automatically. This document demonstrates how to use this feature. For more design details, please refer to dependencies-automatically-propagation

Prerequisites

Karmada has been installed

We can install Karmada by referring to quick-start, or directly run hack/local-up-karmada.sh script which is also used to run our E2E cases.

Enable PropagateDeps feature

PropagateDeps feature gate has evolved to the Beta sine Karmada v1.4 and is enabled by default. If you use the Karmada 1.3 or earlier, you need to enable this feature gate.

  1. kubectl edit deployment karmada-controller-manager -n karmada-system

Add --feature-gates=PropagateDeps=true option.

Example

Create a Deployment mounted with a ConfigMap

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: my-nginx
  5. labels:
  6. app: my-nginx
  7. spec:
  8. replicas: 2
  9. selector:
  10. matchLabels:
  11. app: my-nginx
  12. template:
  13. metadata:
  14. labels:
  15. app: my-nginx
  16. spec:
  17. containers:
  18. - image: nginx
  19. name: my-nginx
  20. ports:
  21. - containerPort: 80
  22. volumeMounts:
  23. - name: configmap
  24. mountPath: "/configmap"
  25. volumes:
  26. - name: configmap
  27. configMap:
  28. name: my-nginx-config
  29. ---
  30. apiVersion: v1
  31. kind: ConfigMap
  32. metadata:
  33. name: my-nginx-config
  34. data:
  35. nginx.properties: |
  36. proxy-connect-timeout: "10s"
  37. proxy-read-timeout: "10s"
  38. client-max-body-size: "2m"

Create a propagation policy with this Deployment and set propagateDeps: true.

  1. apiVersion: policy.karmada.io/v1alpha1
  2. kind: PropagationPolicy
  3. metadata:
  4. name: my-nginx-propagation
  5. spec:
  6. propagateDeps: true
  7. resourceSelectors:
  8. - apiVersion: apps/v1
  9. kind: Deployment
  10. name: my-nginx
  11. placement:
  12. clusterAffinity:
  13. clusterNames:
  14. - member1
  15. - member2
  16. replicaScheduling:
  17. replicaDivisionPreference: Weighted
  18. replicaSchedulingType: Divided
  19. weightPreference:
  20. staticWeightList:
  21. - targetCluster:
  22. clusterNames:
  23. - member1
  24. weight: 1
  25. - targetCluster:
  26. clusterNames:
  27. - member2
  28. weight: 1

Upon successful policy execution, the Deployment and ConfigMap are properly propagated to the member cluster.

  1. $ kubectl --kubeconfig /etc/karmada/karmada-apiserver.config get propagationpolicy
  2. NAME AGE
  3. my-nginx-propagation 16s
  4. $ kubectl --kubeconfig /etc/karmada/karmada-apiserver.config get deployment
  5. NAME READY UP-TO-DATE AVAILABLE AGE
  6. my-nginx 2/2 2 2 22m
  7. # member cluster1
  8. $ kubectl config use-context member1
  9. Switched to context "member1".
  10. $ kubectl get deployment
  11. NAME READY UP-TO-DATE AVAILABLE AGE
  12. my-nginx 1/1 1 1 25m
  13. $ kubectl get configmap
  14. NAME DATA AGE
  15. my-nginx-config 1 26m
  16. # member cluster2
  17. $ kubectl config use-context member2
  18. Switched to context "member2".
  19. $ kubectl get deployment
  20. NAME READY UP-TO-DATE AVAILABLE AGE
  21. my-nginx 1/1 1 1 27m
  22. $ kubectl get configmap
  23. NAME DATA AGE
  24. my-nginx-config 1 27m