Common Parameters Detail - anongitmous/k8sShell GitHub Wiki

-KubeConfig

Type: String
Aliases: kc
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Context

Type: String
Aliases: ctx
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Namespace

Type: String
Aliases: ns
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ClusterConfigKey

  • A key within the loaded config whose values will be used for resolving cmdlet common parameters and arguments as well as other runtime properties.
  • See Config Overview for details.
Type: String
Aliases: cck
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FieldSelector

  • Server-side selector (field query) to filter on, supports: =, ==, and !=.
  • e.g. -FieldSelector 'spec.nodeName=ip-152-20-34-132.us-east-1.compute.internal,status.phase=Running'.
Type: String
Aliases: fs
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-LabelSelector

  • Server-side selector (label query) to filter on, supports
    • equality based: =, ==, and !=. e.g. -LabelSelector 'key1=value1,key2=value2'
    • set-based: in, notin, exists
      e.g. -LabelSelector 'label in (value1, value2, value3)'
      e.g. -LabelSelector 'label notin (value1, value2)'
      e.g. -LabelSelector 'label' (label must exist)
      e.g. -LabelSelector '!label' (label must not exist)
Type: String
Aliases: ls
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Timeout

  • The number of seconds to wait before the server gives up on an operation.
Type: Int32
Aliases:
Position: Named
Default value: Unlimited
Accept pipeline input: False
Accept wildcard characters: False

-Watch

  • Monitor the server for changes to a resource.
  • Valid values are one of:
    • Added
    • Modified
    • AddedModified
    • Deleted
    • All
  • Examples
    • Watch for all pod events:
      Get-Pods -Watch All
    • Watch for all node events:
      Get-Nodes -Watch All
    • Watch for all service events:
      Get-Svcs -Watch All
Type: Mtf.Kubernetes.Transformers.StringToWatchEvent.WatchEvent
Aliases: w
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ResultSize

  • The upper limit of how many objects to return to the client.
  • The default is no limit. A value of 0 indicates the same.
Type: Int32
Aliases:
Position: Named
Default value: No limit
Accept pipeline input: False
Accept wildcard characters: False

-AsJson

  • Output the objects in textual JSON format.
Type: SwitchParameter
Aliases:
Position: Named
Default value: N/A
Accept pipeline input: False
Accept wildcard characters: False

-NoNulls

  • If -AsJson has been specified, then only JSON names that have non-Null values will be returned.
Type: SwitchParameter
Aliases:
Position: Named
Default value: N/A
Accept pipeline input: False
Accept wildcard characters: False

-ShowStructure

  • Display the object structure of the k8s object wrapped in an object returned from one of the K8sShell cmdlets.
  • The main purpose of this output is so that object properties and methods can be explored for the purposes of display, filtering, etc.

â„šī¸ To display properties and methods for any of the K8sShell cmdlets, pipe a cmdlet into Get-Member, e.g. Get-Pods | Get-Member.

Type: SwitchParameter
Aliases:
Position: Named
Default value: N/A
Accept pipeline input: False
Accept wildcard characters: False
Truncated Sample Output for a Pod
name: V1Pod, type: V1Pod
  name: ApiVersion, type: String
  name: Kind, type: String
  name: Metadata, type: V1ObjectMeta
    name: Annotations, type: Dictionary
      name: Key, type: String
      name: Value, type: String
    name: CreationTimestamp, type: DateTime?
    name: DeletionGracePeriodSeconds, type: Int64?
    name: DeletionTimestamp, type: DateTime?
    name: Finalizers, type: List
      name: Item, type: String
    name: GenerateName, type: String
    name: Generation, type: Int64?
    name: Labels, type: Dictionary
      name: Key, type: String
      name: Value, type: String
    name: ManagedFields, type: List
      name: Item, type: V1ManagedFieldsEntry
        name: ApiVersion, type: String
        name: FieldsType, type: String
        name: FieldsV1, type: Object
        name: Manager, type: String
        name: Operation, type: String
        name: Subresource, type: String
        name: Time, type: DateTime?
    name: Name, type: String
    name: NamespaceProperty, type: String
    name: OwnerReferences, type: List
      name: Item, type: V1OwnerReference
        name: ApiVersion, type: String
        name: BlockOwnerDeletion, type: Boolean?
        name: Controller, type: Boolean?
        name: Kind, type: String
        name: Name, type: String
        name: Uid, type: String
    name: ResourceVersion, type: String
    name: SelfLink, type: String
    name: Uid, type: String
  name: Spec, type: V1PodSpec
    name: ActiveDeadlineSeconds, type: Int64?
    name: Affinity, type: V1Affinity
      name: NodeAffinity, type: V1NodeAffinity
        name: PreferredDuringSchedulingIgnoredDuringExecution, type: List
          name: Item, type: V1PreferredSchedulingTerm
            name: Preference, type: V1NodeSelectorTerm
              name: MatchExpressions, type: List
                name: Item, type: V1NodeSelectorRequirement
                  name: Key, type: String
                  name: OperatorProperty, type: String
                  name: Values, type: List
                    name: Item, type: String
              name: MatchFields, type: List
                name: Item, type: V1NodeSelectorRequirement
                  name: Key, type: String
                  name: OperatorProperty, type: String
                  name: Values, type: List
                    name: Item, type: String
            name: Weight, type: Int32
