Skip to content

GKE Networking Guide

Complete guide to networking in Google Kubernetes Engine (GKE), covering Pods, Services, DNS, load balancing, security, and IP address management.

Networking Overview

Key Networking Concepts

ConceptDescription
Pod NetworkEach Pod gets a unique IP address, Pods can communicate directly
ServicesStable network endpoint for a set of Pods
IngressHTTP(S) routing to Services
Gateway APINext-gen traffic management (Layer 4 & 7)
Network PoliciesFirewall rules for Pod-to-Pod traffic
Dataplane V2eBPF-based networking with built-in policy enforcement

Services

Service Types

ClusterIP Service

Default service type. Provides internal-only access within the cluster.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP  # Default
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080

LoadBalancer Service

Exposes service externally using a cloud load balancer.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-external-service
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080
  # Restrict source IPs
  loadBalancerSourceRanges:
  - 10.0.0.0/8
  - 192.168.1.0/24

Service Discovery

Services are discoverable via DNS:

  • Same namespace: my-service
  • Cross namespace: my-service.other-namespace
  • FQDN: my-service.namespace.svc.cluster.local

Load Balancing

Load Balancer Types

Load Balancer TypeLayerUse Case
External Network LBL4TCP/UDP services, gaming, IoT
External HTTP(S) LBL7Web apps, APIs, microservices
Internal TCP/UDP LBL4Internal TCP services
Internal HTTP(S) LBL7Internal APIs, service mesh

Internal Load Balancer

yaml
apiVersion: v1
kind: Service
metadata:
  name: internal-service
  annotations:
    networking.gke.io/load-balancer-type: "Internal"
spec:
  type: LoadBalancer
  selector:
    app: internal-app
  ports:
  - port: 80
    targetPort: 8080

Gateway API

Gateway API is the next-generation traffic management for Kubernetes.

Gateway Example

yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: external-gateway
spec:
  gatewayClassName: gke-l7-global-external-managed
  listeners:
  - name: http
    protocol: HTTP
    port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: app-route
spec:
  parentRefs:
  - name: external-gateway
  rules:
  - matches:
    - path:
        value: /api
    backendRefs:
    - name: api-service
      port: 80
  - matches:
    - path:
        value: /
    backendRefs:
    - name: frontend-service
      port: 80

Gateway API Features

FeatureDescription
Path-based routingRoute by URL path
Host-based routingRoute by hostname
Header matchingRoute by HTTP headers
Traffic splittingCanary deployments, A/B testing
TLS terminationHTTPS with managed certificates

Network Policies

Control Pod-to-Pod communication with Network Policies.

Default Deny Policy

yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: production
spec:
  podSelector: {}  # Applies to all pods
  policyTypes:
  - Ingress
  - Egress

Allow Specific Traffic

yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-to-backend
spec:
  podSelector:
    matchLabels:
      app: backend
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: frontend
    ports:
    - protocol: TCP
      port: 8080

Network Policy Best Practices

  1. Start with default deny - Block all traffic, then allow what's needed
  2. Use namespace selectors - Isolate namespaces from each other
  3. Enable logging - Audit allowed and denied connections
  4. Test policies - Verify before applying to production

GKE Dataplane V2

eBPF-based networking dataplane with enhanced features.

Dataplane V2 Benefits

BenefitDescription
Built-in policy enforcementNative NetworkPolicy support
ObservabilityHubble for traffic visibility
PerformanceOptimized eBPF data path
Kubernetes-native loggingNetwork policy logs in Cloud Logging

Enable Dataplane V2

bash
gcloud container clusters create my-cluster \
    --enable-dataplane-v2 \
    --region us-central1

IP Address Management

IP Address Planning

IP Planning Considerations

ComponentRecommendation
Nodes/24 per 250 nodes
Pods/14 for large clusters (1M+ Pods)
Services/20 for most clusters
Pod densityDefault 110 Pods/node

VPC-Native Clusters

bash
gcloud container clusters create my-cluster \
    --enable-ip-alias \
    --cluster-ipv4-cidr=/14 \
    --services-ipv4-cidr=/20 \
    --region us-central1

Multi-Cluster Networking

Multi-Cluster Services (MCS)

Multi-cluster Services enables:

  • Cross-cluster service discovery
  • Automatic health-aware failover
  • Global DNS resolution

DNS Configuration

NodeLocal DNSCache

Improve DNS performance by caching queries locally on each node.

Enable NodeLocal DNSCache:

bash
gcloud container clusters update my-cluster \
    --update-addons=NodeLocalDNS=ENABLED

Cloud DNS for GKE

Use Cloud DNS for improved scalability and reliability:

bash
gcloud container clusters update my-cluster \
    --cluster-dns=clouddns \
    --cluster-dns-scope=vpc

Quick Reference

Common Networking Commands

bash
# View services
kubectl get services -A

# View endpoints
kubectl get endpoints

# View network policies
kubectl get networkpolicies -A

# Test connectivity
kubectl run test --rm -it --image=busybox -- wget -qO- http://service-name

# View DNS resolution
kubectl run test --rm -it --image=busybox -- nslookup service-name

Troubleshooting Checklist

IssueCheck
Service unreachableEndpoints exist, Pod labels match selector
DNS not resolvingkube-dns running, service exists
Traffic blockedNetwork policies, firewall rules
Load balancer pendingQuota, firewall, health checks

Last updated: December 2025

Built with VitePress & Mermaid diagrams