2017-08-23 22 views
0

RancherOS v1.0.3で動作する2つのコンテナ(GitLabとPostgreSQL)があります。私はそれらをクーベルネット集団の一部にしたいと思います。KubernetesでDockerコンテナの実行パラメータを渡す

[[email protected] ~]$ cat postgresql.sh 
docker run --name gitlab-postgresql -d \ 
    --env 'POSTGRES_DB=gitlabhq_production' \ 
    --env 'POSTGRES_USER=gitlab' --env 'POSTGRES_PASSWORD=password' \ 
    --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \ 
    postgres:9.6-2 


[[email protected] ~]$ cat gitlab.sh 
docker run --name gitlab -d \ 
    --link gitlab-postgresql:postgresql \ 
    --publish 443:443 --publish 80:80 \ 
    --env 'GITLAB_PORT=80' --env 'GITLAB_SSH_PORT=10022' \ 
    --env 'GITLAB_SECRETS_DB_KEY_BASE=64-char-key-A' \ 
    --env 'GITLAB_SECRETS_SECRET_KEY_BASE=64-char-key-B' \ 
    --env 'GITLAB_SECRETS_OTP_KEY_BASE=64-char-key-C' \ 
    --volume /srv/docker/gitlab/gitlab:/home/git/data \ 
    sameersbn/gitlab:9.4.5 

クエリ:
1)私が提供ポッド、複製コントローラなどにYAMLファイルを使用する方法についていくつかのアイデアを持っているが、私はそれが適用できるようにKubernetesに上記docker runパラメータを渡す方法を確認していません同じものを正しく描写する。

2)--link引数(上記のgitlab.shで使用されています)をKubernetesに渡す必要があるかどうかはわかりません。私は現在、両方のコンテナを単一のホストに配置していますが、後で(PostgreSQLとGitLab)それぞれのクラスタを作成する予定ですが、ホスト間通信が自動的にKubernetesによって処理されるかどうかを確認したいだけです。もしそうでなければ、どのような選択肢が探求できるのでしょうか?

答えて

3

まず、実行文をdocker-compose.ymlファイルに記述してください。これは非常に簡単であり、それは今あなたのための変換部を行いkompose.ioから素晴らしいツール名komposeがある

version: '3' 

services: 
    postgresql: 
    image: postgres:9.6-2 
    environment: 
     - "POSTGRES_DB=gitlabhq_production" 
     - "POSTGRES_USER=gitlab" 
     - "POSTGRES_PASSWORD=password" 
    volumes: 
     - /srv/docker/gitlab/postgresql:/var/lib/postgresql 
    gitlab: 
    image: sameersbn/gitlab:9.4.5 
    ports: 
     - "443:443" 
     - "80:80" 
    environment: 
     - "GITLAB_PORT=80" 
     - "GITLAB_SSH_PORT=10022" 
     - "GITLAB_SECRETS_DB_KEY_BASE=64-char-key-A" 
     - "GITLAB_SECRETS_SECRET_KEY_BASE=64-char-key-B" 
     - "GITLAB_SECRETS_OTP_KEY_BASE=64-char-key-C" 
    volumes: 
     - /srv/docker/gitlab/gitlab:/home/git/data 

以下のようなものを入れます。あなたは上記の関連ファイル

$ kompose convert -f docker-compose.yml 
WARN Volume mount on the host "/srv/docker/gitlab/gitlab" isn't supported - ignoring path on the host 
WARN Volume mount on the host "/srv/docker/gitlab/postgresql" isn't supported - ignoring path on the host 
INFO Kubernetes file "gitlab-service.yaml" created 
INFO Kubernetes file "postgresql-service.yaml" created 
INFO Kubernetes file "gitlab-deployment.yaml" created 
INFO Kubernetes file "gitlab-claim0-persistentvolumeclaim.yaml" created 
INFO Kubernetes file "postgresql-deployment.yaml" created 
INFO Kubernetes file "postgresql-claim0-persistentvolumeclaim.yaml" created 

を取得します変換する場合今、あなたは、ボリュームを修正する必要がkubernetesごとにパーツを取り付けます。これは仕事の80%を完了し、あなただけのあなただけの

==> gitlab-claim0-persistentvolumeclaim.yaml <== 
apiVersion: v1 
kind: PersistentVolumeClaim 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: gitlab-claim0 
    name: gitlab-claim0 
