Changes between Version 6 and Version 7 of k8snetworking2023
- Timestamp:
- Dec 8, 2023, 2:47:41 PM (12 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
k8snetworking2023
v6 v7 1 '''Issuing a Virtual IP to a Service Using MetalLB on Kubernetes''' 1 == Issuing a Virtual IP to a Service Using MetalLB on Kubernetes == 2 2 3 3 MetalLB is a load balancer implementation for bare metal Kubernetes clusters, using L2 advertisements. This tutorial will guide you through the process of setting up MetalLB in your Kubernetes cluster and assigning a virtual IP to a service. 4 4 5 '''Step 1: Install MetalLB''' 5 === Step 1: Install MetalLB === 6 6 7 7 MetalLB can be installed via a manifest or using Helm. We'll use the manifest method here. … … 10 10 11 11 {{{ 12 kubectl apply -f 13 https://raw.githubusercontent.com/metallb/metallb/v0.13.12/con 14 fig/manifests/metallb-native.yaml 12 #!sh 13 kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.12/config/manifests/metallb-native.yaml 14 15 15 }}} 16 16 … … 23 23 You should see the MetalLB pods running. 24 24 25 '''Step 2: Configure MetalLB''' 25 === Step 2: Configure MetalLB === 26 26 27 27 MetalLB can operate in either Layer 2 mode or BGP mode. We'll use Layer 2 mode for simplicity. 28 28 29 ''1. Create a ConfigMap for MetalLB: Define a range of IP addresses that MetalLB will manage. Create a file named `metallb-pool.yaml` with the following content:'' 30 31 {{{ 29 ''1. Create a !ConfigMap for MetalLB: Define a range of IP addresses that MetalLB will manage. Create a file named `metallb-pool.yaml` with the following content:'' 30 31 {{{ 32 #!python 32 33 apiVersion: metallb.io/v1beta1 33 34 kind: IPAddressPool … … 50 51 51 52 {{{ 53 #!python 52 54 apiVersion: metallb.io/v1beta1 53 55 kind: L2Advertisement … … 66 68 '''Step 3: Create a Service with a Virtual IP''' 67 69 68 Let’s expose the wordpress application: Edit the service of type LoadBalancer on69 wordpress-service.yaml: 70 71 {{{ 70 Let’s expose the wordpress application: Edit the service of type !LoadBalancer on `wordpress-service.yaml`: 71 72 {{{ 73 #!python 72 74 apiVersion: v1 73 75 kind: Service … … 102 104 On a different VM than the master do the testing for ARP advertisements. 103 105 104 Remove MetalLB (Only for the reference) 105 106 {{{ 106 Remove !MetalLB (Only for the reference) 107 108 {{{ 109 #!sh 107 110 arp -a 108 111 ping 192.168.1.200 … … 111 114 }}} 112 115 113 Remove MetalLB (Only for the reference) 114 115 {{{ 116 kubectl delete -f 117 https://raw.githubusercontent.com/metallb/metallb/v0.13.12/con 118 fig/manifests/metallb-native.yaml 116 Remove !MetalLB (Only for the reference) 117 118 {{{ 119 #!sh 120 kubectl delete -f https://raw.githubusercontent.com/metallb/metallb/v0.13.12/config/manifests/metallb-native.yaml 119 121 kubectl delete -f metallb-pool.yaml 120 122 kubectl delete -f L2add.yaml … … 122 124 }}} 123 125 124 === Kubernetes Ingress. (Optional) === 125 126 In a Kubernetes environment, if you want to use an Ingress resource to direct traffic to a service that's exposed via NodePort, while still allowing users to access the service using a standard port (like port 80) without specifying the NodePort, you can set it up as follows: 127 128 '''Step 1: Expose Your Service Using NodePort''' 129 130 ''1. Create a Service of Type NodePort for Your Web Application: Suppose you have a deployment named webapp. You'll need to create a service for it. Here's an example YAML for the service:'' 131 132 {{{ 126 127 == Kubernetes Ingress. (Optional) == 128 129 In a Kubernetes environment, if you want to use an Ingress resource to direct traffic to a service that's exposed via !NodePort, while still allowing users to access the service using a standard port (like port 80) without specifying the !NodePort, you can set it up as follows: 130 131 === Step 1: Expose Your Service Using !NodePort === 132 133 ''1. Create a Service of Type !NodePort for Your Web Application: Suppose you have a deployment named webapp. You'll need to create a service for it. Here's an example YAML for the service:'' 134 135 {{{ 136 #!python 133 137 apiVersion: v1 134 138 kind: Service … … 145 149 }}} 146 150 147 This service will expose your webapp on a NodePort.151 This service will expose your webapp on a !NodePort. 148 152 149 153 • Apply the Service: … … 151 155 `kubectl apply -f [your-service-file].yaml` 152 156 153 '''Step 2: Set Up Ingress to Route to the NodePort Service''' 157 === Step 2: Set Up Ingress to Route to the !NodePort Service === 154 158 155 159 ''1. Define an Ingress Resource: Create an Ingress resource that routes traffic to your NodePort service. Here's an example YAML for the Ingress:'' 156 160 157 161 {{{ 158 162 #!python 159 163 apiVersion: networking.k8s.io/v1 160 164 kind: Ingress … … 183 187 184 188 185 '''Step 3: Ensure Ingress Controller is Set Up Correctly''' 189 === Step 3: Ensure Ingress Controller is Set Up Correctly === 186 190 187 191 Ensuring that your Ingress Controller is properly set up and accessible from outside the Kubernetes cluster involves several key steps. This setup is crucial for allowing external traffic to reach your services through the Ingress rules you've defined. Here's a breakdown of what this entails: … … 194 198 195 199 {{{ 196 kubectl apply -f 197 https://raw.githubusercontent.com/kubernetes/ingress- 198 nginx/controller- 199 v1.8.2/deploy/static/provider/cloud/deploy.yaml 200 #!sh 201 kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml 202 200 203 }}} 201 204 '' … … 204 207 205 208 • Service Type: The Ingress Controller itself is exposed via a Kubernetes Service. This Service needs to be accessible from outside the cluster. There are two common ways to do this: 206 - NodePort: The Service is exposed on a high port (e.g., 30000-32767) on each node's IP address. External traffic can reach the Ingress Controller by hitting any node's IP at this port.207 - LoadBalancer: If your cluster is running in a cloud environment that supportsLoadBalancer Services, this is a more straightforward way to expose your Ingress Controller. For our setup lets allow the metalLB setup to lease an external IP address that routes traffic to the Ingress Controller.208 209 '''Step 4: DNS Configuration''' 210 211 ''1. Configure DNS: Map the DNS record to the external IP address of one of your cluster nodes (if using NodePort for the Ingress Controller) or to the external IP provided by the LoadBalancer (if usingLoadBalancer for the Ingress Controller).''209 - !NodePort: The Service is exposed on a high port (e.g., 30000-32767) on each node's IP address. External traffic can reach the Ingress Controller by hitting any node's IP at this port. 210 - !LoadBalancer: If your cluster is running in a cloud environment that supports !LoadBalancer Services, this is a more straightforward way to expose your Ingress Controller. For our setup lets allow the metalLB setup to lease an external IP address that routes traffic to the Ingress Controller. 211 212 === Step 4: DNS Configuration === 213 214 ''1. Configure DNS: Map the DNS record to the external IP address of one of your cluster nodes (if using !NodePort for the Ingress Controller) or to the external IP provided by the !LoadBalancer (if using !LoadBalancer for the Ingress Controller).'' 212 215 213 216 Read More: