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?

kubernetes入門 - Part4 - jsonnetを使ってみよう(jsonnet⇒json⇒yaml)

Posted at

ダウンロード、解凍、Path追加

  1. これをダウンロード
  2. 7zipでtar.gzを解凍し、用意した任意のディレクトリ(例えば、tools)とかに配置
  3. システム環境変数のPathに追加

インストール確認として、バージョン確認

C:\Users\abc>jsonnet --version
Jsonnet commandline interpreter (Go implementation) v0.20.0

サンプルjsonnet

test.jsonnet
{
  configMaps: [
    {
      name: "config-" + std.toString(i),
      data: { "val": std.toString(i * 2) }
    }
    for i in std.range(1, 3)
  ]
}

configmap作成

jsonnet test.jsonnet > configmap.json

こんなやつができました。環境別に設定ファイルとか作るときに便利そうです。

configmap.json
{
   "configMaps": [
      {
         "data": {
            "val": "2"
         },
         "name": "config-1"
      },
      {
         "data": {
            "val": "4"
         },
         "name": "config-2"
      },
      {
         "data": {
            "val": "6"
         },
         "name": "config-3"
      }
   ]
}

jsonnetからyamlを作るために、yqをインストール

ここからyq_windows_amd64.exeをダウンロードし、jsonnet同様、システム環境変数のPathに追加
※ファイル名はyq.exeに変更しておく

バージョン確認

C:\Users\abc>yq --version
yq (https://github.com/mikefarah/yq/) version v4.45.4

jsonnetからyaml作成

jsonnet example.jsonnet | yq -P > configmap.yaml

こんなyamlができました。

configmap.yaml
configMaps:
  - data:
      val: "2"
    name: config-1
  - data:
      val: "4"
    name: config-2
  - data:
      val: "6"
    name: config-3
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?