Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate docs/tasks/configmap-secret/managing-secret-using-config-file/ into Japanese #27065

Merged
merged 3 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
title: 設定ファイルを使用してSecretを管理する
content_type: task
weight: 20
description: リソース設定ファイルを使用してSecretを作成する
---

<!-- overview -->

## {{% heading "prerequisites" %}}

{{< include "task-tutorial-prereqs.md" >}}

<!-- steps -->

## 設定ファイルを作成する

先にJSONやYAML形式のファイルでSecretを作成してから、そのオブジェクトを作成することができます。
Copy link
Contributor

@YuikoTakada YuikoTakada Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

あらかじめJSONやYAML形式のファイルを作成することで、Secretを作成することができます。

?

Copy link
Member

@inductor inductor Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YuikoTakada I think することで implies a way to do something.「あらかじめJSONやYAML形式のファイルを作成」only says that you can create a YAML/JSON file, which does not mean you can create an actual object, so I would leave it as 「してから」 rather than using 「することで」, because 作成することで~できます sounds like you can create the object just by creating the YAML/JSON file which is not true.

What about something like this

あらかじめYAMLまたはJSON形式でSecretのマニフェストを作成したうえで、オブジェクトを作成することができます。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inductor thank you for your comments.

あらかじめYAMLまたはJSON形式でSecretのマニフェストを作成したうえで、オブジェクトを作成することができます。

It sounds good, thanks.

[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)リソースには、`data`と`stringData`の2つのマップが含まれています。
`data`フィールドは任意のデータを格納するのに使用され、base64でエンコードされます。
`stringData`フィールドは利便性のために用意されており、Secretデータをエンコードされていない文字列として提供することができます。
`data`と`stringData`のキーは、英数字、`-`、`_`、`.`で構成されている必要があります。

たとえば、`data`フィールドを使用して2つの文字列をSecretに格納するには、次のように文字列をbase64に変換します:

```shell
echo -n 'admin' | base64
```

出力は次のようになります:

```
YWRtaW4=
```

```shell
echo -n '1f2d1e2e67df' | base64
```

出力は次のようになります:

```
MWYyZDFlMmU2N2Rm
```

以下のようなSecret設定ファイルを記述します:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm
```

なお、Secretオブジェクトの名前は、有効な[DNSサブドメイン名](/ja/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)である必要があります。

{{< note >}}
SecretデータのシリアライズされたJSONおよびYAMLの値は、base64文字列としてエンコードされます。
これらの文字列の中では、改行は有効ではなく、省略する必要があります。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in https://kubernetes.io/ja/docs/concepts/configuration/secret/ , written as:

シリアライズされたJSONやYAMLの機密データはBase64エンコードされています。 
文字列の中の改行は不正で、含まれていてはなりません。 

I myself prefer Secretデータ rather than 機密データ so I love your translation, but I think 不正な is better than 有効でなく . so I suggest:

SecretデータのシリアライズされたJSONおよびYAMLの値は、base64文字列としてエンコードされます。
文字列の中の改行は不正で、含まれていてはなりません。

How do you thinnk?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd write 文字列中 instead because の~の sounds a bit lengthy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inductor thank you for your comments.
you mean, you prefer 文字列中の改行は不正で、 instead of 文字列の中の改行は不正で、 , right?
it sounds good :)

Darwin/macOSで`base64`ユーティリティーを使用する場合、長い行を分割するために`-b`オプションを使用するのは避けるべきです。
逆に、Linux ユーザーは、`base64` コマンドにオプション`-w 0`を追加するか、`-w`オプションが利用できない場合には、パイプライン`base64 | tr -d '\n'`を追加する*必要があります*。
{{< /note >}}

特定のシナリオでは、代わりに`stringData`フィールドを使用できます。
このフィールドでは、base64エンコードされていない文字列を直接Secretに入れることができ、Secretの作成時や更新時には、その文字列がエンコードされます。

たとえば、設定ファイルを保存するためにSecretを使用しているアプリケーションをデプロイする際に、デプロイプロセス中に設定ファイルの一部を入力したい場合などが考えられます。

たとえば、次のような設定ファイルを使用しているアプリケーションの場合:

```yaml
apiUrl: "https://my.api.com/api/v1"
username: "<user>"
password: "<password>"
```

次のような定義でSecretに格納できます:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
stringData:
config.yaml: |
apiUrl: "https://my.api.com/api/v1"
username: <user>
password: <password>
```

## Secretを作成する

[`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply)でSecretを作成します:

```shell
kubectl apply -f ./secret.yaml
```

出力は次のようになります:

```
secret/mysecret created
```

## Secretを確認する

`stringData`フィールドは、書き込み専用の便利なフィールドです。Secretを取得する際には決して出力されません。たとえば、次のようなコマンドを実行した場合:

```shell
kubectl get secret mysecret -o yaml
```

出力は次のようになります:

```yaml
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: 2018-11-15T20:40:59Z
name: mysecret
namespace: default
resourceVersion: "7225"
uid: c280ad2e-e916-11e8-98f2-025000000001
type: Opaque
data:
config.yaml: YXBpVXJsOiAiaHR0cHM6Ly9teS5hcGkuY29tL2FwaS92MSIKdXNlcm5hbWU6IHt7dXNlcm5hbWV9fQpwYXNzd29yZDoge3twYXNzd29yZH19
```

`kubectl get`と`kubectl describe`コマンドはデフォルトではSecretの内容を表示しません。
これは、Secretが不用意に他人にさらされたり、ターミナルログに保存されたりしないようにするためです。
エンコードされたデータの実際の内容を確認するには、[Secretのデコード](/ja/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret)を参照してください。

`username`などのフィールドが`data`と`stringData`の両方に指定されている場合は、`stringData`の値が使われます。
たとえば、以下のようなSecretの定義の場合:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
stringData:
username: administrator
```

結果は以下の通りです:

```yaml
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: 2018-11-15T20:46:46Z
name: mysecret
namespace: default
resourceVersion: "7579"
uid: 91460ecb-e917-11e8-98f2-025000000001
type: Opaque
data:
username: YWRtaW5pc3RyYXRvcg==
```

`YWRtaW5pc3RyYXRvcg==`をデコードすると`administrator`となります。

## クリーンアップ

作成したSecretを削除するには次のコマンドを実行します:

```shell
kubectl delete secret mysecret
```

## {{% heading "whatsnext" %}}

- [Secretのコンセプト](/ja/docs/concepts/configuration/secret/)を読む
- [kubectlを使用してSecretを管理する](/ja/docs/tasks/configmap-secret/managing-secret-using-kubectl/)方法を知る
- [kustomizeを使用してSecretを管理する](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)方法を知る
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ kubectl delete secret db-user-pass
## {{% heading "whatsnext" %}}

- [Secretのコンセプト](/ja/docs/concepts/configuration/secret/)を読む
- [設定ファイルを使用してSecretを管理する](/docs/tasks/configmap-secret/managing-secret-using-config-file/)方法を知る
- [設定ファイルを使用してSecretを管理する](/ja/docs/tasks/configmap-secret/managing-secret-using-config-file/)方法を知る
- [kustomizeを使用してSecretを管理する](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)方法を知る