LoginSignup
8
5

More than 5 years have passed since last update.

GKEからVPN経由でオンプレにつなげられなかった場合の対処

Posted at

経緯

自社の環境だとGCP+オンプレのハイブリッド(?)な開発環境を使っているのだが、GKEからオンプレの環境に繋がらない問題に直面した

GKE(というかk8s)のネットワークの設定とか調べて何とか解決できたので、同じ問題にあたった人の助けとなるように対処方法を明記しておく

そもそもの原因

原因はk8sのIPマスカレードのデフォルト設定とVPNのLocal IP rangesが被ってたのが原因でした

オンプレ環境につなぎに行く際にはIPマスカレードしてもらいたいのだが、k8sのデフォルトの設定だと、 10.0.0.0/8 の範囲のIPはIPマスカレードの対象外になっていて、VPNのLocal IP rangesがその中に含まれている場合に今回の問題が起こるようです

対処方法

幸運なことに日本語ドキュメントが用意されてたのでそちらを参考に対処を実施した

IP マスカレード エージェント  |  Kubernetes Engine  |  Google Cloud Platform

簡単にいうと、ip-masq-agentをDaemonSetとして起動して、IPマスカレードの設定をConfigMapとして登録してね、ってことみたいです

設定用のyamlファイル作ったので、こちらを kubectl create してもらえればIPマスカレードの設定変更されると思います

kube-system.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ip-masq-agent
  namespace: kube-system
data:
  config: |
    nonMasqueradeCIDRs:
    #   - 10.0.0.0/8
      - 192.168.0.0/16
      - 172.16.0.0/12
    resyncInterval: 60s
---
# https://raw.githubusercontent.com/kubernetes-incubator/ip-masq-agent/master/ip-masq-agent.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: ip-masq-agent
  namespace: kube-system
spec:
  template:
    metadata:
      labels:
        k8s-app: ip-masq-agent
    spec:
      hostNetwork: true
      containers:
      - name: ip-masq-agent
        image: gcr.io/google-containers/ip-masq-agent-amd64:v2.0.0
        securityContext:
          privileged: true
        volumeMounts:
          - name: config
            mountPath: /etc/config
      volumes:
        - name: config
          configMap:
            # Note this ConfigMap must be created in the same namespace as the daemon pods - this spec uses kube-system
            name: ip-masq-agent
            optional: true
            items:
              # The daemon looks for its config in a YAML file at /etc/config/ip-masq-agent
              - key: config
                path: ip-masq-agent
# 設定確認@node(10.0.0.0/8が除外されているのを確認)
# iptables  -t nat -L IP-MASQ-AGENT
Chain IP-MASQ-AGENT (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             169.254.0.0/16       /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
RETURN     all  --  anywhere             192.168.0.0/16       /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
RETURN     all  --  anywhere             172.16.0.0/12        /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
MASQUERADE  all  --  anywhere             anywhere             /* ip-masq-agent: outbound traffic should be subject to MASQUERADE (this match must come after cluster-local CIDR matches) */ ADDRTYPE match dst-type !LOCAL

課題

GCE上のDockerコンテナからオンプレにつなぐ際にはMTUの設定の変更が必要だったのだが、なんか知らんがGKEからの接続の際には特にMTU変更しなくても繋がったので、そのあたり調査したい

8
5
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
8
5