0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellでkubectlの結果をjqで整形するまで

Posted at

これは何

KubernetesのNodeのTaintsだけをバーッと見たいけど現時点では良いコマンドが無いので、jqkubectl describe nodeから整形する。
WindowsのPowerShellで実現したい。

全体

  1. PowerShellでchocolateyをインストールする
  2. chocolateyjqをインストールする
  3. kubectl describe nodeの結果をjqで整形する

PowerShellでchocolateyをインストールする

PowerShellを管理者として実行

省略

公式サイトに従いchocolateyをインストールする

公式
https://chocolatey.org/install

Step2のindividualを参照

PS C:\WINDOWS\system32> Get-ExecutionPolicy
Restricted

Restrictedが返ってきた場合」の手順もあるので、従う

PS C:\WINDOWS\system32> Set-ExecutionPolicy AllSigned
PS C:\WINDOWS\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

これでインストール完了

動作確認

PS C:\WINDOWS\system32> choco
Chocolatey v0.10.15
Please run 'choco -?' or 'choco <command> -?' for help menu.

chocolateyjqをインストールする

公式サイトに従いjqをインストールする

公式
https://stedolan.github.io/jq/download/

PS C:\WINDOWS\system32> chocolatey install jq

動作確認

PS C:\WINDOWS\system32> jq
jq - commandline JSON processor [version 1.6]

Usage:  C:\ProgramData\chocolatey\lib\jq\tools\jq.exe [options] <jq filter> [file...]
        C:\ProgramData\chocolatey\lib\jq\tools\jq.exe [options] --args <jq filter> [strings...]
        C:\ProgramData\chocolatey\lib\jq\tools\jq.exe [options] --jsonargs <jq filter> [JSON_TEXTS...]

jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.

The simplest filter is ., which copies jq's input to its output
unmodified (except for formatting, but note that IEEE754 is used
for number representation internally, with all that that implies).

For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq

Example:

        $ echo '{"foo": 0}' | jq .
        {
                "foo": 0
        }

For a listing of options, use C:\ProgramData\chocolatey\lib\jq\tools\jq.exe --help.

kubectl describe nodeの結果をjqで整形する

とりあえず各NodeのNode名とTaintsを表示してみる。

PS C:\WINDOWS\system32> kubectl get nodes -o json | jq ".items[]|{name:.metadata.name, taints:.spec.taints}"
{
  "name": "ip-10-0-1-174.us-east-2.compute.internal",
  "taints": null
}
{
  "name": "ip-10-0-54-134.us-east-2.compute.internal",
  "taints": [
    {
      "effect": "NoSchedule",
      "key": "dedicated",
      "value": "groupName"
    }
  ]
}
{
  "name": "ip-10-0-91-149.us-east-2.compute.internal",
  "taints": null
}

おわり

taintsを取得するコマンドはなぜ無いのだろう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?