apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
type: LoadBalancer
The Kubernetes description provided by platforms such as AWS and GCP uses a load balancer (LB) that is assigned a global IP address for communication with the outside world.
In our k8s cluster, the MetalLB is used to assign IP addresses in the range 192.168.100.160-199/24.
The LB assigned the address of 192.168.100.0/24 cannot be accessed from any other places except seminar room 10, such as exercise rooms and ains-wifi.
From AY2021, we recommend using Ingress by the service object,svc/<username>-svc
(e.g., svc/s12xxxxxxx-svc), rather than LB.
1. Basic usage
On the official site, kubernetes.io official - Service Type: LoadBalancer, you can find the service definition that forwards communication to port 9376 of a pod with the label "app.kubernetes.io/name: MyApp" on selector is shown in the following.
-
name: should be unique and an arbitrary name that is easy to understand.
-
selector: is the value set in the pod’s metadata.labels.
-
port: should be the port number you want the external connection to use.
-
targetPort: is the port number that the Pod is using.
When you want to expose your pod through the network, please use this definition and modify those four parameters.
Adding type: LoadBalancer to the Service definition of nginx-nfs prepared in Persistent Storage will allow access with the IP address 192.168.100.x/24.