<?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>DEV Community: Charles Motaroki</title>
    <description>The latest articles on DEV Community by Charles Motaroki (@charles_motaroki).</description>
    <link>https://dev.to/charles_motaroki</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%2F909990%2F2d6144bf-41e4-40e9-8a52-fd01b382e103.png</url>
      <title>DEV Community: Charles Motaroki</title>
      <link>https://dev.to/charles_motaroki</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/charles_motaroki"/>
    <language>en</language>
    <item>
      <title>Kubernetes cheat sheet</title>
      <dc:creator>Charles Motaroki</dc:creator>
      <pubDate>Sun, 21 Aug 2022 14:36:10 +0000</pubDate>
      <link>https://dev.to/charles_motaroki/kubernetes-cheat-sheet-2f72</link>
      <guid>https://dev.to/charles_motaroki/kubernetes-cheat-sheet-2f72</guid>
      <description>&lt;p&gt;Learning Kubernetes can be a daunting task at first for any programmer. And like any other valuable skill worth learning, mastery of Kubernetes will test both your grit and resolve. The name itself is a mouthful with a little bit of jargon thrown around like pods and containers. Hopefully this quick read will help to demystify the mystery that is Kubernetes.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is Kubernetes?
&lt;/h2&gt;

&lt;p&gt;Kubernetes is is a container orchestration tool that was originally developed at Google for internal use within the company. They later open sourced it and now everyone including you and me can use it to manage containers. Most cloud providers not to mention Microsoft, Amazon and even Google, offer a managed Kubernetes service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do we even need containers?
&lt;/h2&gt;

&lt;p&gt;To answer this question first allow me to give you a brief history lesson on the evolution of how we deployed applications in the past. In the very beginning applications were designed to run on specific hardware. This meant that applications designed for Linux machines could not run on windows servers. Also, there was no way of allocating compute resources to multiple applications running on the same server. Organizations used to have specific servers for running databases, serving application content and storing backups. As you can imagine this was very expensive. Not to mention that once resources were provisioned for your application, once the quota was exceeded, your application crashed. Getting it back up would involve liaising with your server admin to restore functions. Managing dependencies was a nightmare as upgrading one application's dependencies would often break other applications using the same dependencies. There was need for a logical abstraction layer between the operating system layer and the application layer. Fast forward to the dawn of virtualization and hypervisors made it easier to not only share resources between multiple applications hosted on the same server, but also the underlying infrastructure was obfuscated. This made it possible to deploy applications to the same server without necessarily designing for multiple operating systems. &lt;br&gt;
One problem remained. Starting up virtual machine instances took time and they were bulky. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1tjk3CNU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ao49zb7c30aq7yud1x6t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1tjk3CNU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ao49zb7c30aq7yud1x6t.PNG" alt="Image description" width="761" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Enter containers📦&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Containers make it possible to package applications and the dependencies they require at runtime. This made running applications more predictable since now very little emphasis was placed on the underlying operating system. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n1juplyf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n76wbe0h8zufackdxf16.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n1juplyf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n76wbe0h8zufackdxf16.PNG" alt="Image description" width="684" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Containers make use of container runtimes with some of the more popular ones being Docker, Rocket and containerd. Containers alleviate most of the problems of virtualization since they are scalable, lightweight, more efficient and portable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So why Kubernetes?&lt;br&gt;
Containers come with their fair share of challenges. How do you scale containers, how do you make sure they know how to communicate with each other and how do you detect failing instances. These are some of the challenges Kubernetes seeks to solve. According to their site Kubernetes describes itself as an open-source system for automating deployment, scaling, and management of containerized applications.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  The cheat sheet
&lt;/h2&gt;

&lt;p&gt;Common kubectl commands:&lt;/p&gt;

