Skip to content

Autopilot Networking

Networking model của Autopilot

Autopilot bắt buộc dùng VPC-native networking (alias IPs) và Dataplane V2 (Cilium/eBPF). Không có option để chọn routes-based networking hay kubenet. Đây là constraint cứng, không thể thay đổi sau khi cluster được tạo.

VPC-native: Mỗi Pod nhận một IP từ Pod CIDR range, được cấp qua alias IPs trên node NIC. Không có NAT giữa Pod IP và VPC.

Dataplane V2 (eBPF/Cilium): Thay thế kube-proxy và iptables bằng eBPF programs. Lợi ích: không có iptables chain explosion khi có nhiều Services, native NetworkPolicy enforcement, Hubble observability.

Cloud DNS: Autopilot bắt buộc dùng Cloud DNS cho DNS resolution trong cluster (không phải kube-dns in-cluster DNS server). Cloud DNS cung cấp managed DNS infrastructure bên ngoài cluster.

IP Allocation và node sizing

Điểm quan trọng nhất

Trong Standard clusters, bạn control /node-cidr-mask-size — thường /24 (256 IPs, 110 Pods max per node). Trong Autopilot, bạn không kiểm soát node CIDR size.

Autopilot cố định 32 Pods per node — đây là một trong những thay đổi quan trọng nhất so với Standard (tối đa 110 Pods per node).

Hệ quả:

  • Mỗi node cần ít nhất 32 Pod IPs + node IP + alias IPs = ~36 IPs
  • Autopilot phân bổ /26 subnet per node (64 IPs)
  • Với 100 nodes, cần 100 × 64 = 6400 IPs từ Pod CIDR range

Sizing Pod CIDR cho Autopilot

Khi tạo Autopilot cluster, phải đảm bảo Pod CIDR đủ lớn:

bash
# Ví dụ: cluster tối đa 1000 nodes
# Cần: 1000 × 64 = 64,000 IPs → /16 (65,536 IPs)

gcloud container clusters create-auto CLUSTER_NAME \
  --region REGION \
  --cluster-ipv4-cidr="10.0.0.0/16" \   # Pod CIDR, đủ cho 1000 nodes
  --services-ipv4-cidr="10.1.0.0/20"    # Services CIDR

Anti-pattern: Dùng Pod CIDR quá nhỏ

bash
# WRONG: /24 chỉ có 256 IPs, chỉ đủ cho ~4 nodes
--cluster-ipv4-cidr="10.0.0.0/24"

Với Pod CIDR quá nhỏ, cluster sẽ fail khi scale vượt capacity. Và bạn không thể expand Pod CIDR sau khi cluster được tạo.

IP exhaustion trong Autopilot

IP exhaustion là failure mode phổ biến trong production Autopilot. Signs:

Warning: Failed to assign Pod IPs
Error: no available IP addresses in subnet
bash
# Kiểm tra IP usage
gcloud compute addresses list --filter="subnetwork:your-subnet"

# Xem node count và IP usage
kubectl get nodes --no-headers | wc -l
kubectl describe nodes | grep -E "PodCIDR"

Services CIDR và Service IP allocation

Services CIDR cũng cần sizing cẩn thận. Autopilot tự động allocate /20 range cho Services mặc định (4,096 Service IPs).

Nếu bạn có nhiều Services (microservices, headless services), có thể cần /20 lớn hơn.

Dataplane V2 và Network Policy

Chỉ hỗ trợ Cilium NetworkPolicies

Autopilot (với Dataplane V2) hỗ trợ:

  • Kubernetes standard NetworkPolicy (v1) — dùng Cilium engine
  • Cilium CiliumNetworkPolicy — extended features
  • Không hỗ trợ Calico NetworkPolicy CRDs

Nếu bạn migrate từ Standard cluster với Calico policies, phải convert:

