Deploy apiserver-network-proxy (ANP) For Pull mode

Purpose

For a member cluster that joins Karmada in the pull mode, you need to provide a method to connect the network between the Karmada control plane and the member cluster, so that karmada-aggregated-apiserver can access this member cluster.

Deploying ANP to achieve this is one of the methods. This document describes how to deploy ANP for Karmada.

Environment

Karmada can be deployed using the kind tool.

You can directly use hack/local-up-karmada.sh to deploy Karmada.

Actions

Step 1: Download code

To facilitate demonstration, the code is modified based on ANP v0.0.24 to support access to the front server through HTTP. Here is the code repository address: https://github.com/mrlihanbo/apiserver-network-proxy/tree/v0.0.24/dev.

  1. git clone -b v0.0.24/dev https://github.com/mrlihanbo/apiserver-network-proxy.git
  2. cd apiserver-network-proxy/

Step 2: Build images

Build the proxy-server and proxy-agent images.

  1. docker build . --build-arg ARCH=amd64 -f artifacts/images/agent-build.Dockerfile -t swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-agent:0.0.24
  2. docker build . --build-arg ARCH=amd64 -f artifacts/images/server-build.Dockerfile -t swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-server:0.0.24

Step 3: Generate certificates

Run the command to check the IP address of karmada-host:

  1. docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' karmada-host-control-plane

Run the make certs command to generate certificates and specify PROXY_SERVER_IP as the IP address obtained in the preceding command.

  1. make certs PROXY_SERVER_IP=x.x.x.x

The certificates are generated in the certs folder.

Step 4: Deploy proxy-server

Save the proxy-server.yaml file in the root directory of the ANP code repository.

unfold me to see the yaml

  1. # proxy-server.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: proxy-server
  6. namespace: karmada-system
  7. spec:
  8. replicas: 1
  9. selector:
  10. matchLabels:
  11. app: proxy-server
  12. template:
  13. metadata:
  14. labels:
  15. app: proxy-server
  16. spec:
  17. containers:
  18. - command:
  19. - /proxy-server
  20. args:
  21. - --health-port=8092
  22. - --cluster-ca-cert=/var/certs/server/cluster-ca-cert.crt
  23. - --cluster-cert=/var/certs/server/cluster-cert.crt
  24. - --cluster-key=/var/certs/server/cluster-key.key
  25. - --mode=http-connect
  26. - --proxy-strategies=destHost
  27. - --server-ca-cert=/var/certs/server/server-ca-cert.crt
  28. - --server-cert=/var/certs/server/server-cert.crt
  29. - --server-key=/var/certs/server/server-key.key
  30. image: swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-server:0.0.24
  31. imagePullPolicy: IfNotPresent
  32. livenessProbe:
  33. failureThreshold: 3
  34. httpGet:
  35. path: /healthz
  36. port: 8092
  37. scheme: HTTP
  38. initialDelaySeconds: 10
  39. periodSeconds: 10
  40. successThreshold: 1
  41. timeoutSeconds: 60
  42. name: proxy-server
  43. volumeMounts:
  44. - mountPath: /var/certs/server
  45. name: cert
  46. restartPolicy: Always
  47. hostNetwork: true
  48. volumes:
  49. - name: cert
  50. secret:
  51. secretName: proxy-server-cert
  52. ---
  53. apiVersion: v1
  54. kind: Secret
  55. metadata:
  56. name: proxy-server-cert
  57. namespace: karmada-system
  58. type: Opaque
  59. data:
  60. server-ca-cert.crt: |
  61. {{server_ca_cert}}
  62. server-cert.crt: |
  63. {{server_cert}}
  64. server-key.key: |
  65. {{server_key}}
  66. cluster-ca-cert.crt: |
  67. {{cluster_ca_cert}}
  68. cluster-cert.crt: |
  69. {{cluster_cert}}
  70. cluster-key.key: |
  71. {{cluster_key}}

Save the replace-proxy-server.sh file in the root directory of the ANP code repository.

