|
2 | 2 |
|
3 | 3 | [](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes) [](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes) [](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes) |
4 | 4 |
|
5 | | -This container image can be deployed on a Kubernetes cluster. When accessed via a web browser on port `8080`, it will display: |
| 5 | +This container image can be deployed on a Kubernetes cluster. It runs a web app, that displays the following: |
6 | 6 |
|
7 | 7 | - a default **Hello world!** message |
8 | | -- the pod name |
9 | | -- node os information |
| 8 | +- namespace, pod, and node details |
| 9 | +- container image details |
10 | 10 |
|
11 | 11 |  |
12 | 12 |
|
13 | | -The default "Hello world!" message displayed can be overridden using the `MESSAGE` environment variable. The default port of 8080 can be overriden using the `PORT` environment variable. |
14 | | - |
15 | | -## Deploy |
16 | | - |
17 | | -### Standard Configuration |
18 | | - |
19 | | -Deploy to your Kubernetes cluster using the hello-kubernetes.yaml, which contains definitions for the service and deployment objects: |
20 | | - |
21 | | -```yaml |
22 | | -# hello-kubernetes.yaml |
23 | | -apiVersion: v1 |
24 | | -kind: Service |
25 | | -metadata: |
26 | | - name: hello-kubernetes |
27 | | -spec: |
28 | | - type: LoadBalancer |
29 | | - ports: |
30 | | - - port: 80 |
31 | | - targetPort: 8080 |
32 | | - selector: |
33 | | - app: hello-kubernetes |
34 | | ---- |
35 | | -apiVersion: apps/v1 |
36 | | -kind: Deployment |
37 | | -metadata: |
38 | | - name: hello-kubernetes |
39 | | -spec: |
40 | | - replicas: 3 |
41 | | - selector: |
42 | | - matchLabels: |
43 | | - app: hello-kubernetes |
44 | | - template: |
45 | | - metadata: |
46 | | - labels: |
47 | | - app: hello-kubernetes |
48 | | - spec: |
49 | | - containers: |
50 | | - - name: hello-kubernetes |
51 | | - image: paulbouwer/hello-kubernetes:1.9 |
52 | | - ports: |
53 | | - - containerPort: 8080 |
54 | | -``` |
| 13 | +## Quick start |
| 14 | + |
| 15 | +You can deploy `hello-kubernetes` to your Kubernetes cluster using [Helm 3](https://helm.sh/docs/intro/install/). The Helm chart installation and configuration options can be found in the [Deploy using Helm](docs/deploy-using-helm.md) guide. |
| 16 | + |
| 17 | +When running through the following examples, ensure that you are in the chart directory in the repo, since you are referencing a local helm chart. |
55 | 18 |
|
56 | 19 | ```bash |
57 | | -$ kubectl apply -f yaml/hello-kubernetes.yaml |
| 20 | +cd deploy/helm |
58 | 21 | ``` |
59 | 22 |
|
60 | | -This will display a **Hello world!** message when you hit the service endpoint in a browser. You can get the service endpoint ip address by executing the following command and grabbing the returned external ip address value: |
| 23 | +### Example 1: Default |
| 24 | + |
| 25 | +Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace with the default "Hello world!" message. The app is exposed via a public Load Balancer on port 80 by default - note that a LoadBalancer service typically only works in cloud provider based Kubernetes offerings. |
61 | 26 |
|
62 | 27 | ```bash |
63 | | -$ kubectl get service hello-kubernetes |
64 | | -``` |
| 28 | +helm install --create-namespace --namespace hello-kubernetes hello-world ./hello-kubernetes |
65 | 29 |
|
66 | | -### Customise Message |
67 | | - |
68 | | -You can customise the message displayed by the `hello-kubernetes` container. Deploy using the hello-kubernetes.custom-message.yaml, which contains definitions for the service and deployment objects. |
69 | | - |
70 | | -In the definition for the deployment, add an `env` variable with the name of `MESSAGE`. The value you provide will be displayed as the custom message. |
71 | | - |
72 | | -```yaml |
73 | | -# hello-kubernetes.custom-message.yaml |
74 | | -apiVersion: v1 |
75 | | -kind: Service |
76 | | -metadata: |
77 | | - name: hello-kubernetes-custom |
78 | | -spec: |
79 | | - type: LoadBalancer |
80 | | - ports: |
81 | | - - port: 80 |
82 | | - targetPort: 8080 |
83 | | - selector: |
84 | | - app: hello-kubernetes-custom |
85 | | ---- |
86 | | -apiVersion: apps/v1 |
87 | | -kind: Deployment |
88 | | -metadata: |
89 | | - name: hello-kubernetes-custom |
90 | | -spec: |
91 | | - replicas: 3 |
92 | | - selector: |
93 | | - matchLabels: |
94 | | - app: hello-kubernetes-custom |
95 | | - template: |
96 | | - metadata: |
97 | | - labels: |
98 | | - app: hello-kubernetes-custom |
99 | | - spec: |
100 | | - containers: |
101 | | - - name: hello-kubernetes |
102 | | - image: paulbouwer/hello-kubernetes:1.9 |
103 | | - ports: |
104 | | - - containerPort: 8080 |
105 | | - env: |
106 | | - - name: MESSAGE |
107 | | - value: I just deployed this on Kubernetes! |
| 30 | +# get the LoadBalancer ip address. |
| 31 | +kubectl get svc hello-kubernetes-hello-world -n hello-kubernetes -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }' |
108 | 32 | ``` |
109 | 33 |
|
| 34 | +### Example 2: Custom message |
| 35 | + |
| 36 | +Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace with an "I just deployed this on Kubernetes!" message. The app is exposed via a public Load Balancer on port 80 by default - note that a LoadBalancer service typically only works in cloud provider based Kubernetes offerings. |
| 37 | + |
110 | 38 | ```bash |
111 | | -$ kubectl apply -f yaml/hello-kubernetes.custom-message.yaml |
112 | | -``` |
| 39 | +helm install --create-namespace --namespace hello-kubernetes custom-message ./hello-kubernetes \ |
| 40 | + --set message="I just deployed this on Kubernetes!" |
113 | 41 |
|
114 | | -### Specify Custom Port |
115 | | - |
116 | | -By default, the `hello-kubernetes` app listens on port `8080`. If you have a requirement for the app to listen on another port, you can specify the port via an env variable with the name of PORT. Remember to also update the `containers.ports.containerPort` value to match. |
117 | | - |
118 | | -Here is an example: |
119 | | - |
120 | | -```yaml |
121 | | -apiVersion: apps/v1 |
122 | | -kind: Deployment |
123 | | -metadata: |
124 | | - name: hello-kubernetes-custom |
125 | | -spec: |
126 | | - replicas: 3 |
127 | | - selector: |
128 | | - matchLabels: |
129 | | - app: hello-kubernetes-custom |
130 | | - template: |
131 | | - metadata: |
132 | | - labels: |
133 | | - app: hello-kubernetes-custom |
134 | | - spec: |
135 | | - containers: |
136 | | - - name: hello-kubernetes |
137 | | - image: paulbouwer/hello-kubernetes:1.9 |
138 | | - ports: |
139 | | - - containerPort: 80 |
140 | | - env: |
141 | | - - name: PORT |
142 | | - value: "80" |
| 42 | +# get the LoadBalancer ip address. |
| 43 | +kubectl get svc hello-kubernetes-custom-message -n hello-kubernetes -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }' |
143 | 44 | ``` |
144 | 45 |
|
145 | | -## Cutomize URL context path |
146 | | -
|
147 | | -If you have an ingress that routes to a custom context path then you can customize the URL context path. The css files and the images will be loaded properly in that case. |
148 | | -
|
149 | | -```yaml |
150 | | -apiVersion: apps/v1 |
151 | | -kind: Deployment |
152 | | -metadata: |
153 | | - name: hello-kubernetes-custom |
154 | | -spec: |
155 | | - replicas: 3 |
156 | | - selector: |
157 | | - matchLabels: |
158 | | - app: hello-kubernetes-custom |
159 | | - template: |
160 | | - metadata: |
161 | | - labels: |
162 | | - app: hello-kubernetes-custom |
163 | | - spec: |
164 | | - containers: |
165 | | - - name: hello-kubernetes |
166 | | - image: paulbouwer/hello-kubernetes:1.9 |
167 | | - ports: |
168 | | - - containerPort: 8080 |
169 | | - env: |
170 | | - - name: MESSAGE |
171 | | - value: I just deployed this on Kubernetes! |
172 | | - - name: CONTEXT_PATH |
173 | | - value: "/api/v1/hello-kubernetes/" |
174 | | -``` |
| 46 | +### Example 3: Ingress |
175 | 47 |
|
176 | | -## Build Container Image |
| 48 | +Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace. This example assumes that an ingress has been deployed and configured in the cluster, and that the ingress has a path of `/app/hello-kubernetes/` mapped to the `hello-kubernetes` service. |
177 | 49 |
|
178 | | -If you'd like to build the image yourself, then you can do so as follows. The `build-arg` parameters provides metadata as defined in [OCI image spec annotations](https://github.com/opencontainers/image-spec/blob/master/annotations.md). |
| 50 | +The `hello-kubernetes` app can be reached on the ip address of the ingress via the `/app/hello-kubernetes/` path. |
179 | 51 |
|
180 | | -Bash |
181 | 52 | ```bash |
182 | | -$ docker build --no-cache --build-arg IMAGE_VERSION="1.9" --build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" --build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" -f Dockerfile -t "hello-kubernetes:1.9" app |
| 53 | +helm install --create-namespace --namespace hello-kubernetes ingress ./hello-kubernetes \ |
| 54 | + --set ingress.configured=true \ |
| 55 | + --set ingress.pathPrefix="/app/hello-kubernetes/" \ |
| 56 | + --set service.type="ClusterIP" |
183 | 57 | ``` |
184 | 58 |
|
185 | | -Powershell |
186 | | -```powershell |
187 | | -PS> docker build --no-cache --build-arg IMAGE_VERSION="1.9" --build-arg IMAGE_CREATE_DATE="$(Get-Date((Get-Date).ToUniversalTime()) -UFormat '%Y-%m-%dT%H:%M:%SZ')" --build-arg IMAGE_SOURCE_REVISION="$(git rev-parse HEAD)" -f Dockerfile -t "hello-kubernetes:1.9" app |
188 | | -``` |
| 59 | +## Documentation |
| 60 | + |
| 61 | +### Deploying |
| 62 | + |
| 63 | +If you'd like to explore the various Helm chart configuration options, then read the [Deploy with Helm](docs/deploy-using-helm.md) documentation. You can also discover more about the ingress configuration options in the [Deploy with ingress](docs/deploy-with-ingress.md) documentation |
189 | 64 |
|
190 | | -## Develop Application |
| 65 | +### Building your own images |
191 | 66 |
|
192 | | -If you have [VS Code](https://code.visualstudio.com/) and the [Visual Studio Code Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed, the `.devcontainer` folder will be used to build a container based node.js 13 development environment. |
| 67 | +If you'd like to build the `hello-kubernetes` container image yourself and reference from your own registry or DockerHub repository, then you can get more details on how to do this in the [Build and push container images](docs/build-and-push-container-images.md) documentation. |
193 | 68 |
|
194 | | -Port `8080` has been configured to be forwarded to your host. If you run `npm start` in the `app` folder in the VS Code Remote Containers terminal, you will be able to access the website on `http://localhost:8080`. You can change the port in the `.devcontainer\devcontainer.json` file under the `appPort` key. |
| 69 | +### Development environment |
195 | 70 |
|
196 | | -See [here](https://code.visualstudio.com/docs/remote/containers) for more details on working with this setup. |
| 71 | +If you have [VS Code](https://code.visualstudio.com/) and the [VS Code Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed, the `.devcontainer` folder will be used to provide a container based development environment. You can read more about how to use this in the [Development environments](docs/development-environment.md) documentation. |
0 commit comments