<?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>Debug School: Adam R</title>
    <description>The latest articles on Debug School by Adam R (@adamr1776).</description>
    <link>https://www.debug.school/adamr1776</link>
    <image>
      <url>https://www.debug.school/images/6Zn-ICSCA03mjfvxpqxup8FwRMD9PMZiS69g8-S_st0/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvdXNl/ci9wcm9maWxlX2lt/YWdlLzcyMi84NmJm/ZjZlMy1mOGEyLTQ5/NDEtOTVjMC1kOGIx/Yjc4ZTIxMjkucG5n</url>
      <title>Debug School: Adam R</title>
      <link>https://www.debug.school/adamr1776</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://www.debug.school/feed/adamr1776"/>
    <language>en</language>
    <item>
      <title>Day 3 summary - Adam</title>
      <dc:creator>Adam R</dc:creator>
      <pubDate>Wed, 18 Oct 2023 12:01:25 +0000</pubDate>
      <link>https://www.debug.school/adamr1776/day-3-summary-adam-2ppi</link>
      <guid>https://www.debug.school/adamr1776/day-3-summary-adam-2ppi</guid>
      <description>&lt;p&gt;&lt;strong&gt;Configmap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How can we save data in a k8 cluster (such as certificates, passwords, important configuration files) that can be used by pods?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is where configmap is useful. You can get the configmaps using &lt;code&gt;kubectl get cm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Note that configmaps exist at the cluster level.&lt;/li&gt;
&lt;li&gt;By default, one configmap is created per [[namespace]]. You can create additional configmaps as needed using &lt;code&gt;kubectl create configmap adam-cm --from-file=configFile.conf&lt;/code&gt;. This will create a configmap called adam-cm, and the contents of this cm will be taken from the configuration file we specified.&lt;/li&gt;
&lt;li&gt;Alternately, you can also create a configmap declaratively using something like &lt;code&gt;kubectl apply -f cm.yaml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A [[pod]] can be access the contents of a cm by having a volume specified in the pod's spec mapped to the configmap. All the containers within the pod can then access the contents of the configmap via volume mounting. Here is an example of a pod that accesses a cm via volume mounting: &lt;a href="///assets/pod2.yaml"&gt;pod2.yaml&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Once it is mounted in a pod, you can validate it with &lt;code&gt;kubectl exec -it helloworld-nginx /bin/bash&lt;/code&gt; and &lt;code&gt;cd /etc/nginx/conf.d&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DaemonSet&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;kubectl get ds&lt;/code&gt; will show you the daemonsets, therefore &lt;code&gt;ds&lt;/code&gt; is a shortcut to for daemonsets in k8&lt;/li&gt;
&lt;li&gt;deamonset allows you to run a deamon [[Pod]] in each worker (i.e. each node). It is useful for running logging and monitoring applications to keep an eye on the nodes. Daemonset ensures that exactly one pod is active per [[worker]] node.&lt;/li&gt;
&lt;li&gt;daemonsets pods, like any other pod, are also logically separated by namespaces. Therefore, if you have multiple namespaces running on a worker node, each of those namespaces can have their own deamonset pod even if they're running on the same node.&lt;/li&gt;
&lt;li&gt;You can start a daemonset using &lt;code&gt;kubectl apply -f ds.yaml&lt;/code&gt; optionally specifying namespaces. Here's a sample yaml: &lt;a href="///assets/ds.yaml"&gt;ds.yaml&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Like most other k8 entities, you can &lt;code&gt;kubectl describe ds&lt;/code&gt; on daemonsets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** Service/Ingress/NodePort&lt;/p&gt;

&lt;p&gt;Service in kubernetes is essentially network load balancing for the various [[pod]] in the cluster.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Application load balancer in kubernetes is known as egress.&lt;/li&gt;
&lt;li&gt;Service acts as a bridge for network communication between pods. The service also acts similar to a pod, but it is managed by the cluster.&lt;/li&gt;
&lt;li&gt;For example if you have 5 frontend pods and 3 backend pods, and the IP addresses of all eight pods are changing as pods come up and go down. In this case, the frontend pods will not know which backend pod address to call. Service solves this problem by having the frontend call the service IP address, and service will redirect to one of the backend pods.&lt;/li&gt;
&lt;li&gt;Labels are used with services to setup filtering and inform the service of new pods. If the labels pods matches the &lt;code&gt;selector&lt;/code&gt; label of the service, those pods will be load balanced by the service. 

