Changes between Version 8 and Version 9 of minikubedeployment2023
- Timestamp:
- Dec 8, 2023, 2:34:51 PM (15 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
minikubedeployment2023
v8 v9 1 1 '''You may continue to install Kubernetes on the vm you already installed docker. If you are installing this on a different machine make sure docker is already installed. 2 2 ''' 3 == == Part 1 ====3 == Part 1 == 4 4 5 5 '''Installing kubeadm, kubelet, and kubectl:''' … … 39 39 `kubeadm version` 40 40 41 41 42 '''Disable Swap Space''' 42 43 … … 50 51 51 52 `free -h` 52 53 54 53 55 '''Install Container runtime''' 54 56 … … 56 58 57 59 {{{ 60 #!sh 58 61 sudo tee /etc/modules-load.d/k8s.conf <<EOF 59 62 overlay 60 63 br_netfilter 61 EOF 64 EOF 62 65 }}} 63 66 … … 71 74 72 75 {{{ 73 sudo tee /etc/sysctl.d/kubernetes.conf<<EOF 76 #!sh 77 sudo tee /etc/sysctl.d/kubernetes.conf <<EOF 74 78 net.bridge.bridge-nf-call-ip6tables = 1 75 79 net.bridge.bridge-nf-call-iptables = 1 … … 114 118 115 119 {{{ 120 #!sh 116 121 br_netfilter 22256 0 117 122 bridge 151336 1 br_netfilter … … 132 137 You will see Your Kubernetes control-plane has initialized successfully! 133 138 134 You need to save the kubeadm join token string on a text document for future use. 135 136 22. To start the cluster, you need to run the following as a regular user (For this scenario we will only use a single host):139 '''You need to save the kubeadm join token string on a text document for future use.''' 140 141 22. To start the cluster, you need to run the following as a regular user (For this scenario we will only use a single master): 137 142 138 ` 139 140 ` 141 142 ` 143 `mkdir -p $HOME/.kube` 144 145 `sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config` 146 147 `sudo chown $(id -u):$(id -g) $HOME/.kube/config` 143 148 144 149 23. Check cluster info: … … 164 169 165 170 28. Connecting Worker nodes: 166 167 28.1. Install docker on both worker nodes as per the guidelines here.(LINK) 168 169 28.2. Install Kubernetes on each worker nodes. Follow steps 1 to 20. 170 171 28.3 Use previously saved kubeadm join token string to connect the workers. Run it with sudo. 172 173 If you forgot the token, run the following on your master to create a new token: 174 175 `kubeadm token create --print-join-command` 176 177 But remember, this will create a new token. 178 179 28.4 After all workers are connected, check status of the cluster: Here after all commands should be run on the master. 180 181 kubectl get nodes -o wide 182 183 ==== Part 2 ==== 184 Create a file simple-pod.yaml 185 186 {{{ 171 a. Install docker on both worker nodes as per the guidelines [https://ws.learn.ac.lk/wiki/dockerdeployment2023#Part1: here] (Upto step 6). 172 b. Install Kubernetes on each worker nodes. Follow above steps 1 to 20. 173 c. Use previously saved kubeadm join token string to connect the workers. Run it with '''sudo'''. 174 175 [OPTIONAL] If you forgot the token, run the following on your master to create a new token: 176 177 `kubeadm token create --print-join-command` 178 179 But remember, this will create a new token. 180 181 d. After all workers are connected, check status of the cluster: Here after all commands should be run on the master. 182 183 `kubectl get nodes -o wide` 184 185 == Part 2 == 186 Create a file `simple-pod.yaml` 187 188 {{{ 189 #!python 187 190 apiVersion: v1 188 191 kind: Pod … … 209 212 `kubectl delete pod nginx` 210 213 211 Pods are generally not created directly and are created using workload resources. See Working with Pods 212 [https://kubernetes.io/docs/concepts/workloads/pods/#working-with-pods Links to an external site]. for more information on how Pods are used with workload resources 213 214 ==== Part 3 ==== 214 Pods are generally not created directly and are created using workload resources. 215 216 See Working with Pods[https://kubernetes.io/docs/concepts/workloads/pods/#working-with-pods] for more information on how Pods are used with workload resources 217 218 == Part 3 == 215 219 216 220 '''Deploying a Simple Web Application on Kubernetes''' … … 219 223 220 224 A Deployment ensures that a specified number of pod replicas are running at any given time. Let's create a simple Deployment for a web application using the nginx image. 221 Save the following YAML to a file named webapp-deployment.yaml: 222 223 {{{ 225 Save the following YAML to a file named `webapp-deployment.yaml`: 226 227 {{{ 228 #!python 224 229 apiVersion: apps/v1 225 230 kind: Deployment … … 249 254 A Service is an abstraction that defines a logical set of Pods and enables external traffic exposure, load balancing, and service discovery. For our web application, we'll use a NodePort service. 250 255 251 Save the following YAML to a file named webapp-service.yaml: 252 253 {{{ 256 Save the following YAML to a file named `webapp-service.yaml`: 257 258 {{{ 259 #!python 254 260 apiVersion: v1 255 261 kind: Service … … 271 277 272 278 `kubectl apply -f webapp-deployment.yaml` 279 273 280 `kubectl apply -f webapp-service.yaml` 281 274 282 275 283 4. Verify the Deployment: … … 277 285 278 286 `kubectl get deployments` 287 279 288 `kubectl get services` 280 289 290 281 291 You should see your webapp-deployment with 2 replicas. Give it a time to take both replicas online. 282 292 283 293 5. Access the Web Application: 284 294 285 Since we used a NodePort service, the web application should be accessible on node's IP at port 30080.295 Since we used a !NodePort service, the web application should be accessible on node's IP at port 30080. 286 296 If you're unsure of your node IPs, you can get them with: 287 297 … … 290 300 Then, in a web browser or using a tool like curl, access the web application: 291 301 292 `curl http://< NODE_IP>:30080`302 `curl http://<MASTER/NODE_IP>:30080` 293 303 294 304 You should see the default nginx welcome page, indicating that your web application is running. … … 302 312 `kubectl delete service <service name>` 303 313 304 Part 4 305 306 '''Deploying WordPress and MySQL on Kubernetes''' 314 315 == Part 4 == 316 317 '''Deploying !WordPress and MySQL on Kubernetes''' 307 318 308 319 Installing dependancies: … … 312 323 `kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml` 313 324 314 Check with kubectl get storageclass 325 Check with `kubectl get storageclass` 326 315 327 Make this storage class (local-path) the default: 316 328 … … 319 331 1. Create a PersistentVolumeClaim for MySQL: 320 332 321 MySQL needs persistent storage to store its data. Save the following YAML to a file named mysql-pvc.yaml: 322 323 {{{ 333 MySQL needs persistent storage to store its data. Save the following YAML to a file named `mysql-pvc.yaml`: 334 335 {{{ 336 #!python 324 337 apiVersion: v1 325 338 kind: PersistentVolumeClaim … … 339 352 340 353 2. Deploy MySQL: 341 Save the following YAML to a file named mysql-deployment.yaml: 342 343 {{{ 354 Save the following YAML to a file named `mysql-deployment.yaml`: 355 356 {{{ 357 #!python 344 358 apiVersion: apps/v1 345 359 kind: Deployment … … 381 395 3. Create a Service for MySQL: 382 396 383 This will allow WordPress to communicate with MySQL. Save the following YAML to a file named mysql-service.yaml: 384 385 {{{ 397 This will allow !WordPress to communicate with MySQL. Save the following YAML to a file named `mysql-service.yaml`: 398 399 {{{ 400 #!python 386 401 apiVersion: v1 387 402 kind: Service … … 400 415 `kubectl apply -f mysql-service.yaml` 401 416 402 4. Deploy WordPress:417 4. Deploy !WordPress: 403 418 Save the following YAML to a file named wordpress-deployment.yaml: 404 419 405 420 {{{ 421 #!python 406 422 apiVersion: apps/v1 407 423 kind: Deployment … … 437 453 5. Create a Service for WordPress: 438 454 439 This will expose WordPress to external traffic. Save the following YAML to a file named wordpress-service.yaml: 440 441 {{{ 455 This will expose !WordPress to external traffic. Save the following YAML to a file named `wordpress-service.yaml`: 456 457 {{{ 458 #!python 442 459 apiVersion: v1 443 460 kind: Service … … 460 477 6. Access WordPress: 461 478 462 Since we used a NodePort service,WordPress should be accessible on node's IP at a dynamically allocated port above 30000.463 To find the NodePort assigned toWordPress:479 Since we used a !NodePort service, !WordPress should be accessible on node's IP at a dynamically allocated port above 30000. 480 To find the !NodePort assigned to !WordPress: 464 481 465 482 `kubectl get svc wordpress` 466 483 467 Then, in a web browser with the ssh tunnel, access WordPress:484 Then, in a web browser, access `WordPress`: 468 485 469 486 `http://< INTERNAL-IP>:<NODE_PORT>` 470 487 471 Part 5 488 489 == Part 5 == 472 490 473 491 Convert your Docker deployment into a Kubernetes deployment, you may compose your own service, deployment manifests as needed. Use the docker images you used previously when creating the pods/deployments. 474 492 493 475 494 Additional ref:[ https://kubebyexample.com/]