teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

追記

2018/12/04 10:11

投稿

trafalbad
trafalbad

スコア303

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,33 @@
14
14
  ```
15
15
 
16
16
  ```yaml
17
- # redis_lb.yaml
17
+ # redis_lb_pod.yaml
18
+ apiVersion: extensions/v1beta1
19
+ kind: Deployment
20
+ metadata:
21
+ name: visit-counter
22
+ labels:
23
+ app: visit-counter
24
+ spec:
25
+ replicas: 1
26
+ template:
27
+ metadata:
28
+ labels:
29
+ app: visit-counter
30
+ spec:
31
+ containers:
32
+ - name: visit-counter
33
+ image: "gcr.io/buyma-dev/visit-counter:v1"
34
+ env:
35
+ - name: REDISHOST
36
+ valueFrom:
37
+ configMapKeyRef:
38
+ name: redishost
39
+ key: REDISHOST
40
+ ports:
41
+ - name: http
42
+ containerPort: 8080
43
+ ---
18
44
  apiVersion: v1
19
45
  kind: Service
20
46
  metadata:
@@ -25,43 +51,16 @@
25
51
  app: visit-counter
26
52
  ports:
27
53
  - port: 80
54
+ targetPort: 8080
28
55
  protocol: TCP
29
- targetPort: 8080
30
56
 
31
-
32
- # redis_pod.yaml:
33
- apiVersion: apps/v1
34
- kind: Deployment
35
- metadata:
36
- name: visit-counter
37
- spec:
38
- replicas: 1
39
- selector:
40
- matchLabels:
41
- app: visit-counter
42
- template:
43
- metadata:
44
- labels:
45
- app: visit-counter
46
- spec:
47
- containers:
48
- - name: visit-counter
49
- image: gcr.io/buyma-dev/visit-counter:v1
50
- env:
51
- - name: REDISHOST
52
- valueFrom:
53
- configMapKeyRef:
54
- name: redishost
55
- key: REDISHOST
56
- ports:
57
- - containerPort: 8080
58
-
59
57
  ```
60
58
 
61
59
  ```txt
62
60
  # Dockerfile
63
61
  FROM gcr.io/google_appengine/python
64
62
 
63
+
65
64
  RUN virtualenv -p python3.4 /env
66
65
 
67
66
  ENV VIRTUAL_ENV /env
@@ -79,10 +78,14 @@
79
78
  # Add application code.
80
79
  ADD . /app
81
80
 
81
+ EXPOSE 8080
82
+
82
83
  CMD ["gunicorn", "-b", "0.0.0.0:8080", "main:app"]
83
84
 
84
85
 
85
86
 
87
+
88
+
86
89
  # requirements.txt
87
90
  Flask==1.0.2
88
91
  gunicorn==19.9.0
@@ -100,11 +103,8 @@
100
103
 
101
104
  app = Flask(__name__)
102
105
 
103
- redis_host = os.environ.get('REDISHOST', 'localhost')
104
- redis_port = int(os.environ.get('REDISPORT', 6379))
105
- redis_client = redis.StrictRedis(host=redis_host, port=redis_port)
106
+ redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
106
107
 
107
-
108
108
  @app.route('/')
109
109
  def index():
110
110
  value = redis_client.incr('counter', 1)
@@ -121,10 +121,7 @@
121
121
 
122
122
 
123
123
  if __name__ == '__main__':
124
- # This is used when running locally. Gunicorn is used to run the
125
- # application on Google App Engine. See entrypoint in app.yaml.
126
- app.run(host='0.0.0.0', port=8080, debug=True)
124
+ app.run(host='0.0.0.0')
127
-
128
125
  ```
129
126
 
130
127
  ```yaml
@@ -144,5 +141,4 @@
144
141
  # update with Redis instance network name
145
142
  network:
146
143
  name: default
147
-
148
144
  ```

3

修正

2018/12/04 10:11

投稿

trafalbad
trafalbad

スコア303

title CHANGED
File without changes
body CHANGED
@@ -25,35 +25,37 @@
25
25
  app: visit-counter
26
26
  ports:
27
27
  - port: 80
28
+ protocol: TCP
28
29
  targetPort: 8080
29
- protocol: TCP
30
30
 
31
+
31
- # redis_pod.yaml
32
+ # redis_pod.yaml:
32
- apiVersion: extensions/v1beta1
33
+ apiVersion: apps/v1
33
34
  kind: Deployment
34
35
  metadata:
35
36
  name: visit-counter
36
- labels:
37
- app: visit-counter
38
37
  spec:
39
38
  replicas: 1
39
+ selector:
40
+ matchLabels:
41
+ app: visit-counter
40
42
  template:
41
43
  metadata:
42
44
  labels:
43
45
  app: visit-counter
44
46
  spec:
45
47
  containers:
46
- - name: visit-counter
48
+ - name: visit-counter
47
- image: "gcr.io/sturdy-willow-167902/visit-counter:v1"
49
+ image: gcr.io/buyma-dev/visit-counter:v1
48
- env:
50
+ env:
49
- - name: REDISHOST
51
+ - name: REDISHOST
50
- valueFrom:
52
+ valueFrom:
51
- configMapKeyRef:
53
+ configMapKeyRef:
52
- name: redishost
54
+ name: redishost
53
- key: REDISHOST
55
+ key: REDISHOST
54
- ports:
56
+ ports:
55
- - name: http
56
- containerPort: 8080
57
+ - containerPort: 8080
58
+
57
59
  ```
