I will walk you through the NGINX ingress controller installation and configuration steps in this article.
Here is a video tutorial; continue reading for a list of written instructions. VIDEO
Exercises to complete:# install k3s securely without traefik and servicelb install nginx as ingress controller in k3s Check nodes and pods status Create a load balancer to expose NGINX ingress controller ports Create a namespace test Create an example for testing Test the configuration Copy k3s config file Change owner to user for k3s config file Install k9s Run k9s k9s usage explanation Check k3s services Check the example test application Install k3s securely without the traefik and servicelb# 1
sudo curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC = "--disable traefik,servicelb" K3S_KUBECONFIG_MODE = "644" sh -
copy
Add cgroup entries into the cmdline.txt# 1
sudo vim /boot/cmdline.txt
copy
Add at the end of the line that starts with console= the below entries: 1
cgroup_memory = 1 cgroup_enable = memory
copy
Reboot the server# What is NGINX ingress controller?# See the documentation: NGINX ingress controller
Install NGINX as ingress controller in k3s# 1
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/baremetal/deploy.yaml
copy
See the documentation: NGINX ingress controller Installation Guide
Check node status# Check pods# 1
kubectl get pods -A
copy
Create a load balancer to expose NGINX ingress controller ports# 1
vim ingress-controller-load-balancer.yaml
copy
Put the below content into the file 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
apiVersion : v1
kind : Service
metadata :
name : ingress-nginx-controller-loadbalancer
namespace : ingress-nginx
spec :
selector :
app.kubernetes.io/component : controller
app.kubernetes.io/instance : ingress-nginx
app.kubernetes.io/name : ingress-nginx
ports :
- name : http
port : 80
protocol : TCP
targetPort : 80
- name : https
port : 443
protocol : TCP
targetPort : 443
type : LoadBalancer
copy
Apply the load balancer file# 1
kubectl apply -f ingress-controller-load-balancer.yaml
copy
Create a namespace test# 1
kubectl create namespace test
copy
Create an example for testing# The sample below uses the NGINX ingress controller to establish a deployment and expose it. Because SSL will be utilized by default and produce an error for a nonexistent certificate, it’s critical to pay attention to the annotation nginx.ingress.kubernetes.io/ssl-redirect: “false”.
The domain name that is used is another crucial factor. I’m going to use the domain name test.localhost, but you should obviously change it to your own and direct it to your k3s instance node.
Create a file called my-example.yaml and use the following syntax to implement this example for Ingress testing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
apiVersion : apps/v1
kind : Deployment
metadata :
name : test-nginx-app
namespace : test
spec :
selector :
matchLabels :
name : test-nginx-backend
template :
metadata :
labels :
name : test-nginx-backend
spec :
containers :
- name : backend
image : docker.io/nginx:alpine
imagePullPolicy : Always
ports :
- containerPort : 80
---
apiVersion : v1
kind : Service
metadata :
name : test-nginx-service
namespace : test
spec :
ports :
- name : http
port : 80
protocol : TCP
targetPort : 80
selector :
name : test-nginx-backend
---
apiVersion : networking.k8s.io/v1
kind : Ingress
metadata :
name : test-nginx-ingress
namespace : test
annotations :
nginx.ingress.kubernetes.io/ssl-redirect : "false"
spec :
rules :
- host : test.localhost
http :
paths :
- path : /
pathType : Prefix
backend :
service :
name : test-nginx-service
port :
number : 80
copy
Apply the example for testing# 1
kubectl apply -f my-example.yaml --namespace test
copy
Test the configuration# 1
2
3
4
5
kubectl cluster-info
kubectl get nodes
kubectl get pods -A
kubectl config get-contexts
kubectl get all --all-namespaces
copy
Copy k3s config file# 1
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
copy
Change owner to user for k3s config file
1
sudo chown -R $USER :$USER /home/$USER
copy
Install k9s# In order to communicate with your Kubernetes clusters, K9s offers a terminal UI. This project’s goal is to make it simpler to use, monitor, and administer your apps in the field. K9s continuously scans Kubernetes for modifications and provides follow-up commands to interact with the resources you have selected.
1
curl -sS https://webinstall.dev/k9s | bash
copy
Run k9s# Quit by pressing ctrl+c
k9s usage# 1
2
3
k9s info
k9s help
k9s -A
copy
Check k3s services# 1
kubectl get svc --all-namespaces -o wide
copy
Check the example test application# 1
curl http://10.43.13.55
copy
Comments