<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Emmanuel Elias</title>
    <description>The latest articles on Forem by Emmanuel Elias (@mcjovial).</description>
    <link>https://forem.com/mcjovial</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F683817%2Fb36c360c-f500-44e9-9f2a-5bc5fa97ed07.jpg</url>
      <title>Forem: Emmanuel Elias</title>
      <link>https://forem.com/mcjovial</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mcjovial"/>
    <language>en</language>
    <item>
      <title>K8s Deployment to Digital ocean</title>
      <dc:creator>Emmanuel Elias</dc:creator>
      <pubDate>Sun, 12 Feb 2023 05:41:47 +0000</pubDate>
      <link>https://forem.com/mcjovial/k8s-deployment-to-digital-ocean-199n</link>
      <guid>https://forem.com/mcjovial/k8s-deployment-to-digital-ocean-199n</guid>
      <description>&lt;p&gt;Kubernetes (often abbreviated as "k8s") is a powerful open-source platform for automating the deployment, scaling, and management of containerized applications.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;I know its boring already&lt;/em&gt; 😂&lt;br&gt;
well here we go.&lt;/p&gt;

&lt;p&gt;The following is a step-by-step procedure on how to deploy a Kubernetes (k8s) project to a DigitalOcean Linux server:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a DigitalOcean Droplet:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in to your DigitalOcean account, and navigate to the "&lt;strong&gt;&lt;em&gt;Create&lt;/em&gt;&lt;/strong&gt;" menu.&lt;/li&gt;
&lt;li&gt;Choose the "&lt;em&gt;&lt;strong&gt;Droplets&lt;/strong&gt;&lt;/em&gt;" option, and select the "&lt;strong&gt;&lt;em&gt;Ubuntu 20.04&lt;/em&gt;&lt;/strong&gt;" image.&lt;/li&gt;
&lt;li&gt;Choose the size and region for your Droplet.&lt;/li&gt;
&lt;li&gt;Add any optional features you would like, such as &lt;strong&gt;backups&lt;/strong&gt; or additional &lt;strong&gt;block storage&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Add your SSH key, if you have one. If not, you will need to create one.&lt;/li&gt;
&lt;li&gt;Choose a &lt;strong&gt;hostname&lt;/strong&gt; for your Droplet and click the "&lt;em&gt;&lt;strong&gt;Create&lt;/strong&gt;&lt;/em&gt;" button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Connect to the Droplet via SSH:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From your local machine, open a terminal or command prompt window.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;ssh&lt;/code&gt; command to connect to your &lt;strong&gt;Droplet&lt;/strong&gt; using its &lt;code&gt;IP address&lt;/code&gt; and your &lt;code&gt;username&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh root@your_droplet_ip_address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3. Install Docker:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update the package index on your droplet:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Install Docker by running the following command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install docker.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Start the Docker service and configure it to start at boot:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start docker
sudo systemctl enable docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;4. Install Kubernetes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the Kubernetes package signing key:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add the Kubernetes repository to the system's package sources:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Update the package index and install Kubernetes:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install -y kubeadm kubelet kubectl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;5. Initialize the Kubernetes cluster:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the following command to initialize the cluster:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo kubeadm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;6. Set up the cluster's networking:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;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:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Configure the kubectl client:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;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:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Test that your kubectl client is properly configured by running the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a list of nodes in your cluster.&lt;br&gt;
That's it! Your cluster's networking is now set up, and your &lt;code&gt;kubectl&lt;/code&gt; client is properly configured to access the cluster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Deploy your k8s project:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy your project files to the droplet.&lt;/li&gt;
&lt;li&gt;Use the kubectl command to deploy your application to the cluster.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f &amp;lt;your_deployment_file&amp;gt;.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check the status of your deployment:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Expose your application:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a service to expose your application:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl expose deployment &amp;lt;your_deployment_name&amp;gt; --type=LoadBalancer --port=&amp;lt;your_port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Verify that the service is running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Your k8s project should now be deployed!✌🏿&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>docker</category>
      <category>cloud</category>
      <category>digitalocean</category>
    </item>
  </channel>
</rss>
