カタログにあるtemplateの中身を確認したい

# はじめに

カタログにあるテンプレートの内容を参考にしたいことってありますよね。
特にカタログにあるテンプレートで作成したPodを束ねて１つのサービスにする等といった場合です

# openshiftのtempalte確認

以下のコマンドでopenshiftのテンプレート名を取得できます。

```bash
[tak@centos76 ~]$ eval $(minishift oc-env)
[tak@centos76 ~]$ oc get -n openshift templates
NAME                       DESCRIPTION                                                                        PARAMETERS        OBJECTS
cakephp-mysql-persistent   An example CakePHP application with a MySQL database. For more information ab...   20 (4 blank)      9
dancer-mysql-persistent    An example Dancer application with a MySQL database. For more information abo...   17 (5 blank)      9
django-psql-persistent     An example Django application with a PostgreSQL database. For more informatio...   20 (5 blank)      9
jenkins-ephemeral          Jenkins service, without persistent storage....                                    7 (all set)       6
jenkins-pipeline-example   This example showcases the new Jenkins Pipeline integration in OpenShift,...       16 (4 blank)      8
mariadb-persistent         MariaDB database service, with persistent storage. For more information about...   9 (3 generated)   4
mongodb-persistent         MongoDB database service, with persistent storage. For more information about...   9 (3 generated)   4
mysql-persistent           MySQL database service, with persistent storage. For more information about u...   9 (3 generated)   4
nodejs-mongo-persistent    An example Node.js application with a MongoDB database. For more information...    19 (4 blank)      9
postgresql-persistent      PostgreSQL database service, with persistent storage. For more information ab...   8 (2 generated)   4
rails-pgsql-persistent     An example Rails application with a PostgreSQL database. For more information...   21 (4 blank)      9
```

# tempalteをyamlに書きだす
templateの名前を確認できたら、内容のyamlに出力したいと思います。

```bash
[tak@centos76 ~]$ oc process -o yaml openshift//mariadb-persistent > ~/mariadb-persistent.yml
```

```yaml
apiVersion: v1
items:
- apiVersion: v1
  kind: Secret
  metadata:
    annotations:
      template.openshift.io/expose-database_name: '{.data[''database-name'']}'
      template.openshift.io/expose-password: '{.data[''database-password'']}'
      template.openshift.io/expose-root_password: '{.data[''database-root-password'']}'
      template.openshift.io/expose-username: '{.data[''database-user'']}'
    labels:
      template: mariadb-persistent-template
    name: mariadb
  stringData:
    database-name: sampledb
    database-password: OsUjiIrFcbs0dT3U
    database-root-password: BcC5vcq0SSNjdXgc
    database-user: userIAH
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      template.openshift.io/expose-uri: mysql://{.spec.clusterIP}:{.spec.ports[?(.name=="mariadb")].port}
    labels:
      template: mariadb-persistent-template
    name: mariadb
  spec:
    ports:
    - name: mariadb
      port: 3306
    selector:
      name: mariadb
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    labels:
      template: mariadb-persistent-template
    name: mariadb
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
- apiVersion: apps.openshift.io/v1
  kind: DeploymentConfig
  metadata:
    annotations:
      template.alpha.openshift.io/wait-for-ready: "true"
    labels:
      template: mariadb-persistent-template
    name: mariadb
  spec:
    replicas: 1
    selector:
      name: mariadb
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          name: mariadb
      spec:
        containers:
        - env:
          - name: MYSQL_USER
            valueFrom:
              secretKeyRef:
                key: database-user
                name: mariadb
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                key: database-password
                name: mariadb
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                key: database-root-password
                name: mariadb
          - name: MYSQL_DATABASE
            valueFrom:
              secretKeyRef:
                key: database-name
                name: mariadb
          image: ' '
          imagePullPolicy: IfNotPresent
          livenessProbe:
            initialDelaySeconds: 30
            tcpSocket:
              port: 3306
            timeoutSeconds: 1
          name: mariadb
          ports:
          - containerPort: 3306
          readinessProbe:
            exec:
              command:
              - /bin/sh
              - -i
              - -c
              - MYSQL_PWD="$MYSQL_PASSWORD" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE
                -e 'SELECT 1'
            initialDelaySeconds: 5
            timeoutSeconds: 1
          resources:
            limits:
              memory: 512Mi
          volumeMounts:
          - mountPath: /var/lib/mysql/data
            name: mariadb-data
        volumes:
        - name: mariadb-data
          persistentVolumeClaim:
            claimName: mariadb
    triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
        - mariadb
        from:
          kind: ImageStreamTag
          name: mariadb:10.2
          namespace: openshift
      type: ImageChange
    - type: ConfigChange
kind: List
metadata: {}
```

# tempalteをjsonに書きだす
templateの名前を確認できたら、内容のjsonに出力したいと思います。

```bash
[tak@centos76 ~]$ oc process -o json openshift//mariadb-persistent > ~/mariadb-persistent.json
```