&lt;p&gt;To view the configuration and print out the contents of the kubeconfig file&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To print out some details for all the cluster contexts in the kubeconfig file&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To print out the cluster information for the active context&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To print out the active context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl config current-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To change the active context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl config use-context &amp;lt;new_context&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get running nodes&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To view resource utilization across the nodes of the cluster&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To create a deployment from a YAML file&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 ./&amp;lt;filename&amp;gt;.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop a running container&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl scale --replicas=0 deployment/&amp;lt;name of deployment&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To deploy an nginx pod and rename it to nginx-1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create deployment --image nginx nginx-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the running deployments&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To see running pods&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To get a wide view of the pods deployed&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To view the complete details of the pod you just created&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl describe pod [pod_name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copying files into a pod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl cp ~/test.html [pod_name]:/usr/share/nginx/html/&amp;lt;filename&amp;gt;.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating a load balancing service to expose pods externally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl expose pod $my_nginx_pod --port 80 --type LoadBalancer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view replicasets&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To see the IP addresses of nodes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get into a pod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl exec -it [pod-name] bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check running services&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Generating a password for MYSQL when working with Kubernetes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create secret generic mysql-pass --from-literal=password=Password123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To display the logs and to stream new logs as they arrive (and also include timestamps for the running pod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl logs [pod_name] -f --timestamps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To retrieve the log file from the pod that ran a job&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl logs [POD-NAME]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Almost everything you need to know about distributed systems</title>
      <dc:creator>Charles Motaroki</dc:creator>
      <pubDate>Sat, 20 Aug 2022 19:19:00 +0000</pubDate>
      <link>https://dev.to/charles_motaroki/almost-everything-you-need-to-know-about-distributed-systems-8bb</link>
      <guid>https://dev.to/charles_motaroki/almost-everything-you-need-to-know-about-distributed-systems-8bb</guid>
      <description>&lt;h2&gt;
  
  
  What is a distributed system?
&lt;/h2&gt;

&lt;p&gt;A distributed system is a collection of computers that appears to its users as a single coherent system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Characteristics of a distributed system
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Availability&lt;/strong&gt; – i.e. resources on demand. Distributed systems are designed with multiple failover systems that ensure that traffic is always redirected to healthy instances that are able to serve the request. Users of the system are not concerned with which server delivered their request and if there are failing instances in the background.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; – Distributed systems are able to handle huge amounts in traffic by automatically adding instances when there is increase in network traffic and scaling down when the traffic reduces. One bottleneck to this approach is how to ensure data is routed to the correct instance. This is the work of load balancers. Load balancers are used to distribute traffic between multiple running instances in a network. Load balancers could either be hardware or software based. There are two types of scaling: horizontal scaling and vertical scaling. Horizontal scaling means adding more computing nodes while vertical scaling means adding more computing resources (CPU, RAM). &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Horizontal scalability is usually more desirable&lt;br&gt;
.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  History of distributed systems
&lt;/h2&gt;

&lt;p&gt;Advances in computing technology and high-speed networks made the area much more attractive. Traditional mainframe servers wasted a lot of resources since there was tight coupling between the kernel and application layer dependencies. This more often than not meant that there would be one server configured for databases, another for serving application content and another one for storing backups. Making changes to the architecture often took months of planning and consultations. This was quite expensive as this meant consulting professionals, shipping the hardware and scheduling downtimes for maintenance. To get an application up and running, you had to wait for this process to end in order to deploy. Since the application dependencies depended so much on the underlying operating system, applications designed for x86 and x64 bit machines would not necessarily work on linux kernel machines.&lt;br&gt;
Then came virtualization which encouraged loose coupling between the application and the operating system. In part this was achieved through the use of a hypervisor which is a logical layer between the operating system and the application. This basically meant that you could install multiple applications in the same server and they would share resources. However, as the application grew in size and more dependencies were added, managing them became difficult. Updating one application’s dependencies would often lead to breaking changes in other applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Come in distributed systems…
&lt;/h2&gt;

&lt;p&gt;As the nature of applications became more complex, suddenly engineers were required to make three-tiered web applications and microservices that were used by millions of users located is geographically diverse regions. Traditional on-premise architecture could not serve this niche of applications. Due to latency, users located further from the server would have awful user experiences because of increased round-trip times. In addition, this type of architecture was not optimized to handle spikes in network traffic. If network requests exceeded the hardware capacity, the server simply crashed. &lt;/p&gt;

&lt;h2&gt;
  
  
  Goals of a distributed system
&lt;/h2&gt;

&lt;p&gt;1)  &lt;strong&gt;Transparency&lt;/strong&gt; – Distributed systems hide the fact that the processes and resources are physically distributed across multiple computers&lt;br&gt;
2)  &lt;strong&gt;Resource sharing&lt;/strong&gt; – Distributed systems were designed to make it easier for users to access and share resources. &lt;br&gt;
3)  &lt;strong&gt;Concurrency&lt;/strong&gt; – A resource may be shared by several competitive users&lt;br&gt;
4)  &lt;strong&gt;Scalability&lt;/strong&gt; – A distributed system should remain effective when there is a significant increase in the number of users.&lt;br&gt;
5)  &lt;strong&gt;Openness&lt;/strong&gt; – A distributed system should be able to log out all processes that consume resources and previous activity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of a distributed system over a centralized system
&lt;/h2&gt;

&lt;p&gt;1)  &lt;strong&gt;Economics&lt;/strong&gt; – A collection of microprocessors offers a better price/performance ratio than traditional mainframes.&lt;br&gt;
2)  &lt;strong&gt;Reliability&lt;/strong&gt; – If one machine crashes, the system as a whole can survive. Batching and disk scheduling can be used to build systems whose efficiency increases with increase in load. As applications grow more popular, if the underlying architecture is not customized for stable performance under high load then crashes are inevitable. &lt;br&gt;
3)  &lt;strong&gt;Speed&lt;/strong&gt; – A distributed system may have more computing power than a mainframe.&lt;br&gt;
4)  &lt;strong&gt;Scalability&lt;/strong&gt; – Computing power can be added in small increments which leads to modular expandability.&lt;br&gt;
5)  &lt;strong&gt;Data sharing&lt;/strong&gt; – Multiple users of a distributed system can access a common database&lt;/p&gt;

