Skip to content

Commit 14ea7b4

Browse files
committed
worked on Controller
1 parent 3f6ab3d commit 14ea7b4

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

advanced/Controller/README.adoc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ To create this deployment in the current namespace, call:
4141

4242
[source,bash]
4343
----
44-
# Create the controller Deployment
45-
kubectl create -f config-watcher-controller.yml
44+
kubectl apply -f https://k8spatterns.io/Controller/config-watcher-controller.yml
4645
----
4746

4847
You might want to have a look at the descriptor file; it contains some useful comments along the way and also the security setup to allow the controller to watch resources and to restart `Pods`.
@@ -57,45 +56,52 @@ Before we deploy this app, we should tail on the log of our controller (e.g. `ku
5756

5857
[source,bash]
5958
----
60-
controller_pod=$(kubectl get pod -o name | grep config-watcher-controller | sed -e "s/^pods\///")
61-
kubectl logs -f $controller_pod config-watcher
59+
kubectl logs -f $(kubectl get pods -l role=controller -o name) config-watcher
6260
----
6361

6462
Then create the web application itself:
6563

6664
[source,bash]
6765
----
68-
# Create a sample web application with an 'expose' annotation:
69-
kubectl create -f web-app.yml
66+
kubectl apply -f https://k8spatterns.io/Controller/web-app.yml
7067
----
7168

7269
If you look into this descriptor, you will find a `Deployment` using our dumb HTTP server which references the content environment variable via a `ConfigMap`.
7370
The `ConfigMap` itself is annotated with a pod selector `k8spatterns.io/podDeleteSelector: "app=webapp"` which directly select the webapp `Pod`.
7471

7572
This resource file also includes the definition of a Service and an Ingress object so that we can access the server from the outside.
7673

74+
Before accessing the web-app we need to path the Ingress object to point to our minikube installation:
75+
76+
[source, bash]
77+
----
78+
kubectl patch ingress webapp --type=json \
79+
-p "[{op: replace, \
80+
path: /spec/rules/0/host, \
81+
value: webapp.$(minikube ip).nip.io}]"
82+
----
83+
84+
NOTE: `nip.io` is a nice DNS reflector service, that as result of a DNS lookup just returns the IP address that is added before as subdomain just before the `.nip.io` part.
7785

7886
You can access our web app directly
7987

8088
[source,bash]
8189
----
82-
# Access webapp via the included Ingress obect
8390
curl -sk https://webapp.$(minikube ip).nip.io
8491
----
8592

8693
Now change the content of `ConfigMap` and watch the log of your controller:
8794

8895
[source,bash]
8996
----
90-
# Patch config-map to update the web content
91-
kubectl patch configmap webapp-config -p '{"data":{"message":"Take this update!"}}'
97+
kubectl patch configmap webapp-config \
98+
-p '{"data":{"message":"Take this update!"}}'
9299
----
93100

94101
and then finally call the URL again to check that the content has been updated to
95102

96103
[source,bash]
97104
----
98-
# Access webapp via the included Ingress obect
99105
curl -sk https://webapp.$(minikube ip).nip.io
100106
----
101107

advanced/Controller/config-watcher-controller.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ metadata:
2525
labels:
2626
project: k8spatterns
2727
pattern: Controller
28+
role: contoller
2829
name: config-watcher-controller
2930
spec:
3031
replicas: 1
@@ -37,6 +38,7 @@ spec:
3738
project: k8spatterns
3839
pattern: Controller
3940
app: config-watcher-controller
41+
role: controller
4042
spec:
4143
# A serviceaccount is needed to watch events
4244
# and to allow for restarting pods. For now its

advanced/Controller/web-app.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,24 @@ spec:
5656
app: webapp
5757
---
5858
# Ingress object for external access to the webserver.
59-
# If running on minikube, open "https://webapp.$(minikube ip).nip.io"
59+
# If running on minikube, # Replace the IP address with the output of `minikube ip` either directly
60+
# in this file or later with a `kubectl patch`.
61+
# Then open "https://webapp.$(minikube ip).nip.io"
6062
# in the browser and don't forget to enable ingress on minikube via
6163
# "minikube addons enable ingress"
62-
apiVersion: extensions/v1beta1
64+
apiVersion: extensions/v1
6365
kind: Ingress
6466
metadata:
6567
name: webapp
6668
spec:
6769
rules:
68-
- http:
70+
- host: webapp.127.0.0.1.nip.io
71+
http:
6972
paths:
70-
- backend:
71-
serviceName: webapp
72-
servicePort: 8080
73-
path: "/"
73+
- path: "/"
74+
pathType: Prefix
75+
backend:
76+
service:
77+
name: webapp
78+
port:
79+
number: 8080

0 commit comments

Comments
 (0)