Changes between Version 8 and Version 9 of minikubedeployment2023


Ignore:
Timestamp:
Dec 8, 2023, 2:34:51 PM (15 months ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • minikubedeployment2023

    v8 v9  
    11'''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.
    22'''
    3 ==== Part 1 ====
     3== Part 1 ==
    44
    55'''Installing kubeadm, kubelet, and kubectl:'''
     
    3939`kubeadm version`
    4040 
     41
    4142'''Disable Swap Space'''
    4243
     
    5051
    5152`free -h`
    52  
     53
     54
    5355'''Install Container runtime'''
    5456
     
    5658
    5759{{{
     60#!sh
    5861sudo tee /etc/modules-load.d/k8s.conf <<EOF
    5962overlay
    6063br_netfilter
    61 EOF 
     64EOF
    6265}}}
    6366
     
    7174
    7275{{{
    73 sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
     76#!sh
     77sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
    7478net.bridge.bridge-nf-call-ip6tables = 1
    7579net.bridge.bridge-nf-call-iptables = 1
     
    114118
    115119{{{
     120#!sh
    116121br_netfilter           22256  0
    117122bridge                151336  1 br_netfilter
     
    132137You will see Your Kubernetes control-plane has initialized successfully!
    133138
    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
     14122. To start the cluster, you need to run the following as a regular user (For this scenario we will only use a single master):
    137142 
    138 ` mkdir -p $HOME/.kube`
    139 
    140 `  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config`
    141 
    142 `  sudo chown $(id -u):$(id -g) $HOME/.kube/config`
     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`
    143148
    14414923. Check cluster info:
     
    164169
    16517028. 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 ==
     186Create a file `simple-pod.yaml`
     187
     188{{{
     189#!python
    187190apiVersion: v1
    188191kind: Pod
     
    209212`kubectl delete pod nginx`
    210213
    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 ====
     214Pods are generally not created directly and are created using workload resources.
     215
     216See 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 ==
    215219
    216220'''Deploying a Simple Web Application on Kubernetes'''
     
    219223
    220224A 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 {{{
     225Save the following YAML to a file named `webapp-deployment.yaml`:
     226
     227{{{
     228#!python
    224229apiVersion: apps/v1
    225230kind: Deployment
     
    249254A 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.
    250255
    251 Save the following YAML to a file named webapp-service.yaml:
    252 
    253 {{{
     256Save the following YAML to a file named `webapp-service.yaml`:
     257
     258{{{
     259#!python
    254260apiVersion: v1
    255261kind: Service
     
    271277
    272278`kubectl apply -f webapp-deployment.yaml`
     279
    273280`kubectl apply -f webapp-service.yaml`
     281
    274282
    2752834. Verify the Deployment:
     
    277285
    278286`kubectl get deployments`
     287
    279288`kubectl get services`
    280289
     290
    281291You should see your webapp-deployment with 2 replicas. Give it a time to take both replicas online.
    282292
    2832935. Access the Web Application:
    284294
    285 Since we used a NodePort service, the web application should be accessible on node's IP at port 30080.
     295Since we used a !NodePort service, the web application should be accessible on node's IP at port 30080.
    286296If you're unsure of your node IPs, you can get them with:
    287297
     
    290300Then, in a web browser or using a tool like curl, access the web application:
    291301
    292 `curl http://<NODE_IP>:30080`
     302`curl http://<MASTER/NODE_IP>:30080`
    293303
    294304You should see the default nginx welcome page, indicating that your web application is running.
     
    302312`kubectl delete service <service name>`
    303313 
    304 Part 4
    305 
    306 '''Deploying WordPress and MySQL on Kubernetes'''
     314
     315== Part 4 ==
     316
     317'''Deploying !WordPress and MySQL on Kubernetes'''
    307318
    308319Installing dependancies:
     
    312323`kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml`
    313324
    314 Check with kubectl get storageclass
     325Check with `kubectl get storageclass`
     326
    315327Make this storage class (local-path) the default:
    316328
     
    3193311. Create a PersistentVolumeClaim for MySQL:
    320332
    321 MySQL needs persistent storage to store its data. Save the following YAML to a file named mysql-pvc.yaml:
    322 
    323 {{{
     333MySQL needs persistent storage to store its data. Save the following YAML to a file named `mysql-pvc.yaml`:
     334
     335{{{
     336#!python
    324337apiVersion: v1
    325338kind: PersistentVolumeClaim
     
    339352
    3403532. Deploy MySQL:
    341 Save the following YAML to a file named mysql-deployment.yaml:
    342 
    343 {{{
     354Save the following YAML to a file named `mysql-deployment.yaml`:
     355
     356{{{
     357#!python
    344358apiVersion: apps/v1
    345359kind: Deployment
     
    3813953. Create a Service for MySQL:
    382396
    383 This will allow WordPress to communicate with MySQL. Save the following YAML to a file named mysql-service.yaml:
    384 
    385 {{{
     397This will allow !WordPress to communicate with MySQL. Save the following YAML to a file named `mysql-service.yaml`:
     398
     399{{{
     400#!python
    386401apiVersion: v1
    387402kind: Service
     
    400415`kubectl apply -f mysql-service.yaml`
    401416
    402 4. Deploy WordPress:
     4174. Deploy !WordPress:
    403418Save the following YAML to a file named wordpress-deployment.yaml:
    404419
    405420{{{
     421#!python
    406422apiVersion: apps/v1
    407423kind: Deployment
     
    4374535. Create a Service for WordPress:
    438454
    439 This will expose WordPress to external traffic. Save the following YAML to a file named wordpress-service.yaml:
    440 
    441 {{{
     455This will expose !WordPress to external traffic. Save the following YAML to a file named `wordpress-service.yaml`:
     456
     457{{{
     458#!python
    442459apiVersion: v1
    443460kind: Service
     
    4604776. Access WordPress:
    461478
    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 to WordPress:
     479Since we used a !NodePort service, !WordPress should be accessible on node's IP at a dynamically allocated port above 30000.
     480To find the !NodePort assigned to !WordPress:
    464481
    465482`kubectl get svc wordpress`
    466483
    467 Then, in a web browser with the ssh tunnel, access WordPress:
     484Then, in a web browser, access `WordPress`:
    468485
    469486`http://< INTERNAL-IP>:<NODE_PORT>`
    470487 
    471 Part 5
     488
     489== Part 5 ==
    472490
    473491Convert 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.
    474492 
     493
    475494Additional ref:[ https://kubebyexample.com/]