# OpenShiftのSDNトラブルシューティング 以下の例で考えてみる。 * 下記のdeploymentを作成 * frontendデプロイのリソースはpod,service,route * mysqlデプロイのリソースはpod,service | deployment | 概要 | プライベートIP | サービスIP | | -------- | -------- | -------- | -------- | | frontend | フロントエンドアプリケーション | 10.128.10.60 | 172.30.102.30 | | mysql | データベース | 10.128.10.61 | 172.30.102.31 | **起きている問題:** **ブラウザでフロントエンドアプリケーション(172.30.102.30)にアクセスしても`Application is not available`となる** ## frontend podのログを調べる ```shell $ oc logs frondend-xxx App is ready at : 8080 ``` podのログにはエラーは出力されていない。 ## フロントエンドアプリケーションとデータベース間の接続を確認する データベースのIPを取得する。 ```shell $ oc get service/mysql -o jsonpath="{.spec.clusterIP}{'\n'}" 172.30.102.31 ``` フロントエンドのdebug podを立てる。 ```shell $ oc debug -t deployment/frontend Starting pod/frontend-debug ... Pod IP: 10.131.0.144 If you don't see a command prompt, try pressing enter. sh-4.4$ ``` ポート3306を介してデータベースに接続する。 アクセス可能なことを確認してセッションを終了し、debug podから抜ける。 ```shell sh-4.4$ curl -v telnet://172.30.102.31:3306 * About to connect() to 172.30.102.31 port 3306 (#0) * Trying 172.30.102.31 * Connected to 172.30.102.31 (172.30.102.31) port 3306 (#0) J 8.0.21 * RCVD IAC 2 * RCVD IAC 199 ^C sh-4.4$ exit exit Removing debug pod ... ``` ## クラスタ内ネットワークの挙動を確認する フロントエンドサービスのIPを取得する。 ```shell $ oc get service/frontend -o jsonpath="{.spec.clusterIP}{'\n'}" 172.30.102.30 ``` データベースのdebug podを立てる。 ```shell $ oc debug -t deployment/mysql Starting pod/mysql-debug ... Pod IP: 10.131.0.146 If you don't see a command prompt, try pressing enter. sh-4.4$ ``` ポート8080を介してフロントエンドアプリケーションに接続する。 curlがタイムアウトになることを確認してセッションを終了し、debug podから抜ける。 ```shell sh-4.4$ curl -m 10 -v http://172.30.102.30:8080 * Rebuilt URL to: http://172.30.102.30:8080/ * Trying 172.30.102.30... * TCP_NODELAY set * Connection timed out after 10000 milliseconds * Closing connection 0 curl: (28) Connection timed out after 10000 milliseconds sh-4.4$ exit exit Removing debug pod ... ``` ## プライベートIPを介して接続し、serviceに関連する問題か確認する データベースのdebug podを立てる。 ```shell $ oc debug -t deployment/mysql Starting pod/mysql-debug ... Pod IP: 10.131.0.146 If you don't see a command prompt, try pressing enter. sh-4.4$ ``` ポート8080を介してフロントエンドアプリケーションに接続する。 `200 OK`が返ってくることを確認してセッションを終了し、debug podから抜ける。 ```shell sh-4.4$ curl -v http://10.128.10.60:8080/todo/ * Trying 10.128.10.60... * TCP_NODELAY set * Connected to 10.128.10.60 (10.128.10.60) port 8080 (#0) > GET /todo/ HTTP/1.1 > Host: 10.128.10.60:8080 > User-Agent: curl/7.61.1 > Accept: / > < HTTP/1.1 200 OK ...output omitted... sh-4.4$ exit exit Removing debug pod ... $ ``` ## frontendサービスの設定を確認し修正する frontendサービスの設定とステータスを確認する。 ```shell $ oc describe service/frontend Name: frontend Namespace: network-sdn Labels: app=todonodejs name=frontend Annotations: <none> Selector: name=api Type: ClusterIP IP: 172.30.102.30 Port: <unset> 8080/TCP TargetPort: 8080/TCP Endpoints: <none> Session Affinity: None Events: <none> ``` エンドポイントがないため、アプリケーションに受信トラフィックが転送できていないことがわかる。 また、frontendデプロイのラベルを確認すると、上記のサービスの値と異なっていることがわかる。 ```shell $ oc describe deployment/frontend | grep -A1 Labels Labels: app=todonodejs name=frontend -- Labels: app=todonodejs name=frontend ``` frontendサービスを修正して、正しいラベルに設定する。 ```shell $ oc edit service/frontend ...output omitted... selector: name: frontend ...output omitted... service/frontend edited ``` frontendサービスの設定を確認し、サービスにエンドポイントがあることを確かめる。 ```shell $ oc describe service/frontend Name: frontend Namespace: network-sdn Labels: app=todonodejs name=frontend Annotations: <none> Selector: name=frontend Type: ClusterIP IP: 172.30.102.30 Port: <unset> 8080/TCP TargetPort: 8080/TCP Endpoints: 10.128.10.60:8080 Session Affinity: None Events: <none> ``` ブラウザでフロントエンドアプリケーション(172.30.102.30)にアクセスすると、問題が解決できていることを確認。