...
      name: PodAffinity, type: V1PodAffinity
        name: PreferredDuringSchedulingIgnoredDuringExecution, type: List
          name: Item, type: V1WeightedPodAffinityTerm
            name: PodAffinityTerm, type: V1PodAffinityTerm
              name: LabelSelector, type: V1LabelSelector
                name: MatchExpressions, type: List
                  name: Item, type: V1LabelSelectorRequirement
                    name: Key, type: String
                    name: OperatorProperty, type: String
                    name: Values, type: List
                      name: Item, type: String
                name: MatchLabels, type: Dictionary
                  name: Key, type: String
                  name: Value, type: String
              name: NamespaceSelector, type: V1LabelSelector
                name: MatchExpressions, type: List
                  name: Item, type: V1LabelSelectorRequirement
                    name: Key, type: String
                    name: OperatorProperty, type: String
                    name: Values, type: List
                      name: Item, type: String
                name: MatchLabels, type: Dictionary
                  name: Key, type: String
                  name: Value, type: String
              name: Namespaces, type: List
                name: Item, type: String
              name: TopologyKey, type: String
            name: Weight, type: Int32
...
      name: PodAntiAffinity, type: V1PodAntiAffinity
        name: PreferredDuringSchedulingIgnoredDuringExecution, type: List
          name: Item, type: V1WeightedPodAffinityTerm
            name: PodAffinityTerm, type: V1PodAffinityTerm
              name: LabelSelector, type: V1LabelSelector
                name: MatchExpressions, type: List
                  name: Item, type: V1LabelSelectorRequirement
                    name: Key, type: String
                    name: OperatorProperty, type: String
                    name: Values, type: List
                      name: Item, type: String
                name: MatchLabels, type: Dictionary
                  name: Key, type: String
                  name: Value, type: String
              name: NamespaceSelector, type: V1LabelSelector
                name: MatchExpressions, type: List
                  name: Item, type: V1LabelSelectorRequirement
                    name: Key, type: String
                    name: OperatorProperty, type: String
                    name: Values, type: List
                      name: Item, type: String
                name: MatchLabels, type: Dictionary
                  name: Key, type: String
                  name: Value, type: String
              name: Namespaces, type: List
                name: Item, type: String
              name: TopologyKey, type: String
            name: Weight, type: Int32
.....
    name: EphemeralContainerStatuses, type: List
      name: Item, type: V1ContainerStatus
        name: AllocatedResources, type: Dictionary
          name: Key, type: String
          name: ResourceQuantity, type: ResourceQuantity
            name: Format, type: SuffixFormat
            name: Value, type: String
        name: ContainerID, type: String
        name: Image, type: String
        name: ImageID, type: String
        name: LastState, type: V1ContainerState
          name: Running, type: V1ContainerStateRunning
            name: StartedAt, type: DateTime?
          name: Terminated, type: V1ContainerStateTerminated
            name: ContainerID, type: String
            name: ExitCode, type: Int32
            name: FinishedAt, type: DateTime?
            name: Message, type: String
            name: Reason, type: String
            name: Signal, type: Int32?
            name: StartedAt, type: DateTime?
          name: Waiting, type: V1ContainerStateWaiting
            name: Message, type: String
            name: Reason, type: String
        name: Name, type: String
        name: Ready, type: Boolean
        name: Resources, type: V1ResourceRequirements
          name: Claims, type: List
            name: Item, type: V1ResourceClaim
              name: Name, type: String
          name: Limits, type: Dictionary
            name: Key, type: String
            name: ResourceQuantity, type: ResourceQuantity
              name: Format, type: SuffixFormat
              name: Value, type: String
          name: Requests, type: Dictionary
            name: Key, type: String
            name: ResourceQuantity, type: ResourceQuantity
              name: Format, type: SuffixFormat
              name: Value, type: String
        name: RestartCount, type: Int32
        name: Started, type: Boolean?
        name: State, type: V1ContainerState
          name: Running, type: V1ContainerStateRunning
            name: StartedAt, type: DateTime?
          name: Terminated, type: V1ContainerStateTerminated
            name: ContainerID, type: String
            name: ExitCode, type: Int32
            name: FinishedAt, type: DateTime?
            name: Message, type: String
            name: Reason, type: String
            name: Signal, type: Int32?
            name: StartedAt, type: DateTime?
          name: Waiting, type: V1ContainerStateWaiting
            name: Message, type: String
            name: Reason, type: String
    name: HostIP, type: String
