K8s Deployment to Digital ocean
Tags: kubernetes, docker, cloud, digitalocean
Published: 2023-02-12 05:41:47

Kubernetes (often abbreviated as "k8s") is a powerful open-source platform for automating the deployment, scaling, and management of containerized applications.

In simpler terms, k8s helps you run and manage your application, which is packaged as a container, in a cluster of computers. The cluster of computers can be either physical or virtual machines. With k8s, you can define how many copies of your application you want to run, how they should communicate with each other, and how they should be updated or scaled.

Kubernetes provides you with the ability to automate many of the tasks involved in deploying and managing containers, such as automatic scaling, self-healing, and rolling updates. This makes it easier for you to focus on writing code, while k8s takes care of the underlying infrastructure.

Overall, k8s helps you deploy and manage your applications in a more efficient and effective manner, ensuring that they are highly available and scalable.

_I know its boring already_ 😂
well here we go.

The following is a step-by-step procedure on how to deploy a Kubernetes (k8s) project to a DigitalOcean Linux server:

**1. Create a DigitalOcean Droplet:**
- Log in to your DigitalOcean account, and navigate to the "**_Create_**" menu.
- Choose the "_**Droplets**_" option, and select the "**_Ubuntu 20.04_**" image.
- Choose the size and region for your Droplet.
- Add any optional features you would like, such as **backups** or additional **block storage**.
- Add your SSH key, if you have one. If not, you will need to create one.
- Choose a **hostname** for your Droplet and click the "_**Create**_" button.

**2. Connect to the Droplet via SSH:**
- From your local machine, open a terminal or command prompt window.
- Use the `ssh` command to connect to your **Droplet** using its `IP address` and your `username`:

```
ssh root@your_droplet_ip_address
```

**3. Install Docker:**
- Update the package index on your droplet:

```
sudo apt update
```
- Install Docker by running the following command:

```
sudo apt install docker.io
```
- Start the Docker service and configure it to start at boot:

```
sudo systemctl start docker
sudo systemctl enable docker
```

**4. Install Kubernetes:**
- Add the Kubernetes package signing key:

```
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
```
- Add the Kubernetes repository to the system's package sources:
```
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
```
- Update the package index and install Kubernetes:
```
sudo apt update
sudo apt install -y kubeadm kubelet kubectl
```

**5. Initialize the Kubernetes cluster:**
- Run the following command to initialize the cluster:
```
sudo kubeadm init
```

**6. Set up the cluster's networking:**
- For most use cases, it is recommended to use a network plugin such as Calico or Flannel. You can install one of these plugins by running the appropriate command, such as:

```
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
```
or
```
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
```
**7. Configure the kubectl client:**
- After the cluster is initialized, you will need to configure your local kubectl client to access the cluster. You can do this by copying the configuration file to your local machine:

```
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```
- Test that your kubectl client is properly configured by running the following command:

```
kubectl get nodes
```
You should see a list of nodes in your cluster.
That's it! Your cluster's networking is now set up, and your `kubectl` client is properly configured to access the cluster.


**8. Deploy your k8s project:**
- Copy your project files to the droplet.
- Use the kubectl command to deploy your application to the cluster.
```
kubectl apply -f <your_deployment_file>.yaml
```
- Check the status of your deployment:

```
kubectl get pods
```

**9. Expose your application:**
- Create a service to expose your application:

```
kubectl expose deployment <your_deployment_name> --type=LoadBalancer --port=<your_port>
```
- Verify that the service is running:

```
kubectl get services
```

That's it! Your k8s project should now be deployed!✌🏿