Class: CDK8sPlus25::K8S::ServicePort

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
k8_s/service_port.rb

Overview

ServicePort contains information on service's port.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port:, app_protocol: nil, name: nil, node_port: nil, protocol: nil, target_port: nil) ⇒ ServicePort

Returns a new instance of ServicePort.

Parameters:

  • port (Numeric)

    The port that will be exposed by this service.

  • app_protocol (String, nil) (defaults to: nil)

    The application protocol for this port.

  • name (String, nil) (defaults to: nil)

    The name of this port within the service.

  • node_port (Numeric, nil) (defaults to: nil)

    The port on each node on which this service is exposed when type is NodePort or LoadBalancer.

  • protocol (String, nil) (defaults to: nil)

    The IP protocol for this port.

  • target_port (CDK8sPlus25::K8S::IntOrString, nil) (defaults to: nil)

    Number or name of the port to access on the pods targeted by the service.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'k8_s/service_port.rb', line 13

def initialize(port:, app_protocol: nil, name: nil, node_port: nil, protocol: nil, target_port: nil)
  @port = port
  Jsii::Type.check_type(@port, "eyJwcmltaXRpdmUiOiJudW1iZXIifQ==", "port")
  @app_protocol = app_protocol
  Jsii::Type.check_type(@app_protocol, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "appProtocol") unless @app_protocol.nil?
  @name = name
  Jsii::Type.check_type(@name, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "name") unless @name.nil?
  @node_port = node_port
  Jsii::Type.check_type(@node_port, "eyJwcmltaXRpdmUiOiJudW1iZXIifQ==", "nodePort") unless @node_port.nil?
  @protocol = protocol
  Jsii::Type.check_type(@protocol, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "protocol") unless @protocol.nil?
  @target_port = target_port
  Jsii::Type.check_type(@target_port, "eyJmcW4iOiJjZGs4cy1wbHVzLTI1Lms4cy5JbnRPclN0cmluZyJ9", "targetPort") unless @target_port.nil?
end

Instance Attribute Details

#app_protocolString? (readonly)

The application protocol for this port.

This field follows standard Kubernetes label syntax. Un-prefixed names are reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). Non-standard protocols should use prefixed names such as mycompany.com/my-custom-protocol.

Returns:

  • (String, nil)


37
38
39
# File 'k8_s/service_port.rb', line 37

def app_protocol
  @app_protocol
end

#nameString? (readonly)

The name of this port within the service.

This must be a DNS_LABEL. All ports within a ServiceSpec must have unique names. When considering the endpoints for a Service, this must match the 'name' field in the EndpointPort. Optional if only one ServicePort is defined on this service.

Returns:

  • (String, nil)


43
44
45
# File 'k8_s/service_port.rb', line 43

def name
  @name
end

#node_portNumeric? (readonly)

The port on each node on which this service is exposed when type is NodePort or LoadBalancer.

Usually assigned by the system. If a value is specified, in-range, and not in use it will be used, otherwise the operation will fail. If not specified, a port will be allocated if this Service requires one. If this field is specified when creating a Service which does not need it, creation will fail. This field will be wiped when updating a Service to no longer need it (e.g. changing type from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport

Returns:

  • (Numeric, nil)


49
50
51
# File 'k8_s/service_port.rb', line 49

def node_port
  @node_port
end

#portNumeric (readonly)

The port that will be exposed by this service.

Returns:

  • (Numeric)


31
32
33
# File 'k8_s/service_port.rb', line 31

def port
  @port
end

#protocolString? (readonly)

Note:

Default: TCP.

The IP protocol for this port.

Supports "TCP", "UDP", and "SCTP". Default is TCP.

Returns:

  • (String, nil)


56
57
58
# File 'k8_s/service_port.rb', line 56

def protocol
  @protocol
end

#target_portCDK8sPlus25::K8S::IntOrString? (readonly)

Number or name of the port to access on the pods targeted by the service.

Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map). This field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service



62
63
64
# File 'k8_s/service_port.rb', line 62

def target_port
  @target_port
end

Class Method Details

.jsii_propertiesObject



64
65
66
67
68
69
70
71
72
73
# File 'k8_s/service_port.rb', line 64

def self.jsii_properties
  {
    :port => "port",
    :app_protocol => "appProtocol",
    :name => "name",
    :node_port => "nodePort",
    :protocol => "protocol",
    :target_port => "targetPort",
  }
end

Instance Method Details

#to_jsiiObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'k8_s/service_port.rb', line 75

def to_jsii
  result = {}
  result.merge!({
    "port" => @port,
    "appProtocol" => @app_protocol,
    "name" => @name,
    "nodePort" => @node_port,
    "protocol" => @protocol,
    "targetPort" => @target_port,
  })
  result.compact
end