In this post, I need to add 1 VM to install Nginx to load balancer here I will create 1 more VM ubuntu 22.04
IP | Hostname | vCPU | RAM | DISK |
---|---|---|---|---|
10.19.2.91 | nginx | 2 cores | 8G | 100G |
10.19.2.92 | stg-02 | 6 cores | 12G | 100G |
10.19.2.93 | stg-03 | 6 cores | 12G | 100G |
10.19.2.94 | stg-03 | 6 cores | 12G | 100G |
We install according to the model
Install Nginx on Ubuntu 22.04
Connect to VM nginx (10.19.2.91)
1 2 3 | ssh ubuntu@10.19.2.91 Nhập Pass |
Step 1 – Install Nginx
Update apt-install packages
1 2 | sudo apt update |
Install Nginx
1 2 | sudo apt install nginx -y |
Step 2 – Grant HTTP Firewall Permissions
1 2 | sudo ufw allow 'Nginx HTTP' |
Step 3 – Check Your Web Host
Check if nginx service is working?
Enable IGRESS
To enable Microk8s Inpress Controller we use the command:
1 2 | microk8s enable ingress |
After successful activation, we will try to create an ingress file of the dashboard
Czech: ingress-dashboard.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: https-ingress-dashboard namespace: kube-system annotations: kubernetes.io/ingress.class: public nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" spec: rules: - http: paths: - path: / pathType: Prefix backend: service: name: kubernetes-dashboard port: number: 443 |
Run the command microk8s kubectl apply -f ingress-dashboard.yaml
When successful, we go to the link https://10.19.2.92/ to check
Configure nginx Reverse Proxy
Step 1: go to the hosts file to add a line at the end of the machine you are using, here I use Windows
Windows Path: C:WindowsSystem32driversetchosts
MacOS & Linux Path: /etc/hosts
1 2 | 10.19.2.91 kubernetes-dashboard.localhost |
Step 2: Configure nginx
Connect to VM nginx (10.19.2.91)
1 2 3 | ssh ubuntu@10.19.2.91 Nhập Pass |
then go to directory: /etc/nginx/sites-enabled
1 2 | cd /etc/nginx/sites-enabled |
create file kubernetes-dashboard.localhost.conf
1 2 | sudo nano kubernetes-dashboard.localhost.conf |
copy the config and add it to the file kubernetes-dashboard.localhost.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | upstream host_stg { server 10.19.2.92; server 10.19.2.93; server 10.19.2.94; } server { listen 80 ; server_name kubernetes-dashboard.localhost; location / { limit_req zone=speedbump burst=20 nodelay; proxy_pass http://host_stg; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } |
Save and check the config is correct: sudo nginx -t
1 2 3 | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
Restart the service:
1 2 | sudo systemctl restart nginx |
Configure ingress-dashboard.yaml
Add the host line: kubernetes-dashboard.localhost to
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: https-ingress-dashboard namespace: kube-system annotations: kubernetes.io/ingress.class: public nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" spec: rules: - host: kubernetes-dashboard.localhost http: paths: - path: / pathType: Prefix backend: service: name: kubernetes-dashboard port: number: 443 |
Run config again: microk8s kubectl apply -f ingress-dashboard.yaml
If you find this post helpful, please give me a like and subscribe to support me. Thank you so much
References: