diff --git a/check-dns.yaml b/check-dns.yaml new file mode 100644 index 0000000..a011e86 --- /dev/null +++ b/check-dns.yaml @@ -0,0 +1,13 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: dns +spec: + template: + spec: + containers: + - name: dns + image: anubhavmishra/tiny-tools + command: ["dig", "consul.service.consul"] + restartPolicy: Never + backoffLimit: 4 diff --git a/consul-dns-fix.yaml b/consul-dns-fix.yaml new file mode 100644 index 0000000..069a6e1 --- /dev/null +++ b/consul-dns-fix.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + addonmanager.kubernetes.io/mode: EnsureExists + name: kube-dns + namespace: kube-system +data: + stubDomains: | + {"consul": ["10.103.17.72"]} diff --git a/consul/server-b-default b/consul/server-b-default new file mode 100644 index 0000000..77ee646 --- /dev/null +++ b/consul/server-b-default @@ -0,0 +1,3 @@ +Kind = "service-defaults" +Name = "server-b" +Protocol = "http" \ No newline at end of file diff --git a/consul/server-b-test-deault b/consul/server-b-test-deault new file mode 100644 index 0000000..63e010c --- /dev/null +++ b/consul/server-b-test-deault @@ -0,0 +1,3 @@ +Kind = "service-defaults" +Name = "server-b-test" +Protocol = "http" \ No newline at end of file diff --git a/consul/server-check-default.hcl b/consul/server-check-default.hcl new file mode 100644 index 0000000..0acae7b --- /dev/null +++ b/consul/server-check-default.hcl @@ -0,0 +1,3 @@ +Kind = "service-defaults" +Name = "server-check" +Protocol = "http" \ No newline at end of file diff --git a/consul/server-check-service.hcl b/consul/server-check-service.hcl index 05c481b..db64007 100644 --- a/consul/server-check-service.hcl +++ b/consul/server-check-service.hcl @@ -2,5 +2,6 @@ { "service": { "name": "server-check" + "protocol": "http" } } \ No newline at end of file diff --git a/deploy.yaml b/deploy.yaml index ce3802a..106cb76 100644 --- a/deploy.yaml +++ b/deploy.yaml @@ -6,6 +6,21 @@ # annotations: # "consul.hashicorp.com/connect-inject": "true" #dit is hoe consul injection handled --- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: account-a +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: account-b +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: account-b-test +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -30,11 +45,11 @@ spec: "consul.hashicorp.com/connect-inject": "true" spec: containers: - - name: front-end - image: beppev/server-a-consul:master + - name: server-a + image: beppev/server-a:master-consul imagePullPolicy: "Always" ports: - - containerPort: 5000 + - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment @@ -62,11 +77,11 @@ spec: "consul.hashicorp.com/connect-inject": "true" spec: containers: - - name: front-end - image: beppev/server-b-consul:master + - name: server-b + image: beppev/server-b:master-consul imagePullPolicy: "Always" ports: - - containerPort: 6000 + - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment @@ -94,11 +109,11 @@ spec: "consul.hashicorp.com/connect-inject": "true" #dit is hoe consul injection handled spec: containers: - - name: front-end - image: beppev/server-b-consul:experimental + - name: server-b-test + image: beppev/server-b:experimental-consul imagePullPolicy: "Always" ports: - - containerPort: 6000 + - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment @@ -124,30 +139,30 @@ spec: "consul.hashicorp.com/connect-inject": "true" #dit is hoe consul injection handled spec: containers: - - name: front-end + - name: server-d image: beppev/server-d-consul:master ports: - - containerPort: 6000 + - containerPort: 80 # --- -# apiVersion: v1 -# kind: Service -# metadata: -# name: expose-service -# # namespace: consul-project-1 -# annotations: -# "consul.hashicorp.com/connect-inject": "true" #dit is hoe consul injection handled -# labels: -# app: "project-1" -# spec: -# selector: -# expose: "true" -# ports: -# - name: http -# protocol: TCP -# port: 5000 -# targetPort: 5000 -# nodePort: 30036 -# type: NodePort +apiVersion: v1 +kind: Service +metadata: + name: expose-service + # namespace: consul-project-1 + annotations: + "consul.hashicorp.com/connect-inject": "true" #dit is hoe consul injection handled + labels: + app: "project-1" +spec: + selector: + expose: "true" + ports: + - name: http + protocol: TCP + port: 80 + targetPort: 80 + nodePort: 30036 + type: NodePort # --- # apiVersion: v1 # kind: Service diff --git a/helm-consul-values.yaml b/helm-consul-values.yaml index 4191114..8d35603 100644 --- a/helm-consul-values.yaml +++ b/helm-consul-values.yaml @@ -18,8 +18,6 @@ client: # Use only one Consul server for local development server: - service: - type: 'NodePort' replicas: 1 bootstrapExpect: 1 disruptionBudget: diff --git a/serverA/app.py b/serverA/app.py index 1fb7633..ab9f2c1 100644 --- a/serverA/app.py +++ b/serverA/app.py @@ -3,7 +3,7 @@ import requests app = Flask(__name__) -URL = "http://server-check:6000" +URL = "http://server-check.service.consul" @app.errorhandler(404) def page_not_found(error): @@ -35,4 +35,4 @@ def findServer(name, port): return requests.get("http://"+name+":"+port) if __name__ == '__main__': - app.run(debug=True, host="0.0.0.0", port=5000) + app.run(debug=True, host="0.0.0.0", port=80) diff --git a/serverA/dockerfile b/serverA/dockerfile index 5709ecc..62c5399 100644 --- a/serverA/dockerfile +++ b/serverA/dockerfile @@ -4,7 +4,7 @@ copy . /app workdir /app run pip install -r requirements.txt -expose 5000 +expose 80 entrypoint [ "python" ] cmd [ "app.py" ] \ No newline at end of file diff --git a/serverB/app.py b/serverB/app.py index 53b95c6..a58c342 100644 --- a/serverB/app.py +++ b/serverB/app.py @@ -6,12 +6,19 @@ app = Flask(__name__) @app.route('/') def doRequest(): data = { - "serverName": "serverB", + "serverName": "server-b", "version": "master", "success": "true" } return jsonify(data) + +@app.route('/', defaults={'path': ''}) +@app.route('/') +def doRequest(path): + return path + "\nserver-b" + + if __name__ == '__main__': - app.run(debug=True, host="0.0.0.0", port=6000) + app.run(debug=True, host="0.0.0.0", port=80) diff --git a/serverB/dockerfile b/serverB/dockerfile index b9692c2..62c5399 100644 --- a/serverB/dockerfile +++ b/serverB/dockerfile @@ -4,7 +4,7 @@ copy . /app workdir /app run pip install -r requirements.txt -expose 6000 +expose 80 entrypoint [ "python" ] cmd [ "app.py" ] \ No newline at end of file diff --git a/serverC/app.py b/serverC/app.py index 13ef8a2..419d4af 100644 --- a/serverC/app.py +++ b/serverC/app.py @@ -6,11 +6,19 @@ app = Flask(__name__) @app.route('/') def doRequest(): data = { - "serverName": "serverC", + "serverName": "server-c", + "version": "master", "success": "true" } return jsonify(data) + +@app.route('/', defaults={'path': ''}) +@app.route('/') +def doRequest(path): + return path + "\nserver-c" + + if __name__ == '__main__': - app.run(debug=True, host="0.0.0.0", port=6000) + app.run(debug=True, host="0.0.0.0", port=80) diff --git a/serverC/dockerfile b/serverC/dockerfile index b9692c2..62c5399 100644 --- a/serverC/dockerfile +++ b/serverC/dockerfile @@ -4,7 +4,7 @@ copy . /app workdir /app run pip install -r requirements.txt -expose 6000 +expose 80 entrypoint [ "python" ] cmd [ "app.py" ] \ No newline at end of file diff --git a/serverD/app.py b/serverD/app.py index 621588e..eb89df2 100644 --- a/serverD/app.py +++ b/serverD/app.py @@ -21,4 +21,4 @@ def get(): if __name__ == '__main__': - app.run(debug=True, host="0.0.0.0", port=6000) + app.run(debug=True, host="0.0.0.0", port=80) diff --git a/serverD/dockerfile b/serverD/dockerfile index 643443f..62c5399 100644 --- a/serverD/dockerfile +++ b/serverD/dockerfile @@ -4,7 +4,7 @@ copy . /app workdir /app run pip install -r requirements.txt -expose 7000 +expose 80 entrypoint [ "python" ] cmd [ "app.py" ] \ No newline at end of file