132 lines
2.6 KiB
Markdown
132 lines
2.6 KiB
Markdown
# kube
|
|
|
|
This repo contains some kubernetes test stuff
|
|
|
|
## testapp
|
|
|
|
The testapp consists of three parts:
|
|
|
|
* srv - the frontend server
|
|
* db - simulating a database backend that gets called
|
|
* api - another service that calls an external service (httpbin.org)
|
|
|
|
Topology:
|
|
|
|
```
|
|
+--- db
|
|
/
|
|
srv ---+
|
|
\
|
|
+--- api --- httpbin.org
|
|
```
|
|
|
|
### Prepare
|
|
|
|
You need to have access from you local machine to the container registry deployed in you cluster on port 5000:
|
|
|
|
You can use ssh port-forwarding: `ssh k8s-master -L 5000:127.0.0.1:5000`
|
|
|
|
You need a local docker installation to build and upload the containers.
|
|
|
|
For the normal deployment the nginx ingress controller is used.
|
|
|
|
#### Ingress traffic
|
|
|
|
To get traffic to the ingress controller, install an nginx tcp proxy on the master node:
|
|
|
|
Install nginx: `apt install nginx -y`
|
|
|
|
Configure nginx to forward traffic to the node ports.
|
|
First get the ports of your ingress controller.
|
|
|
|
Look for the `80:<nodeport>` and `443:<nodeport>` mappings.
|
|
|
|
* nginx: `kubectl -n ingress-nginx get svc ingress-nginx`
|
|
* Istio: `kubectl -n istio-system get svc istio-ingressgateway`
|
|
|
|
Now add all your worker nodes as stream backends with the ports:
|
|
|
|
```
|
|
cat <<EOF> /etc/nginx/nginx.conf
|
|
load_module /usr/lib/nginx/modules/ngx_stream_module.so;
|
|
events {
|
|
worker_connections 1024;
|
|
}
|
|
stream {
|
|
upstream stream_backend_80 {
|
|
server 192.168.0.3:31380;
|
|
server 192.168.0.4:31380;
|
|
server 192.168.0.5:31380;
|
|
}
|
|
server {
|
|
listen 80;
|
|
proxy_pass stream_backend_80;
|
|
}
|
|
|
|
upstream stream_backend_443 {
|
|
server 192.168.0.3:31390;
|
|
server 192.168.0.4:31390;
|
|
server 192.168.0.5:31390;
|
|
}
|
|
server {
|
|
listen 443;
|
|
proxy_pass stream_backend_443;
|
|
}
|
|
}
|
|
EOF
|
|
```
|
|
|
|
Restart nginx: `systemctl restart nginx`
|
|
|
|
Now you can access your ingress via the masters IP on port 80 and 443.
|
|
|
|
### Build
|
|
|
|
New build the containers and upload them.
|
|
|
|
#### SRV
|
|
|
|
```
|
|
cd testapp/srv
|
|
VERSION=v1 make
|
|
```
|
|
|
|
#### DB
|
|
|
|
```
|
|
cd testapp/db
|
|
VERSION=v1 make
|
|
```
|
|
|
|
#### API
|
|
|
|
```
|
|
cd testapp/api
|
|
VERSION=v1 make
|
|
```
|
|
|
|
### Deploy
|
|
|
|
Deploy your application stack either using the simple versions or the `-istio` versions.
|
|
|
|
To use `-istio` versions you need to install istio in your cluster first.
|
|
|
|
**Note:** Change the `k8s-testapp.example.com` domain in the `srv` manifests to your domain.
|
|
|
|
#### Simple
|
|
|
|
```
|
|
cd testapp
|
|
kubectl apply -f api/api-v1.yaml
|
|
kubectl apply -f db/db.yaml
|
|
kubectl apply -f srv/srv-v1.yaml
|
|
```
|
|
|
|
#### Istio
|
|
|
|
```
|
|
cd testapp
|
|
kubectl apply -f api/api-v1-istio.yaml
|
|
kubectl apply -f db/db.yaml
|
|
kubectl apply -f srv/srv-v1-istio.yaml
|
|
```
|