Get–K8sServices - anongitmous/k8sShell GitHub Wiki

Get the Kubernetes service resource(s) on the cluster.

Syntax

Get-K8sServices

[<K8sShellCommonParameters>]
[<CommonParameters>]

Description

Gets Service resource object(s).

See the example output.

Examples

ℹ️ See A Note about the Examples

1. Get all services from the currently-active namespace

Get-K8sServices

2. Get all services from the 'foo' namespace

Get-K8sServices -Namespace 'foo'

3. Get all service names and their selectors from all namespaces

Get-K8sServices -Namespace '' | Select-Object Name, @{'Name' = 'Selectors'; Expression = {$_.GetSelectors()}}

  • This makes use of PowerShell object pipelining and calls GetSelectors for each service object output by Get-K8sServices.
  • A similar result could also be achieved by piping the output from Get-K8sServices into Show–ServiceSelectors:
    Get-K8sServices -Namespace '' | Show-ServiceSelectors

4. Get all service names and their selectors from all namespaces subject to the label and field selectors

Get-K8sServices -Namespace '' -LabelSelector 'key=value' -FieldSelector 'metadata.name=pod_name'

Parameters

See Common Parameters/Namespaced All

Outputs

Mtf.Kubernetes.Services.V1K8sService

Example

image

Supported Field Selectors

📝 - As of 06/2023

  • metadata.namespace
  • metadata.name

Notes

K8sShell includes the following alias for Get-K8sServices:

  • ksgsvc

📝 Due potential confusion with Microsoft's built-in 'Get-Service' cmdlet, this cmdlet's name was changed to 'Get-K8sServices'.

Related