58
60
 
59
61
  ```txt
@@ -67,17 +69,17 @@
67
69
 
68
70
  # Note: REDISHOST value here is only used for local testing
69
71
  # See README.md on how to inject environment variable as ConfigMap on GKE
70
-
71
72
  ENV REDISHOST 10.0.0.3
72
73
  ENV REDISPORT 6379
73
74
 
74
-
75
+ # Install dependencies.
75
76
  ADD requirements.txt /app/requirements.txt
76
77
  RUN pip install -r /app/requirements.txt
77
78
 
79
+ # Add application code.
78
80
  ADD . /app
79
81
 
80
- CMD ["gunicorn", "-b", "0.0.0.0:6379", "main:app"]
82
+ CMD ["gunicorn", "-b", "0.0.0.0:8080", "main:app"]
81
83
 
82
84
 
83
85
 
@@ -97,14 +99,18 @@
97
99
  import redis
98
100
 
99
101
  app = Flask(__name__)
100
- # ホスト、ポート
101
- redis_client = redis.StrictRedis(host='10.0.0.3', port=6379)
102
102
 
103
+ redis_host = os.environ.get('REDISHOST', 'localhost')
104
+ redis_port = int(os.environ.get('REDISPORT', 6379))
105
+ redis_client = redis.StrictRedis(host=redis_host, port=redis_port)
106
+
107
+
103
108
  @app.route('/')
104
109
  def index():
105
110
  value = redis_client.incr('counter', 1)
106
111
  return 'Visitor number: {}'.format(value)
107
112
 
113
+
108
114
  @app.errorhandler(500)
109
115
  def server_error(e):
110
116
  logging.exception('An error occurred during a request.')
@@ -113,27 +119,30 @@
113
119
  See logs for full stacktrace.
114
120
  """.format(e), 500
115
121
 
122
+
116
123
  if __name__ == '__main__':
124
+ # This is used when running locally. Gunicorn is used to run the
125
+ # application on Google App Engine. See entrypoint in app.yaml.
117
- app.run(host='10.0.0.3', port=6379, debug=True)
126
+ app.run(host='0.0.0.0', port=8080, debug=True)
127
+
118
128
  ```
119
129
 
120
130
  ```yaml
121
131
  # app.yaml
122
132
  runtime: python
123
133
  env: flex
124
- entrypoint: gunicorn -b 0.0.0.0:6379 main:app
134
+ entrypoint: gunicorn -b :$PORT main:app
125
135
 
126
136
  runtime_config:
127
137
  python_version: 3
128
138
 
129
139
  # update with Redis instance host IP, port
130
140
  env_variables:
131
- REDISHOST: 10.0.0.3
141
+ REDISHOST: 10.0.0.3
132
142
  REDISPORT: 6379
133
143
 
134
144
  # update with Redis instance network name
135
145
  network:
136
146
  name: default
137
147
 
138
-
139
148
  ```

2

追記

2018/12/03 09:29

投稿

trafalbad
trafalbad

スコア303

title CHANGED
@@ -1,1 +1,1 @@
1
- GCPで作成したインスタンスのHOSTとPORTを確認する方法
1
+ redisのインスタンスにアクセスできないエラー'Connection refused'について
body CHANGED
@@ -1,10 +1,139 @@
1
- GCPGUIで作成したVMインスタンスのhostport確認したのですが
1
+ GKEのkubernetes[redisインスタンスとクラスタ結合するチュートリアル](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-gke)通りにEXTERNAL-IPでアクセスしたのですが、下のようなエラーが出てしまいます
2
2
 
3
- GUIで「mlops」というインスタンスを作成して、下記コマンドで下記したのですが、確認できませんでした。
4
- ```linux
5
- gcloud compute instances describe <instance name>
6
- => gcloud compute instances describe mlops
7
3
  ```
4
+ $ curl http://35.200.67.203
5
+ >>>
6
+ curl: (7) Failed to connect to 35.200.67.203 port 80: Connection refused
7
+ ```
8
8
 
9
+ ファイルは下のような構成と内容になってます。おそらくserviceを定義しているロードバランサに問題があるかと思うのですが、理由がわかりません。ご教授お願いします
10
+
11
+ ファイル一覧
12
+ ```
13
+ app.yaml Dockerfile main.py redis_lb.yaml redis_pod.yaml requirements.txt
14
+ ```
15
+
16
+ ```yaml
17
+ # redis_lb.yaml
18
+ apiVersion: v1
19
+ kind: Service
20
+ metadata:
21
+ name: visit-counter
22
+ spec:
23
+ type: LoadBalancer
24
+ selector:
25
+ app: visit-counter
26
+ ports:
27
+ - port: 80
28
+ targetPort: 8080
29
+ protocol: TCP
30
+
31
+ # redis_pod.yaml
32
+ apiVersion: extensions/v1beta1
33
+ kind: Deployment
34
+ metadata:
35
+ name: visit-counter
36
+ labels:
37
+ app: visit-counter
38
+ spec:
39
+ replicas: 1
40
+ template:
41
+ metadata:
42
+ labels:
43
+ app: visit-counter
44
+ spec:
45
+ containers:
46
+ - name: visit-counter
47
+ image: "gcr.io/sturdy-willow-167902/visit-counter:v1"
48
+ env:
49
+ - name: REDISHOST
50
+ valueFrom:
51
+ configMapKeyRef:
52
+ name: redishost
53
+ key: REDISHOST
54
+ ports:
55
+ - name: http
56
+ containerPort: 8080
57
+ ```
58
+
59
+ ```txt
60
+ # Dockerfile
61
+ FROM gcr.io/google_appengine/python
62
+
9
- GUIで作成したインスタンスの詳細を確認するにはどうしたら良いでしょうか?
63
+ RUN virtualenv -p python3.4 /env
64
+
65
+ ENV VIRTUAL_ENV /env
66
+ ENV PATH /env/bin:$PATH
67
+
68
+ # Note: REDISHOST value here is only used for local testing
69
+ # See README.md on how to inject environment variable as ConfigMap on GKE
70
+
71
+ ENV REDISHOST 10.0.0.3
72
+ ENV REDISPORT 6379
73
+
74
+
75
+ ADD requirements.txt /app/requirements.txt
76
+ RUN pip install -r /app/requirements.txt
77
+
78
+ ADD . /app
79
+
80
+ CMD ["gunicorn", "-b", "0.0.0.0:6379", "main:app"]
81
+
82
+
83
+
84
+ # requirements.txt
85
+ Flask==1.0.2
86
+ gunicorn==19.9.0
87
+ redis==3.0.1
88
+ ```
89
+
90
+
10
- ご教授お願いします
91
+ ```python
92
+ # main.py
93
+ import logging
94
+ import os
95
+
96
+ from flask import Flask
97
+ import redis
98
+
99
+ app = Flask(__name__)
100
+ # ホスト、ポート
101
+ redis_client = redis.StrictRedis(host='10.0.0.3', port=6379)
102
+
103
+ @app.route('/')
104
+ def index():
105
+ value = redis_client.incr('counter', 1)
106
+ return 'Visitor number: {}'.format(value)
107
+
108
+ @app.errorhandler(500)
109
+ def server_error(e):
110
+ logging.exception('An error occurred during a request.')
111
+ return """
112
+ An internal error occurred: <pre>{}</pre>
113
+ See logs for full stacktrace.
114
+ """.format(e), 500
115
+
116
+ if __name__ == '__main__':
117
+ app.run(host='10.0.0.3', port=6379, debug=True)
118
+ ```
119
+
120
+ ```yaml
121
+ # app.yaml
122
+ runtime: python
123
+ env: flex
124
+ entrypoint: gunicorn -b 0.0.0.0:6379 main:app
125
+
126
+ runtime_config:
127
+ python_version: 3
128
+
129
+ # update with Redis instance host IP, port
130
+ env_variables:
131
+ REDISHOST: 10.0.0.3
132
+ REDISPORT: 6379
133
+
134
+ # update with Redis instance network name
135
+ network:
136
+ name: default
137
+
138
+
139
+ ```

1

追記

2018/12/01 14:01

投稿

trafalbad
trafalbad

スコア303

title CHANGED
@@ -1,1 +1,1 @@
1
- GKEのkubernetes上pythonコードわ動かす方法
1
+ GCP作成したインスタンスのHOSTとPORTを確認方法
body CHANGED
@@ -1,4 +1,10 @@
1
- GKEのkubernetes上でコードを動かし、負荷分散したIPアドレスでアクセスしたら結果が返ってくるようにしたいのですが、下記のサイトを試したのですが、上手く行きません。
2
- 何か参考になるサイトや情報等ご存知でしたらご教授お願い
1
+ GCPGUIで作成したVMインスタンスのhostとportを確認たいので
3
2
 
3
+ GUIで「mlops」というインスタンスを作成して、下記コマンドで下記したのですが、確認できませんでした。
4
+ ```linux
4
- https://cloud.google.com/memorystore/docs/redis/quickstart-gcloud
5
+ gcloud compute instances describe <instance name>
6
+ => gcloud compute instances describe mlops
7
+ ```
8
+
9
+ GUIで作成したインスタンスの詳細を確認するにはどうしたら良いでしょうか?
10
+ ご教授お願いします