檢視次數:
如果您需要將 ICAP 服務暴露在 EKS 叢集之外以供外部用戶端使用,您可以使用 AWS NLB。
ICAP(網路內容調適通訊協定)伺服器需要網路負載平衡器,因為:
  • ICAP 在埠 1344 上運行,並使用其自己的第 7 層通訊協定
  • ALB 僅支援基於 HTTP 的通訊協定
  • NLB 在第 4 層(TCP)運作,並能正確處理 ICAP 流量
先決條件:
  • EKS 叢集已啟動並運行
  • kubectlhelm 已配置適當的訪問權限
  • 已安裝並配置 AWS CLI
  • IAM 權限以建立負載平衡器資源

步驟

  1. 安裝 AWS 負載平衡控制器(如果尚未安裝):
    # Create IAM policy
    curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json
    
    aws iam create-policy \
      --policy-name AWSLoadBalancerControllerIAMPolicy \
      --policy-document file://iam-policy.json
    
    # Create IAM role and service account
    eksctl create iamserviceaccount \
      --cluster <your-cluster-name> \
      --namespace kube-system \
      --name aws-load-balancer-controller \
      --attach-policy-arn arn:aws:iam::<your-account-id>:policy/AWSLoadBalancerControllerIAMPolicy \
      --approve
    
    # Install controller
    helm repo add eks https://aws.github.io/eks-charts
    helm repo update
    
    helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
      -n kube-system \
      --set clusterName=<your-cluster-name> \
      --set serviceAccount.create=false \
      --set serviceAccount.name=aws-load-balancer-controller
    
  2. 為 NLB 標記子網路:
    1. 移至「AWS VPC Console」「Subnets」
    2. 將這些標籤新增到您希望 NLB 使用的每個子網路:
      kubernetes.io/cluster/<your-cluster-name> = shared
      kubernetes.io/role/elb = 1 (for public) 
      or kubernetes.io/role/internal-elb = 1 (for private)
      
      注意
      注意
      確保子網路有足夠的可用 IP。
  3. 更新 values.yaml 以進行外部訪問
    scanner:
      # Other scanner settings remain unchanged
    
      # Enable external NLB service for ICAP
      externalService:
        enabled: true
        annotations:
          service.beta.kubernetes.io/aws-load-balancer-type: "external"
          service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"
          service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
        icapPort: 1344
    
  4. 使用 NLB 配置更新部署:
    helm upgrade my-release visionone-filesecurity/visionone-filesecurity \
      -n visionone-filesecurity \
      -f my-values.yaml
    
  5. 驗證 NLB 部署:
    # Check the service status
    kubectl get service -n visionone-filesecurity | grep scanner-lb
    
    # Get the NLB DNS name
    NLB_DNS=$(kubectl get service -n visionone-filesecurity my-release-visionone-filesecurity-scanner-lb -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    echo "Your NLB DNS name is: $NLB_DNS"
    
  6. 配置 DNS (Route53)
    1. 移至「Route53 Console」「Hosted Zones」
    2. 建立 A 記錄:
      • 名稱:icap.example.com
      • 類型:A(別名)
      • 將流量路由至:網路負載平衡器
      • 選擇您的 NLB
  7. 安裝並使用 c-icap-client 測試您的連線:
    # Install c-icap-client
    sudo apt-get install c-icap
    
    # Test with file scanning
    c-icap-client -i icap.example.com -s scan -p 1344 -f sample.txt -x "X-scan-file-name: sample.txt"
    
  8. 如果您想為您的 ICAP 服務啟用 TLS,請在 my-values.yaml 中更新您的 NLB 配置:
    scanner:
      externalService:
        enabled: true
        type: LoadBalancer
        annotations:
          service.beta.kubernetes.io/aws-load-balancer-type: "external"
          service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"
          service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
          # TLS configuration
          service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:region:account-id:certificate/certificate-id"
        icapPort: 1344
    Apply this configuration:
    helm upgrade my-release visionone-filesecurity/visionone-filesecurity \
      -n visionone-filesecurity \
      -f my-values.yaml