&lt;h2&gt;
  
  
  Communication in distributed systems
&lt;/h2&gt;

&lt;p&gt;There are two types of protocols:&lt;br&gt;
1)  &lt;strong&gt;Connection oriented protocols&lt;/strong&gt; – Necessitates that before exchanging data, the sender and the receiver first establish a connection, negotiate the protocol they will use and after they are done they must terminate the connection.&lt;br&gt;
2)  &lt;strong&gt;Connectionless protocols&lt;/strong&gt; – No advance setup (pre-warming) is required. The sender just transmits the first message when it is ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of communication in distributed systems
&lt;/h2&gt;

&lt;p&gt;1)  &lt;strong&gt;Persistent&lt;/strong&gt; – A message that has been submitted for transmission is stored by the communication middleware for as long as it takes to deliver it to the receiver.&lt;br&gt;
2)  &lt;strong&gt;Transient&lt;/strong&gt; – A message is stored by the communication system only as long as the sending and receiving application are executing.&lt;br&gt;
3)  &lt;strong&gt;Asynchronous&lt;/strong&gt; – A sender continues immediately after it has submitted its message for transmission.&lt;br&gt;
4)  &lt;strong&gt;Synchronous&lt;/strong&gt; – The sender is blocked until its request is known to be accepted.&lt;br&gt;
5)  &lt;strong&gt;Discrete&lt;/strong&gt; – The parties communicate by messages. Each message forming a complete unit of information.&lt;br&gt;
6)  &lt;strong&gt;Streaming&lt;/strong&gt; – Involves sending messages one after another where the messages are related to each other by the order they are sent.&lt;br&gt;
7)  &lt;strong&gt;Multicast communication&lt;/strong&gt; – Application-level multicasting, Gossip-based message dissemination (max rounds, seeing nodes with message)&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of distributed systems
&lt;/h2&gt;

&lt;p&gt;1)  &lt;strong&gt;Distributed computing systems&lt;/strong&gt;&lt;br&gt;
I.  Cluster computing systems&lt;br&gt;
Supercomputers built from off the shelf hardware then placed in high-speed networks.&lt;br&gt;
Usually, a single program is run in parallel on multiple machines.&lt;br&gt;
II. Grid computing systems&lt;br&gt;
Composed of different types of computers&lt;br&gt;
2)  &lt;strong&gt;Distributed information systems&lt;/strong&gt;&lt;br&gt;
Made to distribute information across several servers.&lt;br&gt;
Often used with transaction systems i.e., banks and travel agencies. &lt;br&gt;
The most common communication methods include:&lt;br&gt;
I.  Remote procedure calls&lt;br&gt;
Preforming read operation in RPC &lt;br&gt;
i.  Client procedure calls the client stub&lt;br&gt;
ii. The client stub builds the message and calls the client operating system.&lt;br&gt;
iii.    The client operating system sends the message to the server operating system&lt;br&gt;
iv. The server operating system gives the message to the server stub&lt;br&gt;
v.  The server stub unpacks the parameters and calls the server process&lt;br&gt;
vi. The server process does the work and returns the result to the stub.&lt;br&gt;
II. Remote method invocations&lt;br&gt;
3)  &lt;strong&gt;Distributed pervasive systems&lt;/strong&gt; &lt;br&gt;
These are distributed systems involving mobile and embedded computer devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture of distributed systems
&lt;/h2&gt;

&lt;p&gt;Distributed systems architecture can further be broken down into:&lt;br&gt;
1)  &lt;strong&gt;Software architecture&lt;/strong&gt; – Describes how software components are organized&lt;br&gt;
Various software architecture patterns include:&lt;br&gt;
I.  Layered architecture&lt;br&gt;
II. Object based architecture&lt;br&gt;
III.    Data centered architecture&lt;br&gt;
IV. Event driven architecture – Communication happens through propagation of events&lt;br&gt;
V.  Serverless architecture&lt;br&gt;
VI. Micro Service architecture&lt;br&gt;
2)  &lt;strong&gt;System architecture&lt;/strong&gt; – Involves the installation and placement of software components on real machines&lt;br&gt;
Various types of systems architectures are:&lt;br&gt;
I.  &lt;strong&gt;Decentralized architecture&lt;/strong&gt; – Peer to peer system&lt;br&gt;
II. &lt;strong&gt;Centralized architecture&lt;/strong&gt; – client-server system&lt;br&gt;
III.    &lt;strong&gt;Hybrid architecture&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>computerscience</category>
      <category>systems</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