yaml
# Calico GlobalNetworkPolicy (không hoạt động trong Autopilot)
apiVersion: crd.projectcalico.org/v1
kind: GlobalNetworkPolicy
spec: ...

# Phải convert sang standard NetworkPolicy
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
spec: ...

FQDNNetworkPolicy

Autopilot hỗ trợ FQDNNetworkPolicy — Cilium feature cho phép egress policy theo domain name thay vì IP:

yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: egress-to-external-api
spec:
  podSelector:
    matchLabels:
      app: my-service
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 443
      protocol: TCP

Với FQDNNetworkPolicy (Cilium):

yaml
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: allow-egress-to-api
spec:
  endpointSelector:
    matchLabels:
      app: my-service
  egress:
  - toFQDNs:
    - matchName: "api.external-service.com"
  - toPorts:
    - ports:
      - port: "443"
        protocol: TCP

hostPort trong Autopilot

Giới hạn hostPort

hostPort trong Kubernetes cho phép Pod nhận traffic trực tiếp trên một port của node. Trong Standard, điều này đơn giản. Trong Autopilot, có nhiều restrictions:

Không hỗ trợ static hostPorts cho Kubernetes-managed controllers:

yaml
# WRONG trong Autopilot: Deployment với static hostPort
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: app
        ports:
        - containerPort: 8080
          hostPort: 8080  # Bị reject trong Autopilot

Chỉ hỗ trợ random hostPorts cho static Pods và custom controllers (như Agones game server):

yaml
# OK trong Autopilot: Static Pod với hostPort (random)
spec:
  containers:
  - name: game-server
    ports:
    - containerPort: 7777
      hostPort: 0  # Random port assignment
      protocol: UDP

Cách enable hostPort trong Autopilot

Nếu workload thực sự cần hostPort (ví dụ: Agones game servers), phải enable tính năng này:

bash
gcloud container clusters update CLUSTER_NAME \
  --region REGION \
  --enable-autopilot-hostports

Sau khi enable, workloads được phép dùng hostPort với một số restrictions:

yaml
# Pod với hostPort sau khi enable
metadata:
  annotations:
    autopilot.gke.io/use-host-port: "true"
spec:
  containers:
  - name: game-server
    ports:
    - containerPort: 7777
      hostPort: 7777
      protocol: UDP

Known issue với hostPort và Dataplane V2

Có một known bug trong Dataplane V2 (eBPF): Passthrough Network Load Balancer traffic có thể không được forward đúng đến hostPort Pods, đặc biệt nếu hostPort conflicts với NodePort range (30000-32767).

Workaround: Tránh dùng ports trong range 30000-32767 cho hostPort, hoặc dùng NodePort Services thay thế hostPort.

Alternative tốt hơn hostPort

Thay vì hostPort, các pattern sau thường tốt hơn và hoạt động tốt trong Autopilot:

yaml
# Option 1: NodePort Service (recommended)
apiVersion: v1
kind: Service
spec:
  type: NodePort
  ports:
  - port: 8080
    nodePort: 30080  # Static NodePort
  selector:
    app: my-app

# Option 2: LoadBalancer Service với annotation
apiVersion: v1
kind: Service
spec:
  type: LoadBalancer
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: my-app

Cloud DNS requirement

Autopilot bắt buộc dùng Cloud DNS, không phải in-cluster kube-dns. Điều này có một số implications:

Lợi ích của Cloud DNS trong Autopilot

Không chiếm node resources: kube-dns chạy trên nodes và tiêu tốn CPU/memory. Với Cloud DNS, Google managed infrastructure xử lý DNS lookups bên ngoài cluster.

Higher availability: Cloud DNS có SLA cao hơn kube-dns in-cluster. Không có single point of failure DNS.

Auto-scaling: Không cần scale kube-dns khi cluster grows.

Limitations

Higher latency có thể xảy ra: DNS queries đi ra ngoài cluster và quay trở lại, thay vì resolve trong cluster. Tuy nhiên, Cloud DNS có caching tại node level.