...
    name: NominatedNodeName, type: String
    name: Phase, type: String
    name: PodIP, type: String
    name: PodIPs, type: List
      name: Item, type: V1PodIP
        name: Ip, type: String
    name: QosClass, type: String
    name: Reason, type: String
    name: Resize, type: String
    name: StartTime, type: DateTime?

-Filter

  • Client-side JSONPath object filter(s) to apply to the result set.

  • â„šī¸ This is not equivalent to kubectl's JSONPath functionality. As far as I understand it, kubectl's JSONPath functionality has to do with formatting output, selecting portions of the text output returned. This parameter's purpose is for the filtering of objects: reducing the set of objects returned, but you still get the entire object back which can then be manipulated via PowerShell's object manipulation functionality. PowerShell has much more powerful object property parsing capabilities than that offered by JSONPath.

  • â„šī¸ I originally added this functionality to filter objects. If you prefer JSONPath syntax to PowerShell's functionality, this is here for your use.

  • âš ī¸ Because System.Text.Json does not support JSONPath, this functionality is implemented using Newtonsoft.Json which is not a full implementation of JSONPath syntax. If the JSONPath cannot be parsed by Newtonsoft, an exception will be thrown. In this case, an error is logged, and the object is considered to have not matched.

  • Arguments

    • Single JSONPath - the JSONPath will be evaluated against each object received from the server and only those which match will be returned to the client.
      e.g. match only those pods which have a metadata/name field:
      Get-Pods - Filter "$..['Metadata']['Name']"
    • Multiple JSONPath - each JSONPath provided will be evaluated against each object received from the server and only those which match every JSONPath will be returned to the client.
      e.g. match only those pods with have a metadata/name field AND have a container port of 9042 (note the comma separating the two JSONPath expressions):
      Get-Pods - Filter "$..['Metadata']['Name']", "$..['Spec']..['Containers']..['Ports'][?(@.ContainerPort==9402)]"
    • Compound - a JSON file with an array of arrays can be supplied, where each subarray will be treated as an 'OR' and each of the JSONPaths within any given subarray will be treated as an 'AND' as in the 'Multiple JSONPath' case above.
      Via this feature you can build up arbitrarily complex object filtering libraries.
      The following example JSON will return all objects that have both a Metadata/Name property AND an OwnerReference which matches 'cert-manager', OR objects where the container port is 9402, OR objects that have a container status property of Started equal to false AND a container status property of Ready equal to false.
      {
      "filter": [
        [
          "$..['Metadata']['Name']",
          "$..['Metadata']..['OwnerReferences'][?(@.Name=~/cert-manager/)]"
        ],
        [
          "$..['Spec']..['Containers']..['Ports'][?(@.ContainerPort==9402)]"
        ],
        [
          "$..['Status']..['ContainerStatuses'][?(@.Started==false && @.Ready==false)]" ]
        ]
      }
      One way to pass such a filter to a cmdlet is as follows: Get-Pods -Filter $(Get-Content .\FilterFile.json -Raw).
      Within the JSON the name must be filter and the value must be an array of arrays as above.
  • To learn more about the structure of an object for the purposes of JSONPath filtering, make use of the -AsJson switch parameter.

  • Examples of standard (validated here) -Filter JSONPath expressions for pods and the changes necessary to make them work with Newtonsoft's JSONPath implementation.

    • Should Work but Doesn't Works
      "$.['Metadata'].['ManagedFields'].['FieldsV1'].['ValueKind']" "$..['Metadata']..['ManagedFields']..['FieldsV1']..['ValueKind']"
      "$.['Metadata'].['ManagedFields'][?(@.FieldsV1.ValueKind==1)]" "$..['Metadata'].['ManagedFields'][?(@.FieldsV1.ValueKind==1)]"
      "$.['Spec'].['Containers'].['Ports'][?(@.ContainerPort==9402)]" "$..['Spec']..['Containers']..['Ports'][?(@.ContainerPort==9402)]"
      "$..Metadata.ManagedFields.FieldsV1[?(@.ValueKind==1)]" "$..Metadata.ManagedFields[?(@.FieldsV1.ValueKind==1)]"
Type: String[]
Aliases: f
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
âš ī¸ **GitHub.com Fallback** âš ī¸