'''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. ''' == Part 1 == '''Installing kubeadm, kubelet, and kubectl:''' 1. Update the apt package index: `sudo apt-get update` 2. Install packages needed to use the Kubernetes apt repository: `sudo apt-get install -y apt-transport-https ca-certificates curl vim git` 3. Download the public signing key for the Kubernetes package repositories: `curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg` 4. Add the Kubernetes apt repository: `echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list` Update the apt package index again: `sudo apt-get update` 5. Install kubelet, kubeadm, and kubectl:` `sudo apt-get install -y kubelet kubeadm kubectl` 6. Pin installed versions of kubelet, kubeadm, and kubectl to prevent them from being accidentally updated: `sudo apt-mark hold kubelet kubeadm kubectl` 7. Check installed versions: `kubectl version --client` `kubeadm version` '''Disable Swap Space''' 8. Disable all swaps from /proc/swaps. `sudo swapoff -a` `sudo sed -i.bak -r 's/(.+ swap .+)/#\1/' /etc/fstab` 9. Check if swap has been disabled by running the free command. `free -h` '''Install Container runtime''' 10. Configure persistent loading of modules {{{ #!sh sudo tee /etc/modules-load.d/k8s.conf <:30080` You should see the default nginx welcome page, indicating that your web application is running. Delete all the deployments, run below command: `kubectl delete deployment ` Delete all the Services, run below command: `kubectl delete service ` == Part 4 == '''Deploying !WordPress and MySQL on Kubernetes''' Installing dependancies: Download rancher.io/local-path storage class: `kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml` Check with `kubectl get storageclass` Make this storage class (local-path) the default: `kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'` 1. Create a PersistentVolumeClaim for MySQL: MySQL needs persistent storage to store its data. Save the following YAML to a file named `mysql-pvc.yaml`: {{{ #!python apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi }}} Apply the PVC: `kubectl apply -f mysql-pvc.yaml` 2. Deploy MySQL: Save the following YAML to a file named `mysql-deployment.yaml`: {{{ #!python apiVersion: apps/v1 kind: Deployment metadata: name: mysql spec: replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "password" - name: MYSQL_DATABASE value: "wordpress" ports: - containerPort: 3306 volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pvc }}} Apply the Deployment: `kubectl apply -f mysql-deployment.yaml` 3. Create a Service for MySQL: This will allow !WordPress to communicate with MySQL. Save the following YAML to a file named `mysql-service.yaml`: {{{ #!python apiVersion: v1 kind: Service metadata: name: mysql spec: selector: app: mysql ports: - protocol: TCP port: 3306 targetPort: 3306 }}} Apply the Service: `kubectl apply -f mysql-service.yaml` 4. Deploy !WordPress: Save the following YAML to a file named wordpress-deployment.yaml: {{{ #!python apiVersion: apps/v1 kind: Deployment metadata: name: wordpress spec: replicas: 1 selector: matchLabels: app: wordpress template: metadata: labels: app: wordpress spec: containers: - name: wordpress image: wordpress:latest env: - name: WORDPRESS_DB_HOST value: mysql - name: WORDPRESS_DB_USER value: "root" - name: WORDPRESS_DB_PASSWORD value: "password" ports: - containerPort: 80 }}} Apply the Deployment: `kubectl apply -f wordpress-deployment.yaml` 5. Create a Service for WordPress: This will expose !WordPress to external traffic. Save the following YAML to a file named `wordpress-service.yaml`: {{{ #!python apiVersion: v1 kind: Service metadata: name: wordpress spec: selector: app: wordpress ports: - protocol: TCP port: 80 targetPort: 80 type: NodePort }}} Apply the Service: `kubectl apply -f wordpress-service.yaml` 6. Access WordPress: Since we used a !NodePort service, !WordPress should be accessible on node's IP at a dynamically allocated port above 30000. To find the !NodePort assigned to !WordPress: `kubectl get svc wordpress` Then, in a web browser, access `WordPress`: `http://< INTERNAL-IP>:` == Part 5 == 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. Additional ref:[ https://kubebyexample.com/]