K8s Deployment to Digital ocean

mcjovial

Emmanuel Elias

Posted on February 12, 2023

K8s Deployment to Digital ocean

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
Enter fullscreen mode Exit fullscreen mode

3. Install Docker:

  • Update the package index on your droplet:
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  • Install Docker by running the following command:
sudo apt install docker.io
Enter fullscreen mode Exit fullscreen mode
  • Start the Docker service and configure it to start at boot:
sudo systemctl start docker
sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode

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 -
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode
  • Update the package index and install Kubernetes:
sudo apt update
sudo apt install -y kubeadm kubelet kubectl
Enter fullscreen mode Exit fullscreen mode

5. Initialize the Kubernetes cluster:

  • Run the following command to initialize the cluster:
sudo kubeadm init
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

or

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Test that your kubectl client is properly configured by running the following command:
kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Check the status of your deployment:
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

9. Expose your application:

  • Create a service to expose your application:
kubectl expose deployment <your_deployment_name> --type=LoadBalancer --port=<your_port>
Enter fullscreen mode Exit fullscreen mode
  • Verify that the service is running:
kubectl get services
Enter fullscreen mode Exit fullscreen mode

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

💖 💪 🙅 🚩
mcjovial
Emmanuel Elias

Posted on February 12, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

K8s Deployment to Digital ocean
kubernetes K8s Deployment to Digital ocean

February 12, 2023