unfold me to see the shell

  1. #!/bin/bash
  2. cert_yaml=proxy-server.yaml
  3. SERVER_CA_CERT=$(cat certs/frontend/issued/ca.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  4. sed -i'' -e "s/{{server_ca_cert}}/${SERVER_CA_CERT}/g" ${cert_yaml}
  5. SERVER_CERT=$(cat certs/frontend/issued/proxy-frontend.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  6. sed -i'' -e "s/{{server_cert}}/${SERVER_CERT}/g" ${cert_yaml}
  7. SERVER_KEY=$(cat certs/frontend/private/proxy-frontend.key | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  8. sed -i'' -e "s/{{server_key}}/${SERVER_KEY}/g" ${cert_yaml}
  9. CLUSTER_CA_CERT=$(cat certs/agent/issued/ca.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  10. sed -i'' -e "s/{{cluster_ca_cert}}/${CLUSTER_CA_CERT}/g" ${cert_yaml}
  11. CLUSTER_CERT=$(cat certs/agent/issued/proxy-frontend.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  12. sed -i'' -e "s/{{cluster_cert}}/${CLUSTER_CERT}/g" ${cert_yaml}
  13. CLUSTER_KEY=$(cat certs/agent/private/proxy-frontend.key | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  14. sed -i'' -e "s/{{cluster_key}}/${CLUSTER_KEY}/g" ${cert_yaml}

Run the following commands to run the script:

  1. chmod +x replace-proxy-server.sh
  2. bash replace-proxy-server.sh

Deploy the proxy-server on the karmada-host:

  1. kind load docker-image swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-server:0.0.24 --name karmada-host
  2. export KUBECONFIG=/root/.kube/karmada.config
  3. kubectl --context=karmada-host apply -f proxy-server.yaml

Step 5: Deploy proxy-agent

Save the proxy-agent.yaml file in the root directory of the ANP code repository.

unfold me to see the yaml

  1. # proxy-agent.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. labels:
  6. app: proxy-agent
  7. name: proxy-agent
  8. namespace: karmada-system
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: proxy-agent
  14. template:
  15. metadata:
  16. labels:
  17. app: proxy-agent
  18. spec:
  19. containers:
  20. - command:
  21. - /proxy-agent
  22. args:
  23. - '--ca-cert=/var/certs/agent/ca.crt'
  24. - '--agent-cert=/var/certs/agent/proxy-agent.crt'
  25. - '--agent-key=/var/certs/agent/proxy-agent.key'
  26. - '--proxy-server-host={{proxy_server_addr}}'
  27. - '--proxy-server-port=8091'
  28. - '--agent-identifiers=host={{identifiers}}'
  29. image: swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-agent:0.0.24
  30. imagePullPolicy: IfNotPresent
  31. name: proxy-agent
  32. livenessProbe:
  33. httpGet:
  34. scheme: HTTP
  35. port: 8093
  36. path: /healthz
  37. initialDelaySeconds: 15
  38. timeoutSeconds: 60
  39. volumeMounts:
  40. - mountPath: /var/certs/agent
  41. name: cert
  42. volumes:
  43. - name: cert
  44. secret:
  45. secretName: proxy-agent-cert
  46. ---
  47. apiVersion: v1
  48. kind: Secret
  49. metadata:
  50. name: proxy-agent-cert
  51. namespace: karmada-system
  52. type: Opaque
  53. data:
  54. ca.crt: |
  55. {{proxy_agent_ca_crt}}
  56. proxy-agent.crt: |
  57. {{proxy_agent_crt}}
  58. proxy-agent.key: |
  59. {{proxy_agent_key}}

Save the replace-proxy-agent.sh file in the root directory of the ANP code repository.

unfold me to see the shell

  1. #!/bin/bash
  2. cert_yaml=proxy-agent.yaml
  3. karmada_control_plane_addr=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' karmada-host-control-plane)
  4. member3_cluster_addr=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' member3-control-plane)
  5. sed -i'' -e "s/{{proxy_server_addr}}/${karmada_control_plane_addr}/g" ${cert_yaml}
  6. sed -i'' -e "s/{{identifiers}}/${member3_cluster_addr}/g" ${cert_yaml}
  7. PROXY_AGENT_CA_CRT=$(cat certs/agent/issued/ca.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  8. sed -i'' -e "s/{{proxy_agent_ca_crt}}/${PROXY_AGENT_CA_CRT}/g" ${cert_yaml}
  9. PROXY_AGENT_CRT=$(cat certs/agent/issued/proxy-agent.crt | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  10. sed -i'' -e "s/{{proxy_agent_crt}}/${PROXY_AGENT_CRT}/g" ${cert_yaml}
  11. PROXY_AGENT_KEY=$(cat certs/agent/private/proxy-agent.key | base64 | tr "\n" " "|sed s/[[:space:]]//g)
  12. sed -i'' -e "s/{{proxy_agent_key}}/${PROXY_AGENT_KEY}/g" ${cert_yaml}

Run the following commands to run the script:

  1. chmod +x replace-proxy-agent.sh
  2. bash replace-proxy-agent.sh

Deploy the proxy-agent in the pull mode for a member cluster (in this example, the member3 cluster is in the pull mode.):

  1. kind load docker-image swr.ap-southeast-1.myhuaweicloud.com/karmada/proxy-agent:0.0.24 --name member3
  2. kubectl --kubeconfig=/root/.kube/members.config --context=member3 apply -f proxy-agent.yaml

The ANP deployment is completed now.

Step 6: Add command flags for the karmada-agent deployment

After deploying the ANP deployment, you need to add extra command flags --cluster-api-endpoint and --proxy-server-address for the karmada-agent deployment in the member3 cluster.

Where --cluster-api-endpoint is the APIEndpoint of the cluster. You can obtain it from the KubeConfig file of the member3 cluster.

Where --proxy-server-address is the address of the proxy server that is used to proxy the cluster. In current case, you can set --proxy-server-address to http://<karmada_control_plane_addr>:8088. Get karmada_control_plane_addr value through the following command:

  1. docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' karmada-host-control-plane

Set port 8088 by modifying the code in ANP: https://github.com/mrlihanbo/apiserver-network-proxy/blob/v0.0.24/dev/cmd/server/app/server.go#L267. You can also modify it to a different value.