spec: 
    accessModes: 
    - ReadWriteOnce 
    resources: 
    requests: 
     storage: 100Mi 
status: {} 

==> gitlab-deployment.yaml <== 
apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: gitlab 
    name: gitlab 
spec: 
    replicas: 1 
    strategy: 
    type: Recreate 
    template: 
    metadata: 
     creationTimestamp: null 
     labels: 
     io.kompose.service: gitlab 
    spec: 
     containers: 
     - env: 
     - name: GITLAB_PORT 
      value: "80" 
     - name: GITLAB_SECRETS_DB_KEY_BASE 
      value: 64-char-key-A 
     - name: GITLAB_SECRETS_OTP_KEY_BASE 
      value: 64-char-key-C 
     - name: GITLAB_SECRETS_SECRET_KEY_BASE 
      value: 64-char-key-B 
     - name: GITLAB_SSH_PORT 
      value: "10022" 
     image: sameersbn/gitlab:9.4.5 
     name: gitlab 
     ports: 
     - containerPort: 443 
     - containerPort: 80 
     resources: {} 
     volumeMounts: 
     - mountPath: /home/git/data 
      name: gitlab-claim0 
     restartPolicy: Always 
     volumes: 
     - name: gitlab-claim0 
     persistentVolumeClaim: 
      claimName: gitlab-claim0 
status: {} 

==> gitlab-service.yaml <== 
apiVersion: v1 
kind: Service 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: gitlab 
    name: gitlab 
spec: 
    ports: 
    - name: "443" 
    port: 443 
    targetPort: 443 
    - name: "80" 
    port: 80 
    targetPort: 80 
    selector: 
    io.kompose.service: gitlab 
status: 
    loadBalancer: {} 

==> postgresql-claim0-persistentvolumeclaim.yaml <== 
apiVersion: v1 
kind: PersistentVolumeClaim 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: postgresql-claim0 
    name: postgresql-claim0 
spec: 
    accessModes: 
    - ReadWriteOnce 
    resources: 
    requests: 
     storage: 100Mi 
status: {} 

==> postgresql-deployment.yaml <== 
apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: postgresql 
    name: postgresql 
spec: 
    replicas: 1 
    strategy: 
    type: Recreate 
    template: 
    metadata: 
     creationTimestamp: null 
     labels: 
     io.kompose.service: postgresql 
    spec: 
     containers: 
     - env: 
     - name: POSTGRES_DB 
      value: gitlabhq_production 
     - name: POSTGRES_PASSWORD 
      value: password 
     - name: POSTGRES_USER 
      value: gitlab 
     image: postgres:9.6-2 
     name: postgresql 
     resources: {} 
     volumeMounts: 
     - mountPath: /var/lib/postgresql 
      name: postgresql-claim0 
     restartPolicy: Always 
     volumes: 
     - name: postgresql-claim0 
     persistentVolumeClaim: 
      claimName: postgresql-claim0 
status: {} 

==> postgresql-service.yaml <== 
apiVersion: v1 
kind: Service 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: postgresql 
    name: postgresql 
spec: 
    clusterIP: None 
    ports: 
    - name: headless 
    port: 55555 
    targetPort: 0 
    selector: 
    io.kompose.service: postgresql 
status: 
    loadBalancer: {} 
+0

おかげで生成されるファイルの種類を見ることができるようにここで

は、すべての生成ファイルの猫で、残りの20%を把握必要説明のためのTarun!私は今20%の領域で立ち往生しています。そのためにGlusterを探検します。ちなみに、「ホスト間通信」(クエリ#2)に関するコメントはありますか? – Technext

+1

Kubernetesが自動的にそれを行います。ラベルセレクタを使用してサービスを検索する必要があり、リンクなどを使用する必要はありません。また、PostgresとGitlabの両方をPODとして実行したい場合は、それを行うことができます。その後、同じネットワーク上にある –

+0

あなたの最後の声明について(あなたがポッドとしてPostgresとGitlabの両方を走らせたいのであれば)、ポッドとしてではなく、どうすればそれらを走らせることができますか?私はポッドが唯一の方法だと思った。クベネテスがどのようにコンテナを管理しているのではないですか?よくわかりません。 – Technext

関連する問題