&lt;ul&gt;
&lt;li&gt;Therefore, if you have pods and a service running and you want the service to load balance those pods, you can either update all the pod labels to match the service selector, or you could update the service selector to match all the pods.&lt;/li&gt;
&lt;li&gt;Once any pods with a label matching the service selector come up, the service will automatically discover those new pods and start load balancing them as well.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Services should only be used to load balance similar or interchangeable pods! Therefore, all the pod labels and service selector should be identical. This is obvious, since the whole point of load balancing is that any of the pods can be used to service the request. For example, you should &lt;strong&gt;not&lt;/strong&gt; have a service load balancing both backend pods and DB pods since they are not the same thing!&lt;/li&gt;
&lt;li&gt;The load balancing algorithm used by service is random allocation.&lt;/li&gt;
&lt;li&gt;The service is therefore the entry point for a particular type of microservice (i.e. a particular type of pod). The service can also be accessed outside the cluster if configured.&lt;/li&gt;
&lt;li&gt;You can create a service using command by typing &lt;code&gt;kubectl create svc&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Once you create a service, it will have a cluster IP address and port number. This IP address is named as such because it is only accessible at that address within the cluster.&lt;/li&gt;
&lt;li&gt;To start a service for existing pods:

&lt;ul&gt;
&lt;li&gt;First check the pods exist and get their labels using &lt;code&gt;kubectl get pods -n=adam --show-labels&lt;/code&gt;. This command will display the pods in [[namespace]] adam assuming it exists.&lt;/li&gt;
&lt;li&gt;Check the IP addresses of these nodes with &lt;code&gt;kubectl get pods -o wide -n=adam&lt;/code&gt;. You can try hitting one of them with curl to make sure it's responsive (assuming these pods are running web servers)&lt;/li&gt;
&lt;li&gt;Create a service with &lt;code&gt;kubectl create service clusterip adam-svc --tcp=5678:80 -n=adam&lt;/code&gt; to create a service that listens to port 5678, and forwards the requests to port 80 on the pods.&lt;/li&gt;
&lt;li&gt;Verify the service exists with &lt;code&gt;kubectl get svc -n=adam&lt;/code&gt;. Then get more details about it with &lt;code&gt;kubectl describe svc adam-svc -n=adam&lt;/code&gt;. It will show the service's cluster IP, it's selector, and other info.&lt;/li&gt;
&lt;li&gt;If you hit the service's cluster IP at the configured port, for example with &lt;code&gt;curl http://10.103.249.69:5678&lt;/code&gt;, nothing much happens because the service has not yet started load balancing any pods.&lt;/li&gt;
&lt;li&gt;To make the service start load balancing our pods, edit it with &lt;code&gt;kubectl edit svc adam-svc -n=adam&lt;/code&gt; and set the selector in spec/selector/app to match the label of our pods. Verify that the service selector has been changed with &lt;code&gt;kubectl describe svc adam-svc --show-labels -n=adam&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Watch the service's cluster IP and port, using for example &lt;code&gt;watch curl http://10.96.48.229:5678&lt;/code&gt; to see the results. Note that if both pods running completely identical containers, you may not see anything because even though both pods are being hit, they both return the same thing!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The command &lt;code&gt;kubectl expose&lt;/code&gt; can be used to expose a resource as a new service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Note&lt;/strong&gt;: It's important to understand that the service acts as a load balancer between pods within the cluster! It does not act as a load balancer between the actual nodes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  NodePort
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;By default, pods running in a cluster are not accessible outside the cluster. &lt;/li&gt;
&lt;li&gt;NodePort is a type of service that acts a bridge between outside users and the cluster. If you just set the &lt;code&gt;spec.type&lt;/code&gt; of a service as NodePort, it enables this functionality. You could do this by adding option &lt;code&gt;--type=NodePort&lt;/code&gt;. Or you can &lt;code&gt;kubectl edit svc&lt;/code&gt; an existing service and change the &lt;code&gt;spec.type&lt;/code&gt; field to NodePort.&lt;/li&gt;
&lt;li&gt;When you create a NodePort, all the nodes in the cluster will start listening to the NodePort port number for external traffic! When any of the nodes receives traffic at that port number, &lt;code&gt;kube-proxy&lt;/code&gt; will forward it to the cluster IP address of the service.&lt;/li&gt;
&lt;li&gt;Now &lt;code&gt;kubectl describe&lt;/code&gt; the NodePort svc you created to get it's NodePort, it'll be something like 31319/TCP as an example. Now if you go to &lt;a href="http://nodeip:31319"&gt;http://nodeip:31319&lt;/a&gt;, you are hitting the NodePort service from outside the cluster. Note that services, including NodePorts, only do load balancing at the pod level, not the node level. So if you keep hitting &lt;a href="http://nodeip:31319"&gt;http://nodeip:31319&lt;/a&gt;, the it will be serviced by that particular node.&lt;/li&gt;
&lt;li&gt;Therefore, to achieve true node level load balancing we would need an outside network load balancer that resides outside the cluster, which would balance the traffic between different nodes, all of which are listening at port 31319.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Ingress
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ingress is another mechanism to allow external traffic to the services and to achieve application layer load balancing.&lt;/li&gt;
&lt;li&gt;Ingress allows you set rules to redirect external traffic to various services. This eliminate the problem where you'd need one load balancer for each of the services inside the cluster, which is too expensive. With ingress you only need one load balancer.&lt;/li&gt;
&lt;li&gt;You need a domain name to use Ingress&lt;/li&gt;
&lt;li&gt;Ingress can be name based, path based, certificate based...&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>What is a pod by Adam</title>
      <dc:creator>Adam R</dc:creator>
      <pubDate>Mon, 16 Oct 2023 11:47:07 +0000</pubDate>
      <link>https://www.debug.school/adamr1776/what-is-a-pod-by-adam-2550</link>
      <guid>https://www.debug.school/adamr1776/what-is-a-pod-by-adam-2550</guid>
      <description>&lt;p&gt;A pod is a group of containers and is smallest unit of execution in kubernetes. The scheduler in k8 master node does not deal with containers when scheduling work, it assigns work to pods. It's important to note that pods are a logical construct in k8. As such, pods do not consume memory or CPU themselves. The underlying containers within a pod consume computing power, but the pod itself doesn't. The pod is therefore said to be instantiated, and not created. Also, pods are created by the kubelet within worker nodes. If a pod is not managed by kubernetes, it is referred to as a static pod. Since pods are the smallest logical unit of execution in kubernetes, it has an IP address and each container within the pod shares that IP address. Pods can run on either the master node, or on worker nodes. Each pod has a main container, and it can also have secondary containers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Assignment 1 - What is kubernetes by Adam</title>
      <dc:creator>Adam R</dc:creator>
      <pubDate>Mon, 16 Oct 2023 07:07:16 +0000</pubDate>
      <link>https://www.debug.school/adamr1776/assignment-1-what-is-kubernetes-by-adam-4hca</link>
      <guid>https://www.debug.school/adamr1776/assignment-1-what-is-kubernetes-by-adam-4hca</guid>
      <description>&lt;p&gt;&lt;strong&gt;1) What is kubernetes?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes is an open source software that is used for container orchestration. To be more specific, k8 allows for the management of a large number of containers to increase scalability and reliability of a system. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Why do we need kubernetes?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need kubernetes because using standalone containers does not provide a mechanism to manage the host. For example, one problem is that if you have multiple standalone containers running on a host, there is no good way to use them with a network load balancer because each container running on the host would need its own port number, but load balancers only work with a single port number. This is a problem since it limits the number of containers we can realistically use per host in a large system. K8 with its container orchestration mechanism solves this problem. Furthermore, K8 is needed to scale container based software to handle lots of traffic reliably. K8 can create thousands of containers as needed to meet demand. This is something that is not feasible if we are managing standalone containers without a tool like k8.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) How does kubernetes work?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes works by having all the containers work as a team instead of working completely independently. It does this by forming a 'cluster' in which all containers run. Each container in the cluster is stateless and replaceable. K8 manages the containers and the hosts, and can start and shut down containers as needed to meet the desired state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) Kubernetes architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes architecture consists of a few key components:&lt;/p&gt;

&lt;p&gt;Node: Refers to any machine containers can run on (either physical machine or VM).&lt;/p&gt;

&lt;p&gt;Master server: This is a designated node that exercises authority over the worker nodes. It maintains state, assigns tasks, and can shut down or create containers as needed. Note that the master server has sub-components such as api-server, cluster store, controller of containers, and scheduler.&lt;/p&gt;

&lt;p&gt;Worker node: This is a node that performs the actual work (i.e. runs containers). The worker node receives instructions from the master node on what work needs to be done. It can also create pods for the containers to run in. It has also has a few subcomponents such as kubelet, container engine, and proxy&lt;/p&gt;

&lt;p&gt;Pods: Pods are a logical construct in k8 and are used to group containers. Each container in a pod has the same IP address.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
