Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Application Load Balancer
  • Getting started
    • Overview
      • Overview
      • Installing Gwin
      • Gwin policies
      • Migrating apps from an ALB Ingress controller to Gwin
        • Gateway
        • GatewayPolicy
        • GRPCRoute
        • HTTPRoute
        • Ingress
        • IngressBackendGroup
        • IngressPolicy
        • RoutePolicy
        • Service
        • ServicePolicy
        • TLSRoute
        • YCCertificate
        • YCStorageBucket
    • Configuring security groups
    • Working with service accounts
    • Creating and updating resources via ingress controller configurations
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • L7 load balancer logs
  • Release notes

In this article:

  • Cheatsheet
  • ServicePolicySpec
  • LocalObjectReference
  • LabelSelector
  • LabelSelectorRequirement
  • Service
  • ServiceTargets
  • ServiceTargetsNode
  • ServicePolicyStatus
  1. Tools for Managed Service for Kubernetes
  2. Gwin
  3. Resource configuration
  4. ServicePolicy

ServicePolicy

Written by
Yandex Cloud
Updated at September 24, 2025
  • Cheatsheet
  • ServicePolicySpec
  • LocalObjectReference
  • LabelSelector
  • LabelSelectorRequirement
  • Service
  • ServiceTargets
  • ServiceTargetsNode
  • ServicePolicyStatus

ServicePolicy is a Gwin custom resource for configuring Service-specific policies. It allows you to configure how Kubernetes Services are used as ALB targets, controlling target selection, addressing, and zone matching.

ServicePolicy provides the same functionality as Service annotations but through spec fields instead of annotations, offering better validation and type safety.

  • Cheatsheet
  • ServicePolicySpec
    • LocalObjectReference
    • LabelSelector
    • LabelSelectorRequirement
    • Service
  • ServicePolicyStatus

CheatsheetCheatsheet

NOTE: Specification provided below is not valid configuration.

It's just demonstration of all ServicePolicy fields.

apiVersion: gwin.yandex.cloud/v1
kind: ServicePolicy
metadata:
  name: example-service-policy
  namespace: example-ns
spec:
  # Target selection - policy applies to services matching these criteria
  targetRefs:
    - group: ""
      kind: Service
      name: my-service  # specific service by name
  selector:
    matchLabels:
      app: my-app  # services with these labels
    matchExpressions:
      - key: environment
        operator: In
        values: ["production", "staging"]
  
  # Service target configuration
  policy:
    targets:
      type: Node  # Node or Pod targets
      ipFamily: IPv4  # IP family for targets
      cidrs: ["10.0.0.0/8", "172.16.0.0/12"]  # address filtering
      albZoneMatch: true  # zone matching
      node:
        onlyWithPods: true  # only nodes with pods
        addressType: InternalIP  # address type
Field Description
metadata ServicePolicyMeta
Standard Kubernetes metadata
spec ServicePolicySpec
ServicePolicy specification
status ServicePolicyStatus
ServicePolicy status

ServicePolicySpecServicePolicySpec

Appears in: ServicePolicy

The policy is restricted to resources within the same namespace.

When determining which resources the policy applies to, the following rules are used:

  • If both TargetRefs and Selector are specified, a resource must match both criteria to be affected by the policy.
  • If neither TargetRefs nor Selector is specified, the policy applies to all resources within the same namespace.
Field Description
targetRefs []LocalObjectReference
References to Service resources that this policy should apply to
selector LabelSelector
Label selector for Service resources that this policy should apply to
policy Service
Service-specific configuration

LocalObjectReferenceLocalObjectReference

Reference to a local Kubernetes object.

Appears in: ServicePolicySpec

Field Description
group string
API group of the target resource
Example: ""
kind string
Kind of the target resource
Example: Service
name string
Name of the target resource
Example: my-service

LabelSelectorLabelSelector

Label selector for selecting resources by labels.

Appears in: ServicePolicySpec

Field Description
matchLabels map[string]string
Map of key-value pairs for exact label matching
Example: app: my-service
matchExpressions []LabelSelectorRequirement
List of label selector requirements

LabelSelectorRequirementLabelSelectorRequirement

Label selector requirement for advanced label matching.

Appears in: LabelSelector

Field Description
key string
Label key that the selector applies to
Example: environment
operator string
Operator for the requirement. Options: In, NotIn, Exists, DoesNotExist
Example: In
values []string
Array of string values for In and NotIn operators
Example: ["production", "staging"]

ServiceService

Service policy configuration that applies to Service targets.

Appears in: ServicePolicySpec

Field Description
targets ServiceTargets
Configures how ALB should select and address Service endpoints

ServiceTargetsServiceTargets

Appears in: Service

ServiceTargets defines how ALB targets are selected and addressed for a Service. It controls whether to use Node or Pod endpoints, network restrictions, and zone matching.

Field Description
type string
Specifies whether to use Node or Pod endpoints as ALB targets. Node uses cluster nodes as targets (default), Pod uses individual pods as targets
Example: Node
ipFamily string
Specifies which IP family to use for target addresses. Currently only IPv4 is supported
Example: IPv4
cidrs []string
Helps select appropriate target addresses when targets have multiple IP addresses. Only addresses within these CIDR blocks will be used for ALB targets
Example: ["10.0.0.0/8", "172.16.0.0/12"]
albZoneMatch boolean
Controls whether to verify that targets are located in the same zones as the ALB. When true (default), only targets in ALB zones are included
Example: true
node ServiceTargetsNode
Additional configuration when type is "Node". This field is ignored when type is "Pod"

ServiceTargetsNodeServiceTargetsNode

Appears in: ServiceTargets

ServiceTargetsNode contains configuration specific to Node-type targets. This configuration is only used when ServiceTargets.Type is "Node".

Field Description
onlyWithPods boolean
Controls whether to include only nodes that have pods for this service. When true (default), only nodes running pods that match the service selector are used as targets
Example: true
addressType string
Specifies which node address type to use for ALB targets. InternalIP uses node's internal IP address (default), ExternalIP uses node's external IP address
Example: InternalIP

ServicePolicyStatusServicePolicyStatus

Appears in: ServicePolicy

Field Description
conditions []Condition
List of conditions representing the current state of the ServicePolicy
attachedServices int32
Number of currently attached services

Was the article helpful?

Previous
Service
Next
TLSRoute
© 2025 Direct Cursus Technology L.L.C.