```json
{
    "kind": "List",
    "apiVersion": "v1",
    "metadata": {},
    "items": [
        {
            "apiVersion": "v1",
            "kind": "Secret",
            "metadata": {
                "annotations": {
                    "template.openshift.io/expose-database_name": "{.data['database-name']}",
                    "template.openshift.io/expose-password": "{.data['database-password']}",
                    "template.openshift.io/expose-root_password": "{.data['database-root-password']}",
                    "template.openshift.io/expose-username": "{.data['database-user']}"
                },
                "labels": {
                    "template": "mariadb-persistent-template"
                },
                "name": "mariadb"
            },
            "stringData": {
                "database-name": "sampledb",
                "database-password": "dI8EmieQ1V5LX2Lk",
                "database-root-password": "JBkm3jLT2t7M076F",
                "database-user": "user17P"
            }
        },
        {
            "apiVersion": "v1",
            "kind": "Service",
            "metadata": {
                "annotations": {
                    "template.openshift.io/expose-uri": "mysql://{.spec.clusterIP}:{.spec.ports[?(.name==\"mariadb\")].port}"
                },
                "labels": {
                    "template": "mariadb-persistent-template"
                },
                "name": "mariadb"
            },
            "spec": {
                "ports": [
                    {
                        "name": "mariadb",
                        "port": 3306
                    }
                ],
                "selector": {
                    "name": "mariadb"
                }
            }
        },
        {
            "apiVersion": "v1",
            "kind": "PersistentVolumeClaim",
            "metadata": {
                "labels": {
                    "template": "mariadb-persistent-template"
                },
                "name": "mariadb"
            },
            "spec": {
                "accessModes": [
                    "ReadWriteOnce"
                ],
                "resources": {
                    "requests": {
                        "storage": "1Gi"
                    }
                }
            }
        },
        {
            "apiVersion": "apps.openshift.io/v1",
            "kind": "DeploymentConfig",
            "metadata": {
                "annotations": {
                    "template.alpha.openshift.io/wait-for-ready": "true"
                },
                "labels": {
                    "template": "mariadb-persistent-template"
                },
                "name": "mariadb"
            },
            "spec": {
                "replicas": 1,
                "selector": {
                    "name": "mariadb"
                },
                "strategy": {
                    "type": "Recreate"
                },
                "template": {
                    "metadata": {
                        "labels": {
                            "name": "mariadb"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "env": [
                                    {
                                        "name": "MYSQL_USER",
                                        "valueFrom": {
                                            "secretKeyRef": {
                                                "key": "database-user",
                                                "name": "mariadb"
                                            }
                                        }
                                    },
                                    {
                                        "name": "MYSQL_PASSWORD",
                                        "valueFrom": {
                                            "secretKeyRef": {
                                                "key": "database-password",
                                                "name": "mariadb"
                                            }
                                        }
                                    },
                                    {
                                        "name": "MYSQL_ROOT_PASSWORD",
                                        "valueFrom": {
                                            "secretKeyRef": {
                                                "key": "database-root-password",
                                                "name": "mariadb"
                                            }
                                        }
                                    },
                                    {
                                        "name": "MYSQL_DATABASE",
                                        "valueFrom": {
                                            "secretKeyRef": {
                                                "key": "database-name",
                                                "name": "mariadb"
                                            }
                                        }
                                    }
                                ],
                                "image": " ",
                                "imagePullPolicy": "IfNotPresent",
                                "livenessProbe": {
                                    "initialDelaySeconds": 30,
                                    "tcpSocket": {
                                        "port": 3306
                                    },
                                    "timeoutSeconds": 1
                                },
                                "name": "mariadb",
                                "ports": [
                                    {
                                        "containerPort": 3306
                                    }
                                ],
                                "readinessProbe": {
                                    "exec": {
                                        "command": [
                                            "/bin/sh",
                                            "-i",
                                            "-c",
                                            "MYSQL_PWD=\"$MYSQL_PASSWORD\" mysql -h 127.0.0.1 -u $MYSQL_USER -D $MYSQL_DATABASE -e 'SELECT 1'"
                                        ]
                                    },
                                    "initialDelaySeconds": 5,
                                    "timeoutSeconds": 1
                                },
                                "resources": {
                                    "limits": {
                                        "memory": "512Mi"
                                    }
                                },
                                "volumeMounts": [
                                    {
                                        "mountPath": "/var/lib/mysql/data",
                                        "name": "mariadb-data"
                                    }
                                ]
                            }
                        ],
                        "volumes": [
                            {
                                "name": "mariadb-data",
                                "persistentVolumeClaim": {
                                    "claimName": "mariadb"
                                }
                            }
                        ]
                    }
                },
                "triggers": [
                    {
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "mariadb"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "name": "mariadb:10.2",
                                "namespace": "openshift"
                            }
                        },
                        "type": "ImageChange"
                    },
                    {
                        "type": "ConfigChange"
                    }
                ]
            }
        }
    ]
}
```