Không custom CoreDNS: Bạn không thể modify CoreDNS configuration file. Không thể thêm custom plugins, thay đổi upstream resolvers, hay cấu hình special DNS behaviors.

External DNS resolution patterns:

yaml
# Với Cloud DNS, headless services vẫn hoạt động bình thường
# Pod DNS: pod-ip.namespace.pod.cluster.local
# Service DNS: service-name.namespace.svc.cluster.local

Cloud DNS và private zones

Autopilot tự động config Cloud DNS để resolve cả internal (in-cluster) và external (Google APIs, internet) DNS:

Pod DNS query → Cloud DNS (managed)
    ├── In-cluster service → resolve từ cluster zone
    ├── GCP services → resolve qua Google internal
    └── External domains → resolve qua Google DNS

VPC-native considerations

Shared VPC với Autopilot

Autopilot hỗ trợ Shared VPC (dùng network từ host project):

bash
gcloud container clusters create-auto CLUSTER_NAME \
  --region REGION \
  --network "projects/HOST_PROJECT/global/networks/shared-vpc" \
  --subnetwork "projects/HOST_PROJECT/regions/REGION/subnetworks/subnet-name" \
  --cluster-secondary-range-name "pods-range" \
  --services-secondary-range-name "services-range"

Private clusters trong Autopilot

Autopilot hỗ trợ private clusters (nodes không có external IP):

bash
gcloud container clusters create-auto CLUSTER_NAME \
  --region REGION \
  --enable-private-nodes \
  --enable-private-endpoint \
  --master-ipv4-cidr "172.16.0.0/28"

Với private endpoint, chỉ có thể access API server từ VPC hoặc authorized networks.

Không hỗ trợ routes-based networking

Nếu bạn có Standard cluster dùng routes-based networking (không phải VPC-native) và muốn migrate sang Autopilot, bạn không thể migrate trực tiếp. Phải:

  1. Tạo Autopilot cluster mới (luôn VPC-native)
  2. Deploy workloads vào cluster mới
  3. Migrate traffic
  4. Decommission cluster cũ

Load Balancing trong Autopilot

Autopilot hỗ trợ đầy đủ GKE load balancing options:

yaml
# External LoadBalancer (Global External Application LB)
apiVersion: v1
kind: Service
metadata:
  annotations:
    cloud.google.com/neg: '{"ingress": true}'  # Container-native LB
spec:
  type: LoadBalancer

# Internal LoadBalancer
apiVersion: v1
kind: Service
metadata:
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
spec:
  type: LoadBalancer

Container-native LB (NEG-based) đặc biệt quan trọng trong Autopilot vì nó route traffic trực tiếp đến Pod IPs, không qua node IP. Điều này hiệu quả hơn khi nodes không cố định.

Egress Internet và Cloud NAT

Nếu Pods cần outbound internet access (pull images, gọi external APIs), cần cấu hình Cloud NAT cho subnet:

bash
# Tạo Cloud Router
gcloud compute routers create autopilot-router \
  --region REGION \
  --network YOUR_VPC

# Tạo Cloud NAT
gcloud compute routers nats create autopilot-nat \
  --router=autopilot-router \
  --region REGION \
  --auto-allocate-nat-external-ips \
  --nat-all-subnet-ip-ranges

Với private clusters (không có external IPs trên nodes), Cloud NAT là bắt buộc để Pods kéo images từ public registries.

Network monitoring trong Autopilot

bash
# Xem network policy events
kubectl get events --field-selector reason=NetworkPolicyDeny

# Kiểm tra connectivity giữa Pods
kubectl exec -it pod/SOURCE_POD -- curl http://TARGET_SERVICE:PORT

# Xem Hubble flow logs (nếu enabled)
kubectl exec -it -n kube-system ds/hubble-relay -- hubble observe \
  --namespace MY_NAMESPACE \
  --follow

References