<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ozan Eren on Medium]]></title>
        <description><![CDATA[Stories by Ozan Eren on Medium]]></description>
        <link>https://medium.com/@oziie?source=rss-ebf1e32e203a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*sgvGOsHTvwdXf4ZlD0W5sQ.jpeg</url>
            <title>Stories by Ozan Eren on Medium</title>
            <link>https://medium.com/@oziie?source=rss-ebf1e32e203a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 22:59:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oziie/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kubernetes Clusters Management Maturity: Cluster API, Kamaji and More]]></title>
            <link>https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/kubernetes-clusters-management-maturity-cluster-api-kamaji-and-more-667852bd52a4?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/667852bd52a4</guid>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Wed, 04 Mar 2026 07:18:27 GMT</pubDate>
            <atom:updated>2026-03-08T21:18:09.733Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqNqifULb-ZeP4LBDjpwFw.png" /></figure><p>🆓 <em>AI free! This article is written without using any AI tool.</em></p><p>📌 <strong><em>TL;DR</em></strong> <em>In this article, I explain how you can manage your multiple Kubernetes clusters at advance level by using tools like ClusterAPI and Kamaji. You will find informations that explains the idea behind those tools and quick start guide, use case references. Story is not practical guide completely but is mostly theoretical. Additionally, the story includes use cases part that explains briefly and share some resources about how to handle management &amp; provisioning of multiple Kubernetes clusters in Openstack and Kubevirt platforms.</em></p><h3>💸 Cluster Management Cost</h3><p>Kubernetes is a system that bunch of APIs/components that creates a structure: ‘cluster’. The cluster you designed &amp; provisioned on your desired platform… In general manner, it’s responsible from deploying, scaling and managing lifecycle of your workloads.</p><p>As dependent on case, a single cluster will suffice when you need a test purpose architecture that is not typically shared. On the other hand, if you separate your workloads as application-based, business unit-based etc. and need to scale high-capacity, efficient production workloads, you will need multiple Kubernetes clusters in your architecture. Most of the time, if you’ve done somethings correct while setup a single cluster, it will work like a charm and you will manage seamlessly. However, conditions become challenging if you decide to manage multiple clusters.</p><p>Every Kubernetes cluster comes with a management cost. Think setup of underlying infrastructure(compute, storage networking etc.), maintenance, monitoring and so many other operations. In an environment that you manage your own cloud/private Kubernetes environments, those operations requires considerable effort. Let’s call it “management cost” as this effort means mostly time/money that you spend. If you imagine to manage multi-clusters and you’re not using a complete solution like OCP ACM(Openshift Advance Cluster Management) etc. such costs will continue to increase exponentially. <em>(to be honest, using enterprise tools decreases complexity/time effort, while increasing financial effort anyway.)</em></p><p>As every business, we want to keep our costs at minimal level. Therefore, we need logical management tools to help us on this mater. Here, in the area of Kubernetes, we’ve quite good toolsets. In this story, we will examine Cluster API and Kamaji.</p><h3>🐢 Kubernetes for Kubernetes: Cluster API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*Wi-fEetjDGYhZbU0NyX3Rg.png" /></figure><p><a href="https://cluster-api.sigs.k8s.io/"><strong>Cluster API</strong></a> is an project that provides extended capability and declarative APIs which are developed by SIG to simplify operations like provisioning, upgrading, and operating multiple Kubernetes clusters.</p><p>Despite having bootstrapping tools like Kubeadm and many other tools that reduce complexity during installation of Kubernetes cluster, they don’t address how to manage &amp; automate a Kubernetes environment, lifecycle daily or long term. As officially stated in the documentation, Cluster API aims exactly such points:</p><blockquote>- How can I consistently provision machines, load balancers, VPC, etc., across multiple infrastructure providers and locations?</blockquote><blockquote>- How can I automate cluster lifecycle management, including things like upgrades and cluster deletion?</blockquote><blockquote>- How can I scale these processes to manage any number of clusters?</blockquote><p>As mentioned headline of this section, with Cluster API basically, we use a Kubernetes to perform such operations on other Kubernetes clusters. Therefore we have two cluster concepts here:</p><ul><li><strong>Management cluster</strong> is a Kubernetes cluster used to deploy and manage other clusters. This cluster contains all the necessary Cluster API components and is responsible for describing, creating, and updating tenant clusters. It is often used just for this purpose.</li><li><strong>Tenant clusters</strong> are the user clusters or clusters deployed using the Cluster API. They are created by describing the relevant resources in the management cluster. They are then used for deploying applications and services by end-users. There is no obligation to work same platform with management cluster. Instead, they usually working another platform.</li></ul><p>Cluster API has lot’s of <a href="https://cluster-api.sigs.k8s.io/user/concepts">components and CRDs</a>. Let’s check some of them without going deep dive:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkFaow-VdC_bXGmJgLFK4Q.png" /><figcaption>Cluster API Components</figcaption></figure><ul><li><strong>Infrastructure Provider</strong>, provides cluster compute resources from the platform that will be used. For example, EC2 machines for AWS, VMs for VMware etc.</li><li><strong>Control Plane Provider</strong>, provides control plane of your Kubernetes cluster, namely the components kube-apiserver, kube-scheduler, and kube-controller-manager. Few examples: the KubeadmControlPlane is a provider. <strong><em>Kamaji</em></strong> is another controplane provider as I explained in later parts of story.<br>Here, the providers differentiates depends on how to manage controlplanes:<br> — <strong>Self-provisioned</strong>: control planes are pods or machines managed by a single Cluster API deployment.<br> —<strong> Pod-based:</strong> control planes are deployed using standard <em>Deployment</em> and <em>StatefulSet</em> objects and the API is exposed using a <em>Service </em>on external hosting cluster.<br> — <strong>External</strong> or <strong>Managed:</strong> control planes are offered and controlled by some system other than Cluster API, such as GKE, AKS, EKS.</li><li><strong>Bootstrap Provider</strong>, is used for generating cluster wide certificates, cloud-init configuration the virtual machines and servers being created. Also handles join of control plane and worker nodes to the cluster. Bootstrap provider achieve this goal by generating ‘BootstrapData’ by mostly contains cloud init configuration. BootstrapData is also an input for infrastructure provider to spin up a Machine into a Node.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDH1iENUgSUR5rO0RcFv4Q.png" /><figcaption>Management &amp; Tenant Clusters with Providers</figcaption></figure><p>You can find all supported providers list <a href="https://cluster-api.sigs.k8s.io/reference/providers">here</a>. Some important providers can be seen in below drawing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m5sFvGNgnvCw0N_W3SDsuQ.png" /><figcaption>Some CAPI Cluster Providers</figcaption></figure><p>Addition to these providers, CAPI needs CRDs to define required inputs in a cluster provisioning and management overall. For this purpose, below CRDs are defines and uses by the providers accordingly:</p><p><strong>Cluster:</strong> It represents a Kubernetes cluster whose lifecycle is managed by Cluster API, usually also referred to as <strong><em>workload cluster</em></strong>. This object can be used as a single point of control for the entire cluster. Cluster specs like CIDR defines here. Also provider fields like<em> </em>infrastructureRef and controlPlaneRef defines here and those specs are changeable for different cluster platforms.</p><pre>apiVersion: cluster.x-k8s.io/v1beta2<br>kind: Cluster<br>metadata:<br>  name: my-cluster<br>spec:<br>  clusterNetwork:<br>    pods:<br>      cidrBlocks:<br>      - 192.168.0.0/16<br>  infrastructureRef:<br>    apiGroup: infrastructure.cluster.x-k8s.io<br>    kind: VSphereCluster<br>    name: my-cluster-infrastructure<br>  controlPlaneRef:<br>    apiGroup: controlplane.cluster.x-k8s.io<br>    kind: KubeadmControlPlane<br>    name: my-control-plane</pre><ul><li><strong>Machine: </strong>A CRD that providing the declarative spec for infrastructure hosting a Kubernetes Node (for example, a VM). Any information that is provider-specific is part of the custom resources referenced via infrastructureRef or bootstrap.configRef and is not portable between different providers.</li></ul><pre>apiVersion: cluster.x-k8s.io/v1beta2<br>kind: Machine<br>metadata:<br>  name: my-machine<br>spec:<br>  clusterName: my-cluster<br>  version: v1.35.0<br>  infrastructureRef:<br>    apiGroup: infrastructure.cluster.x-k8s.io<br>    kind: VSphereMachineTemplate<br>    name: my-machine-infrastructure<br>  bootstrap:<br>    configRef:<br>      apiGroup: bootstrap.cluster.x-k8s.io<br>      kind: KubeadmConfigTemplate<br>      name: my-bootstrap-config<br>status:<br>  nodeRef:<br>    name: the-node-running-on-my-machine</pre><p><strong><em>Machines are immutable resources for ClusterAPI:</em></strong> They’re being accepted like once they’re created, they’re never be changed (except, labels etc.). They can only be deleted. Like pods…</p><p>There are other CRDs that specialized to manage such situations well. Like managing pods over Deployments… :</p><ul><li><strong>MachineSet: </strong>A MachineSet’s purpose is to maintain a stable set of Machines running at any given time. A MachineSet works similarly to a core Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/">ReplicaSet</a>. MachineSets are not meant to be used directly, but are the mechanism MachineDeployments use to reconcile desired state.</li><li><strong>MachineDeployment: </strong>A MachineDeployment provides declarative updates for Machines and MachineSets. A MachineDeployment works similarly to a core Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Deployment</a>. A MachineDeployment reconciles changes to a Machine spec by rolling out changes to 2 MachineSets, the old and the newly updated.</li><li><strong>MachinePool:</strong> A MachinePool is a declarative spec for a group of Machines. It is similar to a MachineDeployment, but is specific to a particular Infrastructure Provider. It enables to use primitives/additional features of the Infrastructure Provider like AWS, GCP, Azure. For more information, please check out <a href="https://cluster-api.sigs.k8s.io/tasks/experimental-features/machine-pools">MachinePool</a>.</li><li><strong>MachineHealthChecks: </strong>A MachineHealthCheck defines the conditions when a Node should be considered missing or unhealthy. If the Node matches these unhealthy conditions for a given user-configured time, the MachineHealthCheck initiates remediation of the Node. Remediation of Nodes is performed by replacing the corresponding Machine. <br><strong><em>Note: </em></strong>MachineHealthChecks will only remediate Nodes if they are owned by a MachineSet. This ensures that the Kubernetes cluster does not lose capacity, since the MachineSet will create a new Machine to replace the failed Machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*FhUmHQR2dHq9FRMbnTGNNw.png" /><figcaption>Some Cluster API CRDs</figcaption></figure><p><strong><em>Quick start notes and other links: </em></strong>Cluster API can be installed as binary(clusterctl) or Cluster API operator. You can check out below links to try it right away. Also, I’ve added an use case that 100s Azure AKS clusters managed via Cluster API.</p><ul><li><a href="https://cluster-api.sigs.k8s.io/user/quick-start.html">https://cluster-api.sigs.k8s.io/user/quick-start.html</a></li><li><a href="https://cluster-api-operator.sigs.k8s.io/user/quick-start">https://cluster-api-operator.sigs.k8s.io/user/quick-start</a></li><li><a href="https://techblog.cloudkitchens.com/p/managing-100s-of-kubernetes-clusters">https://techblog.cloudkitchens.com/p/managing-100s-of-kubernetes-clusters</a></li></ul><h3>🕷️ Simplify Control Plane Management: Kamaji</h3><p><a href="https://kamaji.clastix.io/">Kamaji</a> is a control plane provider that basically runs each tenant cluster control plane members as pods within the Management Cluster, rather than running them on dedicated machines/inside the tenant cluster itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HtdKT35Q9TQBwaJFnYxYeA.png" /></figure><p>The architecture can bee seen above brings advantages for multi-cluster management in an environment:</p><ul><li><strong>Isolation: </strong>Since each tenant control plane members run as separated pods in the management cluster, an isolated environment is established. Additionally, connection between the management cluster and tenant clusters are unidirectional. Tenant clusters are not aware about management cluster existence or able to reach it.</li><li><strong>Declarative Management:</strong> Kamaji leverages Kubernetes Custom Resource Definitions (CRDs) to provide a fully declarative approach to managing control planes, datastores, and other resources. This enables us to leverage advantages of tools like Terraform, Ansible, ArgoCD/FluxCD(GitOps).</li><li><strong>Datastore Diversity:</strong> In addition to <a href="https://github.com/clastix/kamaji-etcd">kamaji-etcd</a> default datastore scenario, Kamaji offers support for other storage systems, as PostgreSQL, MySQL or NATS, thanks to the native <a href="https://github.com/k3s-io/kine">kine</a> integration.</li><li><strong>Infrastructure Agnostic: </strong>With Kamaji, you can connect worker nodes from any infrastructure provider. Supports bare metal, virtual machines, and cloud instances, allowing hybrid and multi-cloud deployments.</li><li><strong>Cluster API Integration:</strong> As introduced in this story, Kamaji can be used as <a href="https://github.com/clastix/cluster-api-control-plane-provider-kamaji">“Control plane provider”</a>. It’s enabling automated, declarative lifecycle management of clusters and worker nodes across any infrastructure.</li></ul><p><strong><em>At this point, I’d like emphasized difference between purpose of using Kamaji and ClusterAPI: </em></strong>ClusterAPI handles worker nodes lifecycle management &amp; infrastructure abstraction for multiple clusters. On the other hand, Kamaji simplifies &amp; isolates control plane management for multiple clusters.</p><p>Let’s check howTenantControlPlane CRD looks like:</p><pre>cat &gt; ${TENANT_NAMESPACE}-${TENANT_NAME}-tcp.yaml &lt;&lt;EOF<br>apiVersion: kamaji.clastix.io/v1alpha1<br>kind: TenantControlPlane<br>metadata:<br>  name: ${TENANT_NAME}<br>  namespace: ${TENANT_NAMESPACE}<br>  labels:<br>    tenant.clastix.io: ${TENANT_NAME}<br>spec:<br>  dataStore: default<br>  controlPlane:<br>    deployment:<br>      replicas: 3<br>      additionalMetadata:<br>        labels:<br>          tenant.clastix.io: ${TENANT_NAME}<br>      extraArgs:<br>        apiServer: []<br>        controllerManager: []<br>        scheduler: []<br>      resources: {}<br>    service:<br>      additionalMetadata:<br>        labels:<br>          tenant.clastix.io: ${TENANT_NAME}<br>      serviceType: LoadBalancer<br>  kubernetes:<br>    version: ${TENANT_VERSION}<br>    kubelet:<br>      cgroupfs: systemd<br>    admissionControllers:<br>      - ResourceQuota<br>      - LimitRanger<br>  networkProfile:<br>    port: ${TENANT_PORT}<br>    certSANs:<br>    - ${TENANT_NAME}.${TENANT_DOMAIN}<br>    serviceCidr: ${TENANT_SVC_CIDR}<br>    podCidr: ${TENANT_POD_CIDR}<br>    dnsServiceIPs:<br>    - ${TENANT_DNS_SERVICE}<br>  addons:<br>    coreDNS: {}<br>    kubeProxy: {}<br>    konnectivity:<br>      server:<br>        port: ${TENANT_PROXY_PORT}<br>EOF<br><br>kubectl -n ${TENANT_NAMESPACE} apply -f ${TENANT_NAMESPACE}-${TENANT_NAME}-tcp.yaml</pre><p><strong><em>Quick start notes and other links:</em></strong> Kamaji can be installed on a generic infrastructure or as supported kind, AWS or Azure based clusters. Here are some links to getting started with it:</p><ul><li><a href="https://kamaji.clastix.io/getting-started/">https://kamaji.clastix.io/getting-started/</a></li><li><a href="https://www.youtube.com/watch?v=nSGo_72LnmY&amp;t=158s">https://www.youtube.com/watch?v=nSGo_72LnmY&amp;t=158s</a> <em>(TalosOS + Kamaji Demo)</em></li></ul><h3>🎬<strong>Use Case-1: ClusterAPI on Openstack Magnum</strong></h3><p>Magnum is just another service that provision &amp; manage multiple Kubernetes clusters on Openstack platform. Thanks to Cluster API, provision clusters by using computes and other resources becomes possible.</p><p>Openstack Magnum service uses <a href="https://github.com/vexxhost/magnum-cluster-api"><strong>vexxhost Magnum Cluster API driver</strong></a> which we earlier defined it as <a href="https://cluster-api-openstack.sigs.k8s.io/getting-started">CAPO</a>. In this use case, you can provision your clusters by using one the below methods however at the end, it means using Magnum API and Cluster API backends:</p><ul><li>Openstack CLI <em>(openstack coe)</em></li><li>Openstack Horizon Dashboard</li><li>Ansible/Terraform tools</li><li>Magnum API direct interaction</li></ul><p>If we’d like to summarize how Openstack Magnum provision Kubernetes clusters and manage them individually:</p><ul><li>First, we need to create our “ClusterTemplate” which defines cluster specifications like kubernetes version, master/worker node numbers, resources etc.</li><li>Then, you need to create a cluster from that template to provision your cluster. While creating it, we define some autoscaling settings like min/max worker nodes to scale workloads according to time-based load. Additionally, we pick our private/public network so that our nodes can joined and get IP addresses from those networks.</li></ul><p>At below link, you can find step-by-step instructions to use it.</p><p><a href="https://vexxhost.github.io/magnum-cluster-api/user/getting-started/#creating">Getting Started</a></p><h3>🎬<strong>Use Case-2: ClusterAPI with Kubevirt and Kamaji</strong></h3><p>Below YouTube video is explaining how to use ClusterAPI and Kamaji very well to manage your own private cloud product. It’s simply explained the underlying technologies in the video and other blog link is actually gives a lot details about same use case.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7m1NOp2sUXQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7m1NOp2sUXQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7m1NOp2sUXQ%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd3ec4c4a70d46847f9582eb19a59973/href">https://medium.com/media/dd3ec4c4a70d46847f9582eb19a59973/href</a></iframe><p><a href="https://kubernetes.io/blog/2024/04/05/diy-create-your-own-cloud-with-kubernetes-part-3/">DIY: Create Your Own Cloud with Kubernetes (Part 3)</a></p><p>Last but least… It’s not always good idea to use those tools blindly since the complexity will be your enemy while you’re trying to minimize multiple clusters management problem. After knowing the idea behind those tools and use cases, you carefully design your own environment. That’s the maturity of Kubernetes management.</p><p>Cheers…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=667852bd52a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/kubernetes-clusters-management-maturity-cluster-api-kamaji-and-more-667852bd52a4">Kubernetes Clusters Management Maturity: Cluster API, Kamaji and More</a> was originally published in <a href="https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri">Turk Telekom Bulut Teknolojileri</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing your Kubernetes Cluster: Network Policies]]></title>
            <link>https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/securing-your-kubernetes-cluster-network-policies-e890804c4613?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e890804c4613</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Mon, 02 Jun 2025 08:24:15 GMT</pubDate>
            <atom:updated>2025-06-02T08:24:15.302Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H8J-169lKknTi_jG" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=medium&amp;utm_medium=referral">Alina Grubnyak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Kubernetes network policies are crucial and one of the essential resource kind that to manages communication between different internal/external endpoints securely in a cluster. In this post, we will understand network policies, examine some hands-on examples, validating steps and try to make them easy to understand.</p><h4>Understanding Network Policy</h4><p>In Kubernetes, as default, all pods can communicate with each other without requiring any additional configuration etc. Network policies enables you to define rules that control incoming and outgoing traffic to and from pods. We may say whitelisting and firewall rules in Kubernetes. In OSI networking model, it represents Layer3/4. Through the selectors like pod and namespace, you define the communication flow(allowing/denying) between different pods and namespaces.</p><p>Some terms related Network Policy in Kubernetes:</p><ul><li><strong>Policy Types:</strong> Can be either ingress, egress, or both.</li><li><strong>Pod Selector:</strong> Selects the group of pods to which the policy applies.</li><li><strong>Namespace Selector:</strong> Selects the namespace that policy applies.</li><li><strong>Ingress Policies</strong>: Control incoming traffic to pods.</li><li><strong>Egress Policies</strong>: Control outgoing traffic from pods.</li></ul><p>Nonetheless, Network Policies aren’t a fully complete solution as they provide <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/#what-you-can-t-do-with-network-policies-at-least-not-yet"><strong>limited functionality</strong></a> and you need to fulfill the prerequisites. If we’d mention such limited functionality, network policies has inability to log events when a connection block occurs. Also, they lack of support for explicit deny policies, stopping loopback or incoming host traffic. If you need these features, then you should consider <a href="https://spacelift.io/blog/what-is-a-service-mesh"><strong>using a separate service mesh</strong></a> (Istio etc.) in addition to your network policies or other CNIs like Cillium. (we’ll not examine deep dive CNIs at this story but very brief explanation about <a href="https://isovalent.com/blog/post/intro-to-cilium-network-policies/"><strong>Cillum</strong></a>: It’s just another CNI option that provides L3/L4/L7 level network policy which means having more flexibility at this area.)</p><p>Let’s see how a network policy looks like and explained it step by step over an example…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEXADFZXO3jl5WVqX_3M7g.png" /><figcaption>Egress Network Policy Example</figcaption></figure><ul><li>First, we can see that the network policy applies on the <strong>“namespace:default”</strong>. So, we’re targeting applying our rules on this namespace.</li><li>With <strong>“podSelector”, </strong>we choose to apply this rule to not all pods in the namespace but to specific pods that has label <strong>“id:frontend”.</strong></li><li>We’ve policy type which could be <strong>“Egress” </strong>or <strong>“Ingress”. </strong>This example is for egress traffic. Means that, it’s for outgoing traffic. However, ingress and egress can be existed together in a network policy rule.</li><li>Next, we’re defining our rules for the traffic. Here, <strong>the important point</strong> <strong>is</strong> if the rules are defining as array members or as map. As explained in image, “-” defines that a array member and for a traffic if there are multiple array members are exist, then “<strong>OR”</strong> operator works between these rules.</li><li>In a traffic rule, it could be more than one definition. In that case, for the definitions (namepaceSelector, podSelector, port etc.) <strong>“AND”</strong> operator works.</li></ul><p>Sometimes it could be hard to visualize &amp; understand the policy rule outcomes in our minds. Especially, for complicated rules… In such cases, we can use an editor. <strong><em>Cillium Network Policy Editor </em></strong>is a great tool for such purpose. You can import your rules definitions as YML or JSON for both default Network Policies or Cillium Network Policies.</p><p>Here is the link:</p><p><a href="https://editor.networkpolicy.io/">Network Policy Editor for Kubernetes</a></p><h4>Fundamental Use Cases</h4><p>There are some fundamental use cases that we commonly use to isolate traffic between pods, services and namespaces. I will try to explain each case shortly and visualize them via Network Policy Editor.</p><ul><li><strong><em>Default Deny All Ingress Traffic:</em></strong></li></ul><p>This policy deny all ingress traffic from other sources in a namespace. The distinguishing point is that there is no <strong>“ingress:”</strong> part in the rule so the traffic is denying because there is no rule. “<strong>podSelector: {}”</strong> defines selecting all pods in the namespace. This way, you can clearly identify which components have dependency on which components and deploy Network policies which may requires for other components traffic.</p><p>Egress traffic is allowed as default.</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: default-deny-ingress<br>spec:<br>  podSelector: {}<br>  policyTypes:<br>  - Ingress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*Du_t1VmgJkptdRTOEiXQRg.png" /></figure><ul><li><strong><em>Allow All Ingress Traffic:</em></strong></li></ul><p>This policy is allowing ingress traffic from all sources. As you can see <strong>“ingress:”</strong> part exist however there is no rule. Means that the traffic will be allowed from all other sources.</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: allow-all-ingress<br>spec:<br>  podSelector: {}<br>  ingress:<br>  - {}<br>  policyTypes:<br>  - Ingress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*SiVCTd9kN1x_Cqb6DW2xWw.png" /></figure><p>One of the use case could be, after applying deny all policy which blocks all traffic to an application, you may need to allow access to an application from all pods in the current namespace. In this case you can specify the application pod with <strong>“podSelector”</strong>.</p><pre>kind: NetworkPolicy<br>apiVersion: networking.k8s.io/v1<br>metadata:<br>  name: web-allow-all<br>  namespace: default<br>spec:<br>  podSelector:<br>    matchLabels:<br>      app: web<br>  ingress:<br>  - {}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*jDLFL-riIWOTsZ-Mr8bnrQ.png" /></figure><ul><li><strong><em>Default Deny All Egress Traffic</em></strong></li></ul><p>This policy creating an egress traffic rule that blocks all outgoing traffic from the namespace. Since there is no <strong>“egress:” </strong>part in the YML(empty array), all traffic will be dropped for egress traffic. After deploying such policy, you can deploy Network Policies that allow the specific outgoing traffic so you may have an isolated environment for an egress traffic.</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: default-deny-egress<br>spec:<br>  podSelector: {}<br>  policyTypes:<br>  - Egress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*AycDN3QVykg9zq7H2edYpA.png" /></figure><ul><li><strong><em>Allow All Egress Traffic</em></strong></li></ul><p>This policy allows all connections from all pods in a namespace. You can create a policy that explicitly allows all outgoing connections from pods in that namespace. Ingress traffic is allowed as default. As result, as long as this policy is in place, no additional policy or policies can cause any outgoing connection from those pods to be denied. This policy has no effect on isolation for ingress to any pod.</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: allow-all-egress<br>spec:<br>  podSelector: {}<br>  egress:<br>  - {}<br>  policyTypes:<br>  - Egress</pre><ul><li><strong><em>Default Deny All Ingress &amp; Egress Traffic</em></strong></li></ul><p>You can create a “default” policy for a namespace which prevents all ingress <strong>AND </strong>egress traffic by creating the following Network policy in that namespace. This ensures that even pods that aren’t selected by any other Network policy will not be allowed ingress or egress traffic.</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: default-deny-all<br>spec:<br>  podSelector: {}<br>  policyTypes:<br>  - Ingress<br>  - Egress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*kGNmtdSgihue-Xmz-Oqllg.png" /></figure><h4>Complex Network Policy Rule Example</h4><p>It’s time to examine a bit complex one… Let’s imagine that we’ve an web application that has both frontend and backend ports. Also, clients are reaching to this application outside of the cluster.</p><p>Let’s start with frontend side:</p><pre># Frontend Pods Network Policy Rules<br>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: frontend-policy<br>  namespace: webapp-namespace<br>spec:<br>  podSelector:<br>    matchLabels:<br>      app: webapp<br>      tier: frontend<br>  policyTypes:<br>    - Ingress<br>  ingress:<br>    - from:<br>        - ipBlock:<br>            cidr: 0.0.0.0/0<br>            except:<br>              - 192.168.0.0/16<br>      ports:<br>        - port: 80<br>          protocol: TCP<br>  egress:<br>    - to:<br>        - podSelector:<br>            matchLabels:<br>              app: webapp<br>              tier: backend<br>    - to:<br>        - namespaceSelector:<br>            matchLabels:<br>              kubernetes.io/metadata.name: kube-system<br>      ports:<br>        - port: 53<br>          protocol: UDP</pre><ul><li>In namespace <strong>“webapp-namespace”, </strong>we select the pods which have specific labels — <strong>“app: webapp”</strong> , <strong>“tier: frontend”.</strong></li><li>This policy handles <strong>“Ingress” and “Egress” traffics</strong> as specified in <strong>“policyTypes”</strong> section.</li><li>In the <strong>“Ingress” part</strong>, we’re defining to allow all traffic from all IP block on the <strong>internet(0.0.0.0/0) except local IP addresses (192.168.0.0/16)</strong>. <strong><em>AND</em></strong> through port 80.</li><li>This <strong>“except”</strong> part can be extended according to needs.</li><li>In the <strong>“Egress” </strong>part, we’re defining to reach only the backend pods that have <strong>“app: webapp”</strong> and <strong>“tier: backend” </strong>labels. Any other pods, in/out cluster traffic will be denied thanks to this rule.</li><li><strong>“Egress”</strong> part here is allowing traffic to internal Kubernetes DNS in <strong>“kube-system”</strong> namespace. Why this rule is needed? Because once an egress rule is defined under the <strong>“policyTypes”</strong>, Kubernetes enforces a <strong>“default deny egress”</strong> for any pod matched by the policy so you cannot forward any traffic(unless you explicitly allow). Most likely, your pods may require to handle DNS resolution. In that case you need to add the DNS rule under your egress policy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*EIbx4GxWdb-XZmFVngFZig.png" /><figcaption>Frontend Pods Network Policy</figcaption></figure><p>On the other hand, we’ve backend side:</p><pre># Backend Pods Network Policy Rules<br>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: backend-policy<br>  namespace: webapp-namespace<br>spec:<br>  podSelector:<br>    matchLabels:<br>      app: webapp<br>      tier: backend<br>  policyTypes:<br>    - Ingress<br>    - Egress<br>  ingress:<br>    - from:<br>        - podSelector:<br>            matchLabels:<br>              app: webapp<br>              tier: frontend<br>      ports:<br>        - protocol: TCP<br>          port: 8080<br>  egress:<br>    - to:<br>        - namespaceSelector:<br>            matchLabels:<br>              kubernetes.io/metadata.name: kube-system<br>      ports:<br>        - protocol: UDP<br>          port: 53</pre><ul><li>Here, we define both <strong>“Ingress”</strong> and <strong>“Egress”</strong> traffic rules.</li><li>We select the pods that has <strong>“app: webapp”</strong> and <strong>“tier: backend” </strong>labels<strong> </strong>in the specified namespace <strong>“webapp-namespace”</strong>.</li><li><strong>“Ingress” </strong>part define that we’re allowing traffic from the pods that have <strong>“app: webapp”</strong> , <strong>“tier: frontend”</strong> labels <strong>AND</strong> reaching to the port 8080.</li><li>Like in frontend pods, we’re allowing internal DNS here as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*jpLjEtvQ8m8mb45wP96BnA.png" /><figcaption>Backend Pods Network Policy</figcaption></figure><h4><strong>More Example &amp; Details?</strong></h4><p>If you wanna see more example &amp; details, I can highly recommend below GitHub repository:</p><p><a href="https://github.com/ahmetb/kubernetes-network-policy-recipes/tree/master">GitHub - ahmetb/kubernetes-network-policy-recipes: Example recipes for Kubernetes Network Policies that you can just copy paste</a></p><h4>Best Practices</h4><p>We’ve seen how to use network policies. It’s also important to use them by taking care of some key points so you will not comprimise security and reliability in your cluster.</p><ul><li><strong>Ensure all Pods are covered by a Network Policy</strong></li></ul><p>In a Kubernetes cluster, all pods should be covered by network policies so that traffic through these pods limit with the minimal set of Ingress/Egress rules. Otherwise, allowing all pods reachability may cause potential security breaches.</p><ul><li><strong>Use precise Ingress/Egress target selectors</strong></li></ul><p>Keep your Pod selectors, namespace selectors, and ipBlock ranges as precise as possible to prevent them from accidentally selecting new Pods in the future. For example, if a namespace selector is inappropriate and you’re likely to deploy additional Pods to the namespace, those Pods shouldn’t automatically communicate with your Network Policy’s target as expected.</p><ul><li><strong>Set a default deny policy, then add your allow policies</strong></li></ul><p>You can ensure your cluster has complete Network Policy coverage by creating a <strong>default “deny all” policy </strong>(as shown in the fundamental use cases above), then adding <strong>specific “allow” policies</strong> that authorize required traffic flows. This method means new Pods are protected from accidental network exposure, even if you forget to create a specific Network Policy for them.</p><ul><li><strong>Test your policies to check they’re working as intended</strong></li></ul><p>One of the difficulties of Network Policies is the lack of clear visibility into whether they’re working. The editor site that I mentioned in this story might little bit help at this point. However, it’s worthwhile to test new policies to be sure they’re configured correctly. To do that, you can create a new pod with labels that match your Network Policy’s selectors, then use commands like curl/wget and ping to test the connectivity available through target pods.</p><p>For example, for above complex network policy, you can check whether frontend pods can reach to the backends pods and vice versa by using below commands:</p><pre>#Create example frontend pod named &quot;test-frontend&quot;<br>kubectl run test-frontend \<br>  -n webapp-namespace \<br>  --image=busybox \<br>  --labels=&quot;app=webapp,tier=frontend&quot; \<br>  --restart=Never -it -- sh<br><br>#Create example frontend pod named &quot;test-backend&quot;<br>kubectl run test-backend \<br>  -n webapp-namespace \<br>  --image=busybox \<br>  --labels=&quot;app=webapp,tier=backend&quot; \<br>  --restart=Never -it -- sh<br><br>#Create a untrusted pod named &quot;test-untrusted&quot;<br>kubectl run test-untrusted \<br>  -n webapp-namespace \<br>  --image=busybox \<br>  --restart=Never -it -- sh<br><br>#Create a pod in another namespace named &quot;test-external&quot; to simulate &quot;external&quot; traffic<br>kubectl create ns external-test<br>kubectl run test-external \<br>  -n external-test \<br>  --image=busybox \<br>  --restart=Never -it -- sh<br><br><br><br>#Inside &quot;test-external&quot; pod:<br>wget -qO- http://&lt;frontend-pod-ip&gt;:80<br><br># Should work if coming from public IP<br># Should fail if source IP is in 192.168.0.0/16<br><br><br>#Inside &quot;test-frontend&quot; pod:<br>wget -qO- http://&lt;backend-pod-ip&gt;:8080<br><br>#Should succeed because allowed in backend ingress<br><br><br>#Inside &quot;test-untrusted&quot; pod:<br>wget -qO- http://&lt;backend-pod-ip&gt;:8080<br><br>#Should fail because the pod has not appropriate labels<br><br><br>#Inside &quot;test-frontend&quot; and &quot;test-backend&quot; pod:<br>nslookup google.com  # or internal cluster DNS address<br><br>#Should succeed because UDP port 53 to kube-system is allowed</pre><ul><li><strong>Regularly review your policies and keep them updated</strong></li></ul><p>Your Network Policy requirements are likely to change as your cluster evolves with new Pods and namespaces. You should regularly review your policies and make any alterations required so they remain appropriate for your environment.</p><p>That’s all for now…</p><p>Hope to share more advices to keep secure your Kubernetes clusters, soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e890804c4613" width="1" height="1" alt=""><hr><p><a href="https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/securing-your-kubernetes-cluster-network-policies-e890804c4613">Securing your Kubernetes Cluster: Network Policies</a> was originally published in <a href="https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri">Turk Telekom Bulut Teknolojileri</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IaC World-3: GitOps on Openstack- Provisioning Automation with Terraform and GitLab CI/CD]]></title>
            <link>https://oziie.medium.com/iac-world-3-gitops-on-openstack-provisioning-automation-with-terraform-and-gitlab-ci-cd-bdcf7d543582?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdcf7d543582</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[openstack]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 19:16:40 GMT</pubDate>
            <atom:updated>2024-03-12T20:20:59.383Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vkP5D85Bawj3F_wH" /><figcaption>Photo by <a href="https://unsplash.com/@vapricot?utm_source=medium&amp;utm_medium=referral">Dmitriy Frantsev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Greetings…</blockquote><p>You might seen the title as cocktail of techs and concepts. This cocktail may give you full of enjoy and some peace while managing platforms, deploying software, operate your business on them. Of course, on condition that, you mix the cocktail well.</p><p>In this story, we will examine what is GitOps and demonstration a part of it on Openstack by using Terraform as IaC tool and Gitlab as truth source VCS.</p><p>Before start… If you want to see other stories of the series, you’re welcome:</p><ul><li><a href="https://oziie.medium.com/iac-world-terraform-101-985e5ff6852">IaC World: Terraform 101</a></li><li><a href="https://oziie.medium.com/iac-world-2-some-key-questions-b3d8ea453206">IaC World-2: Some Key Questions</a></li></ul><h3><strong>What is GitOps and it’s part “provisioning automation”? </strong>📕</h3><p>Let’s start with <strong>“provisioning”</strong> first… Provisioning means that creation of infrastructure resources on a whatever target platform and put them into use for your compute required processes like software deployment, business operations etc. If you automate this task… Here comes… “Provisioning automation”.</p><p>But why do we need automation of it? As millions of other things in universe, there are causes of effects so we have it. These causes also outcomes of IaC principles that we follow as a truthful concept:</p><ul><li><strong>Reliability</strong> (your resources should be reliable, created as you wish so business can be alive)</li><li><strong>Reusability</strong> (code once, use repeatedly to create a new or change)</li><li><strong>Effectiveness</strong> (whenever you want, you should able to do it)</li></ul><blockquote><strong>As for GitOps, this is not just about “provisioning automation”.</strong></blockquote><p>In addition to that, based on DevOps processes like important parts CI/CD and version control, <strong>it also automates “software deployment” and “configuration management”</strong> in a software architecture. It uses Git at the core and every development or change stores in Git repository. Therefore operations are traceable and reliable from the beginning of the workflow, up to the end. This operation model is mostly using by software developers and platform engineers that working on cloud environments effectively. My personal opinion is, according to your needs, you can use GitOps concept anywhere anyplace that you can build these tools and leverage the use of target platform APIs. Thanks to tools like Terraform, it keeps your state infrastructure and application state in remote states like Terraform Cloud, GitLab or storage services like AWS S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bu5TH3Cmp2LSlcWNhSEPnQ.png" /><figcaption>GitOps Workflow</figcaption></figure><h3><strong>Demo Use Case — Provisioning Automation </strong>🕹️</h3><p>In this story, my purpose is to show you <strong>“Provisioning Automation”</strong> as part of GitOps concept.</p><p>Our target platform is Openstack. We see how to manage Openstack resources and how to configure few things on them through GitLab CI/CD pipelines. In high level, our project will be sit on this kind of architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKuXeMnLGtiHL8LGKT4_SQ.png" /><figcaption>High Level Architecture</figcaption></figure><p>If we’d like to see what’s going on and understand better, which stages &amp; tasks are created in CI/CD pipeline, how those are related, we can take reference “Low Level Workflow”. <em>(it may not align some practices in workflow drawing but hope that it’s comprehensible </em>🙃<em>)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGSaP9pC2lhJmZ2srdtTOA.png" /><figcaption>Low Level Workflow</figcaption></figure><p>I admit that in practice, coding these may not be really easy as defining concepts. Let’s cut the chase and see how we do “in practice”…</p><h3><strong>Step-1: Create Openstack project &amp; get your authentication details </strong>🛫</h3><p>First things first, we need to have a project to work on it so create a project in Openstack. As we use API at every stage &amp; between tools, we need project authentication details. To get API authentication parameters from Openstack, download <strong>openrc.sh</strong> file (in bash file format, project API auth parameters) and <strong>clouds.yaml</strong>(in yaml format, project API auth parameters).</p><p>You will realize in further steps that we take reference bash parameter names since mentioned in Terraform provider docs accordingly. It also makes clear the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tS4PtWiAs8ZWgEEoWt9mQ.png" /><figcaption>Openstack API Access</figcaption></figure><p>We also need to define an “application credential” to have authorization on our project. As shown below, create an application credential to use later in pipeline. Your credential has at least member and heat_stack_owner roles. Make sure that you saved your secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frcIID2VnAb8q2Er8m1p9g.png" /><figcaption>Openstack Application Credential</figcaption></figure><h3>Step-2: GitLab Repository Initialization 🧱</h3><p>In this project, we use GitLab as VCS and CI/CD pipeline solution so we need to create our repository in GitLab and additionally CI/CD pipeline so that we can push all files that contains necessary codes and execute task through the pipeline.</p><p>You can create your repository through GitLab UI and clone it to your local. We will get CI/CD details in further steps.</p><blockquote><strong>In this blog, I prefer to keep source codes and CI/CD definition in Github publicly, however, you will see some details at images in GitLab form.</strong></blockquote><p>If you’d like to see repository of this project, check the link below:</p><p><a href="https://github.com/oziie/gitops-on-openstack">GitHub - oziie/gitops-on-openstack: Created with purpose of apply GitOps practices on Openstack platform with help of IaC tool Terraform and CI/CD solution GitLab</a></p><p>In addition to Openstack API authentication and application authorization details, we also need to create a secret in GitLab repository to be used in later steps. This secret allows us to reach our repository via Gitlab API and enables CI/CD execution. To make it complete, you need to go <strong>“Settings — Access Tokens”.</strong> Create your access token with api, read_api, read_repository, write_repository rights and save it securely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ju1IVsHkxWheFoJrxDs1ZQ.png" /><figcaption>GitLab Access Token Creation</figcaption></figure><h3>Step-3: Code the Infrastructure Resources with Terraform 👨🏻‍💻</h3><p>Feeling like it’s time to back to analogy :) This is the step where we’re starting to write cocktail recipe. How much you put from which drinks, other such methods :)</p><p>In this story, our purpose will be creation of a VM. We’ll also attach a volume to this VM and execute a startup script via Terraform basically. The script that mounts a path on a new created physical disk.</p><p>Let me briefly explain, how we code our infrastructure…</p><h4><strong># main.tf</strong></h4><p>Here, we are defining “ci_cd_test_vm” resource object from “openstack_compute_instance_v2” resource type by declaring related object values. Values are referencing from <strong>variables.tf</strong> file and it overrides in CI/CD pipeline definition. We will mention this in later steps about how we do.</p><p>Other than Openstack instance resource, I’d like to talk about “vm” resource object that create from <strong>“terraform_data” </strong>. Why we do it? <a href="https://developer.hashicorp.com/terraform/language/resources/provisioners/null_resource"><strong>“terraform_data”</strong></a><strong> </strong>which formerly known as <strong>“null_resource” and </strong><a href="https://medium.com/@thiagoalves/a-reason-to-stop-using-the-terraform-null-resource-51180b2339"><strong>deprecated</strong></a> is using for two scenarios.</p><ul><li><em>It allows arbitrary values to be stored . Afterward these values can be used to implement lifecycle triggers of other resources</em></li><li><em>It trigger provisioners when there isn’t a more appropriate managed resource available. (which is our case)</em></li></ul><p>For more details please check <a href="https://developer.hashicorp.com/terraform/language/resources/terraform-data"><strong>this </strong></a>and <a href="https://devdosvid.blog/2023/04/16/hello-terraform-data-goodbye-null-resource/"><strong>this</strong></a>.</p><p>Even it does not create a real resource in our architecture, we use it to run <strong>remote-exec </strong>commands in correct sequence. Because, our operations that we define in the bash script <strong>config-vm.bash</strong> requires new volume attached &amp; path mounted first on the Openstack instance. Otherwise, terraform apply will fail at remote-exec part. With “remote-exec” command, we first create a folder /tmp/conf_vm/bash_scripts/ then we put all scripts which locates./conf_vm/bash_scripts to the /tmp/conf_vm/bash_scripts/ folder on instance.</p><p>At last step, with provided connection details, our script executes on the instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2b4f859111c3346b90af454f9e9ac06/href">https://medium.com/media/f2b4f859111c3346b90af454f9e9ac06/href</a></iframe><p>Our basic mount bash script is like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/843677748ad05c2c5a33114e384165bc/href">https://medium.com/media/843677748ad05c2c5a33114e384165bc/href</a></iframe><h4># variables.tf</h4><p>We define all required variables here to use in resource creation process. However, later in CI/CD definition file gitlab-ci.yml, we override these values by using terraform.tfvars file which its content defining through the CI/CD task and values come from CI/CD variables that defined in GitLab.</p><p>Variable names referrencing from O<a href="https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs">penstack provider docs</a> in Terraform knowledge base. It also corresponds Openstack env. variable names.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac95b7d198793066870511059468b941/href">https://medium.com/media/ac95b7d198793066870511059468b941/href</a></iframe><h4># volumes.tf</h4><p>We create basically Openstack block storage volume and then attach into created instance. As distinguisher, instance_id is taken.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a246d435075c2183e1419bb8b4a7798/href">https://medium.com/media/5a246d435075c2183e1419bb8b4a7798/href</a></iframe><h4># provider.tf</h4><p>In this file we define Terraform Openstack provider and authentication details to connect Openstack API. These details can be found in <strong>openrc.sh </strong>that we download at the beginning in this story.</p><p>backend “http” {} requires for <strong>GitLab managed Terraform state configuration</strong> as mentioned <a href="https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html"><strong>here</strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9648137d052cc6ab8f58b1ce88fb9138/href">https://medium.com/media/9648137d052cc6ab8f58b1ce88fb9138/href</a></iframe><h4># outputs.tf</h4><p>To have some useful details about created resources once apply process is finished, we’re defining in this file. Basically, vm_ip, vm_name, vm_image_name and vm_flavor_name outputs are sufficient for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46c5027aa757c8d2977fc65d822010b8/href">https://medium.com/media/46c5027aa757c8d2977fc65d822010b8/href</a></iframe><h3>Step-4: Code GitLab CI/CD Pipeline &amp; Define Variables ✍🏻</h3><p>We’re so close complete our recipe, but not yet… :)<br>In this step, we define our CI/CD pipeline that execute the tasks automatically on target platform and give desired infrastructure resources in a state.</p><p>To define tasks, first, we need to define <strong>“stages”. </strong>We have 5 different stages: <strong>tests</strong>, <strong>validate</strong>, <strong>plan</strong>, <strong>apply</strong>, <strong>destroy </strong>and each one of them has 1 task currently. Additionally, we have <strong>default before_script/after_script </strong>section which some operations defining here and making executable for all task at their beginning. As you can see in HLA/LLW images at the beginning of the story, each task runs in a container that provides by <a href="https://docs.gitlab.com/runner/"><strong>GitLab Runner</strong></a> component.</p><p>Let’s take a look at those…</p><h4># default</h4><p><strong>terraform init </strong>command is essential<strong> </strong>at every stage that we work with Terraform. It’s because each time we have unique container and providers, modules must be initialized by Terraform. Otherwise, we cannot track state between different stages/tasks and can’t create correctly our resources. That’s why, we use the command with some flags here. It enables us to initialize our working repository as backend structure.</p><p>In addition to this, we have to use same variables in every stage/task and Terraform variables.tf file must be overwritten by <strong>terraform.tfvars</strong> file which creates with the help of defined CI/CD variables.</p><p>For example, default <strong>OS_VOLUME_SIZE=1</strong> in variables.tf file. We take a CI/CD variables from GitLab which named <strong>OPENSTACK_VOLUME_SIZE</strong> and it’s value is <strong>300. </strong>Eventually, <strong>OS_VOLUME_SIZE </strong>will be overwritten and it’ll be used with its new value — 300- in Terraform operations.</p><h4># tests</h4><p>Basically, this stage includes some tests steps. test_openstack_auth is a task that we check the API authentication on Openstack. It basically checks if the Openstack project exists via Openstack CLI but more test can be added here as well. Task runs automatically in the pipeline.</p><p>As you can see in the task, we override before_script since we don’t need to initialize Terraform for the task.</p><h4># validate</h4><p>This stage validates Terraform code &amp; configuration parameters within <strong>terraform_validate</strong> task. <strong>“terraform validate” </strong>command runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state. It does not need to reach state or backend online and it’s safe it run automatically so that’s why we define this task to run automatically in the pipeline. It depends on success of test_openstack_auth.</p><h4># plan</h4><p><strong>terraform_plan </strong>task is creating a Terraform plan that plan &amp; explains which resources will be created. Ideally, it validates lastly terraform.tfvars file before create the plan.</p><p>In next step, below command creates the plan by using respective terraform.tfvars file. $INFRA_CREATION_PLAN_NAME value comes from pipeline defined variable.</p><p><strong>terraform plan -out $INFRA_CREATION_PLAN_NAME -var-file terraform.tfvars</strong></p><p>We can also download the plan as artifact from Gitlab CI/CD. The stage depends on terraform_validate task. Since, I’ve planned to have more control, I choose execute the task manually (with one click to trigger). If you’d like you can configure as when: on_success.</p><h4># apply</h4><p>Now, we’re ready to apply &amp; create our resources at this stage. <strong>terraform_apply</strong> task is creating resources by using the plan we create in terraform_plan at the plan stage. It’s again checking terraform.tfvars in the task and runs manually to have more control. It depends on terraform_plan task. Creation of resources may take time depends on target platform response.</p><p>Once resources created, also <strong>Terraform state of the infrastructure will be created in your GitLab.</strong> We will get there and see clearly in the CI/CD execution step.</p><h4># destroy</h4><p>It’s also possible to destroy resources via CI/CD pipeline. <strong>destroy</strong> stage <strong>terraform_destroy</strong> task will destroy resource with manual trigger. As the terraform destroy command runs with <strong>--auto-approve</strong> and <strong>lock=false</strong> flag, we need to be careful what we delete, which state we use as target state in execution. Because deletion command will be auto approved and our state will be unlocked.</p><p>The task also deletes the state where <a href="https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html"><strong>we store in GitLab</strong></a><strong> automatically. </strong><strong>TF_HTTP_PASSWORD </strong>corresponds <strong>GitLab access token</strong> and <strong>TF_HTTP_ADDRESS </strong>creates with multiple pre-defined values:<strong> </strong>$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$TF_STATE_NAME</p><p><strong>curl — header “Private-Token:$TF_HTTP_PASSWORD” — request DELETE “$TF_HTTP_ADDRESS”</strong></p><p>This task has dependency on terraform_apply as expected.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0afdc9fefe41f2152c04eb6d9b4d0534/href">https://medium.com/media/0afdc9fefe41f2152c04eb6d9b4d0534/href</a></iframe><p>In addition to CI/CD pipeline definition, we need set our CI/CD variables in GitLab UI. These values are default values that pipeline uses each time you send commit &amp; trigger pipeline. According to whishes or while working in different branch of repository, you overwrite these values accordingly.</p><p>You can define your key and values as shown below in GitLab UI. Go to <strong>Settings — CI/CD — Variables</strong> and set the variables. Full list are located below. You can also check variables with few details about in <a href="https://github.com/oziie/gitops-on-openstack?tab=readme-ov-file#-cicd-variables">Github repository.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*ifzfJLeWtQfw-zPRBTgKjA.png" /><figcaption>Gitlab CI/CD Variables</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63684c1b6396da403fea07125ea9bc62/href">https://medium.com/media/63684c1b6396da403fea07125ea9bc62/href</a></iframe><h3>Step-5: Trigger &amp; Execute CI/CD Pipeline 🚀</h3><p>So, you have drinks under your hands and you know which drinks will be used how much, by using which mixing method etc. Your recipe is ready. Now it’s time to apply your recipe and mix them to make your delicious cocktail ready!</p><p>There are few ways to trigger CI/CD pipeline.</p><p><strong>First option is commit to repository </strong>as working mentality of CI/CD<strong>.</strong> When you commit to repository, test and validate stages will trigger and execute automatically.<em> (If you revert other stages to run automatically, others will work as well.)</em> Then, you can trigger &amp; execute other stages<em>(plan,apply,destroy)</em> that you run manually. It might be a good idea to keep some stages manual while developing your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1XpSwrlNYkga1WPxbqU5w.png" /><figcaption>Pipeline Example</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k97pPFeCVXY85BTS2AU6LQ.png" /><figcaption>Trigger Job Manually</figcaption></figure><p><strong>Second option, you can run a pipeline directly from GitLab UI.</strong> In this option you need to go &amp; click <strong>CI/CD — Pipelines — Run Pipeline.</strong> You can select different branch/tag and overwrite your default CI/CD variables here. Otherwise, your pipeline will run with default ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1Dz908hNr99fMkw3qvU_w.png" /><figcaption>Run pipeline via GitLab UI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f108kCeuJv2R1readj6xOQ.png" /><figcaption>Select Branch/Tag and Define Variables if needed to Overwrite</figcaption></figure><p>🚨 <strong>There is an important point to mention</strong> 🚨</p><p>While creating/destroying &amp; managing your resources with Terraform &amp; “GitLab Managed Terraform State” <strong>you need to make sure that </strong><strong>TF_STATE_NAME, OPENSTACK_IMAGE_NAME, OPENSTACK_FLAVOR_NAME, OPENSTACK_VM_NAME</strong> variables has been changed, unless you want to work on same state. Otherwise, if your intention is not to work on same state, you may broke/change the current state accidentally. Locking of the current working state or working on different branch/environment also could be other good ideas to keep secure the state you want.</p><h4>Now, let’s see a basic example of pipeline execution:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p5iak1cgybhyr5G12ENt4w.png" /><figcaption><strong>Variables has given &amp; pipeline run</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_MCiCkHQIj0OFeLvCClEmQ.png" /><figcaption><strong>General pipeline view</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*9ApOYPqV5IA09IL_jYRgIQ.png" /><figcaption>Some<strong> “test_openstack_auth” </strong>job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*r37eU0Q2JXSraD4dNCANcw.png" /><figcaption>Some<strong> “terraform_validate” </strong>job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*gDMenrhwVU5WVDwrhfTI_g.png" /><figcaption>Some<strong> “terraform_validate” </strong>job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*yRvTAQ4DrnIdGLQPM1mtBQ.png" /><figcaption>Some <strong>“terraform_plan”</strong> job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m03Q4BKxtLut0xLlfgQtJQ.png" /><figcaption>Some <strong>“terraform_apply”</strong> job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*B-7I6ISCv1JdiMS-sacQVg.png" /><figcaption>Some <strong>“terraform_apply”</strong> job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*chbm53IcjY_ZjfshQZvAVA.png" /><figcaption>Some <strong>“terraform_apply”</strong> job details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ECz5t31IFmrg1__LQA_ZFQ.png" /><figcaption><strong>Jobs executed successfully. We can still execute destroy</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_HtKL5t5noIn9wjqTL59Aw.png" /><figcaption><strong>Terraform State created on GitLab</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kyNpckApBEkwKVmg6yFqiQ.png" /><figcaption><strong>Our Instance is running now on Openstack</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*pG_TcJRWzaoBaWM1HAsJcQ.png" /><figcaption><strong>Disk attached &amp; mountpoint is created</strong></figcaption></figure><p>If we’d like to destroy resources, we can execute <strong>terraform_destroy </strong>job as well…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TM-NRFdLzkVaxFCYdrj07Q.png" /><figcaption>Some <strong>terraform_destroy</strong> details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*Fmp3zrhnbJMMZePWaXoIsw.png" /><figcaption>Some <strong>terraform_destroy</strong> details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i20nfnF6guEzU3tBIlc0rA.png" /><figcaption><strong>All jobs executed &amp; pipeline completed</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-9sOTwpYgmJte4Y973fZg.png" /><figcaption><strong>State removed</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blIZMAozaiIzrDbsAyM6dg.png" /><figcaption><strong>Instance deleted</strong></figcaption></figure><p>Well, that’s all that I want to cover in this story.<br>Thanks for your reading. See you in the next one.</p><p>Cheers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*mj4NW7l5Ufoc8CDBWLxXHg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdcf7d543582" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IaC Dünyası-2: Bazı Temel Sorular]]></title>
            <link>https://medium.com/devopsturkiye/iac-d%C3%BCnyas%C4%B1-2-baz%C4%B1-temel-sorular-3183b1335c3b?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3183b1335c3b</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[virtualization]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 18:30:34 GMT</pubDate>
            <atom:updated>2023-04-17T18:30:34.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MDqgRzH7AhGqDLqA" /><figcaption>Photo by <a href="https://unsplash.com/@randyfath?utm_source=medium&amp;utm_medium=referral">Randy Fath</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Merhabalar,</p><p>Bu yazımızda IaC yaklaşımıyla ilgili teknik olmayan fakat bu konsepti ilgilendiren bazı soruları ve farklı durumlar için muhtemel cevaplarını ele alacağız.</p><p>Hiç yaptığınız bir işi sebep/sonuç ilişkisini düşünmeden veya sorgulamadan yaptığınız oldu mu?</p><p>Bu bir oylama değil fakat eminim çoğunuz bu soruya iş/sosyal hayatta karşılaştığınız durumlar yüzünden<em> “evet”</em> cevabını verebiliyorsunuzdur. Günümüzdeki trendlere bakarsak özellikle IaC gibi sıkça adını duyduğumuz yeni gelişmeler/mimariler için oldukça geçerli bir durum olabilir. <em>“IaC olarak altyapımızı tasarlayalım, uygulamamızı mikroservis mimarisine uygun yazalım, Go’yu kullananalım”</em> vb. Fakat bundan önce…</p><blockquote><strong><em>- Peki gerçekten bunu kullanmaya ihtiyacımız var mı?</em></strong></blockquote><blockquote><strong><em>- “Neden” bunu uygulamalıyız?</em></strong></blockquote><blockquote><strong><em>- Uzun/kısa vadede neler beklemeliyiz?</em></strong></blockquote><blockquote><strong><em>- Nereden başlamalıyız? </em></strong>Nasıl bir plan ile ilerleriz?<strong><em> Nelere dikkat etmeliyiz?</em></strong></blockquote><p>Yalnızca IaC değil benzer tüm yaklaşımları kullanmaya başlamadan önce belki de sorulabilecek en temel/doğru sorulardan bazıları bunlar olabilir. Bu yazımızda IaC konsepti açısından bu sorulara kısa cevaplar bulmaya çalışarak IaC konseptini daha iyi anlamayı ve uygulamayı amaçlayacağız. Buradaki görüşlerin çoğu okumalarım, dinlemelerim ve tecrübelerim sonucu görebildiğim kadarını yansıtmaktadır.</p><p>Başlamadan önce serinin ilk yazısına göz atmak isterseniz aşağıdaki linkten ulaşabilirsiniz. Serinin ilk yazısında geçmiş dönemde altyapı sistemlerinin kurgulanması, dezavantajları ve bunlara yönelik oluşan değişimleri ve araçları incelemiştik. Ayrıca, Terraform’u tanımaya başlamıştık.</p><p><a href="https://medium.com/devopsturkiye/iac-d%C3%BCnyas%C4%B1-1-terraform-101-15d7cafda1c1">IaC Dünyası-1: Terraform 101</a></p><p>İşte, sormamız gereken sorular ve muhtemel cevapları…</p><h3>→ Peki gerçekten bunu kullanmaya ihtiyacımız var mı?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FUQ7hVY67RzQOtG0Hbo%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FUQ7hVY67RzQOtG0Hbo%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FUQ7hVY67RzQOtG0Hbo%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd45ca7c204d9addd68b1970d83ceaa4/href">https://medium.com/media/cd45ca7c204d9addd68b1970d83ceaa4/href</a></iframe><p>Bildiğiniz gibi IaC; IT altyapınızı daha hızlı deliver etmenizi sağlayarak, mevcut altyapınız üzerindeki değişikliklerin yapılmasındaki eforların ve risklerin aynı yazılımda olduğu gibi akılcı kod kullanımı yaklaşımlarıyla azaltılmasını sağlar. Aynı zamanda doğru kaynak kullanımı, güvenilir sistemler ve daha az bağımlı yapılar(less coupled) ile sorun çözme sürelerini kısaltmayı amaçlar. Kulağa hoş geliyor…</p><p>Bazı şirketler ve ekipleri, bir altyapıyı oluşturduktan sonra fazla değişiklik yapmadıklarını ve yapsalar da çok nadir olduğunu söylüyorlar. Bunun yanında, onlar için sıfırdan bir sistemi kurmanın tek yolu var. Aynı zamanda iş akışları içerisindeki bazı insanlar değişim proseslerini zorlu hale getirirken bazıları da değişimin geçici olduğunu savunur. Bu yüzden ne kadar zor ve ne kadar manuel olsa da <em>“bilinen yol en iyi yoldur” ve “böyle olması gerektiği için böyledir” </em>mantığıyla ilerleyip süreçlerini IaC gibi konseptelere dönüştürmezler. <strong>Bana göre bu durum bir noktada anlaşılabilirdir. Bu veya herhangi bir konsepte gerçekten ihtiyacı olup olmadığını bilmek, planlamak ve tam anlamıyla uygulamak ayrı bir efor gerektirmektedir. Ve gerekli olmadığı durumda veya yarardan çok zarar getirilebileceği ön görüldüğünde kullanılmamalıdır. Örneğin, farklı bir çok delivery senaryosunda çalışan ufak bir şirketin mevcut yoğunluğuna ve çalışan yetkinliğine göre bu dönüşümü yapması önceliklerinden dolayı(deadline lar, proje yükleri, mali kaygılar vb.) uzun ve zor hale gelebilir.</strong></p><p><strong>Fakat fizibilite çalışması gerçekten bunu kullanmanız gerektiğini söylüyorsa..? Elimizde bu işi yapabilecek yetenekli ve meraklı takım arkadaşlarımız varsa..? Bu durumda IaC’a gibi bir yaklaşıma ihtiyaç olmadığını düşünerek <em>“bilinen yol en iyi yoldur”, “böyle olması gerektiği için böyledir”, “bizim asıl işimiz bu değil, bir ara yaparız” </em>mindset leri yanılgıdan öteye gitmez ve bazen bu yüzden şirketler/ekipler zarar görebilir. </strong>En iyi ihtimalle yazılım ürünün/projenin gereksinim değişimleriyle birlikte böyle bir ihtiyacın çok acil bir şekilde giderilmesi gerekebilir. Bu da her şeyi çok daha zora sokacaktır. Örneğin Black Friday gibi dönemlerde bazı servislerin, infrastructure ın test edilme veya rebuild gereklilikleri vb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*GajVe3SJ0o2ysqlk5pjS3Q.png" /><figcaption>Source: <a href="https://dev.to/langyizhao/infrastructure-as-code-the-5-questions-to-ask-before-you-start-1i0p">https://dev.to/langyizhao/infrastructure-as-code-the-5-questions-to-ask-before-you-start-1i0p</a></figcaption></figure><h3>→ “Neden” bunu uygulamalıyız?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fu8d6zUOWmWJxW6mlDJ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ftheoffice-the-office-tv-episode-802-u8d6zUOWmWJxW6mlDJ&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMGI1NjgxMTdjNGEzY2IwZWExZmNmZDRlNWNlY2FmNjAzMjEwMWFhNiZjdD1n%2Fu8d6zUOWmWJxW6mlDJ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="362" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eb149c647605092201726acc149ff2c/href">https://medium.com/media/8eb149c647605092201726acc149ff2c/href</a></iframe><p>Aslında bu soru bir önceki soruyla benzer yanıta sahip. Fakat burada sebep olarak gösterebileceğimiz birçok şeyin içerisinden temel olan bir şeyi vurgulamak istedim. <strong><em>“Değişiklikler”</em></strong>…</p><p>IT altyapınız siz değişiklik yapmasanız da sürekli değişen ve bunları takip etmenizi, yönetmenizi gerektiren durumları içerir. <em>“Değişiklik”</em> yalnızca sizin kontrolünüzde yapılan update/patch demek değildir. Herhangi bir log dosyasına yazılan data, işlenen veri, OS/tool da çıkan güvenlik zaafiyeti, performance değerlerinin iyileştirilmesi için network/cluster da yapılması gerekli adımlar, buna bağlı olarak tüm ekiplerin kendi scopelarında yaptığı ve diğer ekipleri dolaylı/direkt yoldan etkileyecek işlerin tümü de aslında değişiklik demektir.</p><p>Bu kadar farklı kanallardan gelen değişiklerden ötürü altyapınızı stabil tutarak bu değişiklikleri eklemeniz, gerektiğinde test etmeniz, rebuild etmeniz zor hale gelebilmektedir. Bu yüzden değişiklerin takibini çok daha kolay sağlayabilmek adına IaC kullanmamız doğru bir yaklaşım olacaktır. Bu yaklaşımında uyguladığınız her değişiklikliğin ufak, birbirinden bağımsız ve monolithic olmayan yapıda olması bu değişiklikleri yönetilebilir olmasını sağlamaktadır. Aynı zamanda bu konsepti VCS(Github, Gitlab etc.) ve CI/CD(Jenkins, Argo etc.) ile destekleyerek otomatize etmek IaC yaklaşımından maksimum verimi alabilmeniz demektir.</p><p>En basit örnek olarak, ürününüzün farklı deployment stratejilerine bağlı olarak farklı veya aynı code repository üzerinde değişkenlerinizi ve kodlarınızı declarative/imperative şekillerde tanımlayabilirsiniz. Böylece farklı deploymentlar için değişiklikleri kontrollü şekilde takip edebilir ve istendiğinde bu repository üzerinden stacklerinizi kolayca oluşturabilirsiniz.</p><h3>→ Uzun/kısa vadede neler beklemeliyiz?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ofT5XR9pjLeLiZg9W%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fgilmoregirls-netflix-gilmore-girls-3ofT5XR9pjLeLiZg9W&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNmJkM2FiZTk4MDVjYjBjZTEyNjU3MjU1ZWQ4ODEyNzdmNmU3MzdiYSZjdD1n%2F3ofT5XR9pjLeLiZg9W%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="324" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc615f884fdbfe3384b506b988ff0ede/href">https://medium.com/media/fc615f884fdbfe3384b506b988ff0ede/href</a></iframe><p>Uzun vadede bize getirilerine bakalım… Cloud ve automation ı her alanda kullanmaya başlamamız ve maksimum verimi alma isteğimizle beraber IaC konsepti de önemli hale geldiğini söyleyebiliriz. Her ne kadar bu üç kavramı ayrı ayrı ele almamız mümkün olsa da “Cloud Age” diyebileceğimiz dönemde aslında bunları beraber düşünmemiz gerçek verimliliği yakalayabilmemizi sağlar.<strong><em> Kaliteyi, verimliliği geliştirmek için hızdan yararlanmalıyız… Ve hızı yakalayabilmek için ise kaliteyi, verimliliği oluşturmalıyız…</em></strong> Bunu yapabildiğimizde uzun vadede hız, kalite ve verimliliği yakalamış oluruz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDzB9z2ikLCpt8v3nDXgmA.png" /><figcaption>Source: <a href="https://www.oreilly.com/library/view/infrastructure-as-code/9781098114664/ch01.html">Infrastructure as Code, 2nd Edition</a>, Kief Morris</figcaption></figure><p>Tabii, bunu yapabilmek kısa vadede çok kolay olmayacaktır. Bunun başlıca sebepleri farklı odak noktaları, motivasyon ve yetkinlikler olarak sıralanabilir. Ayrıca altyapıyı otomatize hale getirmek, var olanı IaC yaklaşımına uyarlamak ve ilk başta nasıl yapılacağını, best practice lerini öğrenmek zaman alan işlerdir. Fakat sonuçta diğer sorularda da bahsedilen faydaları, esnekliği, verimliliği, kaliteyi ve hızı uzun vadede kazanırken, kısa vadede de altyapınızı bu konsept ile inşa etmenin dönüşümünü başlatmış olacaksınız. Sooner better…</p><h3>Nereden başlamalıyız? Nasıl bir plan ile ilerleriz? Nelere dikkat etmeliyiz?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F603cLZVdYomSgIBhB0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYjUwZjg3OTVjNjRmZTMzMjMzNWMzMmUwNDIyZTI3OTVmOWJjNzQzNCZjdD1n%2F603cLZVdYomSgIBhB0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F603cLZVdYomSgIBhB0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/a414be4145cdbc1cdfbd78d8bcd37fac/href">https://medium.com/media/a414be4145cdbc1cdfbd78d8bcd37fac/href</a></iframe><p>Tahmin edileceği gibi böyle bir konsept kullanımına en baştan başlamak; zorlu, birçok tercihin yapıldığı ve adaptosyon süreçlerinin yaşandığı bir süreç. Yapılan işin değerini kısa sürede görebilmek, bazılarını ikna etmek ve bunun sonucunda hedeflerinize odaklanmak zor olabilir. Bu tarz durumlarda motivasyon, yine yukarıdaki soruların cevaplarından gelmelidir. Bu cevaplar takımları ve şirketleri drive eden noktalar olmalıdır.</p><p>Peki nereden başlamalıyız? Aklımıza ilk olarak <em>“hangi aracı seçelim”, “X uygulamamız/altyapı platformumuz için entagrasyonu kolay bir yol seçelim”, </em>gibi sorular akla gelebilir. Fakat bence ilk adım<strong><em>“araçların değil konseptin önemli olduğu ve öğrenilmesi gerektiği”</em></strong> vurgulanmalıdır. Tabii ki farklı amaçlar(configuration, provisioning, CI/CD, test etc.) için farklı araç seçimleri pozitif/negatif yönleriyle ele alınmalıdır. Fakat kullandığınız şeyi ne için kullandığınızı bilmiyorsanız, ondan yeteri kadar faydalanamazsınız. Hatta bir süre sonra sizin için yük veya koparamadığınız bir bağ haline bile gelebilir.</p><p>Nereden başlayacağımızı kabaca bildikten sonra, planımızı yapma ve bunu yaparken dikkat etmemiz gereken bazı core noktaları görme zamanı… <em>“Plan”</em> kısmı farklı caseler için ne kadar değişse de <strong><em>“3 core practise”</em></strong> IaC konseptinden yaratılan planlar için uygulanmalıdır.</p><ul><li><strong><em>Define everything as code — Herşeyi kod olarak tanımla</em></strong></li></ul><p>Değişikliklerinizi uygulanabilir, hızlı ve güvenilir şekilde yapmak için planınızda, sahip olduğunuz altyapının tamamını kod olarak tanımlamalı ve buna göre inşa etmelisiniz. Böylelikle kodunuzu farklı durumlarda(kriz senaryoları, testler vb.) instancelar yaratmak için kullanabilirsiniz. Buna <strong><em>“reusability-tekrar kullanılabilirlik” </em></strong>diyebiliriz. Ayrıca tüm altyapınız size bağımlı hale gelmez. Diğer insanlar da aynı kodu kullanarak sizinle aynı platformlara sahip olur. Böylece çalışmalarınızın sonucu daha <strong><em>“consistent-tutarlı”</em></strong>, platformlarınız daha stabil olacaktır. Aynı zamanda kodunuz ve yaptığınız değişiklikler gerekli olan her kişi/takım tarafından görebileceğin için <strong><em>“transparency-şeffaflık”</em></strong> da yaklamış olacaksınız. Böylelikle daha sağlıklı geliştirmeler ve sorun giderme çalışmalarından öneriler alabilirsiniz.</p><ul><li><strong><em>Continuously test and deliver the code — Sürekli olarak test ve deliver edilen kod</em></strong></li></ul><p>IaC konseptini gerçek anlamda uygulayan takımlar test ve delivery aşamasına özen göstermelidir. Genellikle automation ile oluşturulan test ve delivery pipeline ları, en iyi sonuçları alabilmek adına her işlem ve değişiklikten sonra mutlaka çalıştırılmalıdır. CI, farklı takımlar tarafından yapılan işleri merge ettikten sonra test aşamasında testler çalışır. CD ise yaratılan code base in her zaman production-ready ve deploy edilebilir olması için çalışır. Böylece yapılan işin kalitesi ve güvenilirliği inşa edilmiş olunur.</p><ul><li><strong><em>Build small, simple pieces — Küçük ve basit parçalar inşa et</em></strong></li></ul><p>Büyük sistemlerde bir çok şey birbirine bağımlıdır ve bu yüzden normalden daha fazla karışıktır. Değişikliklerin uygulanması süreci zor ve hata yapılması olasılığı yüksektir. Bu riskleri elimine etmek, her bir değişikliği moduler olarak ayrı ayrı daha kolay uygulamak ve test etmek için altyapıyı küçük ve basit parçalar halinde kodlamalıyız.</p><p>Son söz olarak, burada bahsettiklerimiz kabaca kendi tecrübelerim ve okumalarım sonucu bu konseptin hem büyük hem de ufak ölçekteki uygulanması sürecinde ortaya çıkanlar sorular. Eminim çok daha spesifik sorular, farklı caseler bulunmaktadır. Bunları da zamanla tecrübe etmeye ve paylaşmaya çalışacağım.</p><p>Bir sonrakinde görüşmek üzere…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FFC4dBq6KGuQnK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMTJiMzE3ZjFhYTFhZDIxNGNmNjViMGFlN2IzN2E5YjQ2MzVjZTY1OCZjdD1n%2FFC4dBq6KGuQnK%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FFC4dBq6KGuQnK%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="336" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cad16c0ba7210dcf28ae211fd91d0c0/href">https://medium.com/media/0cad16c0ba7210dcf28ae211fd91d0c0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3183b1335c3b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/iac-d%C3%BCnyas%C4%B1-2-baz%C4%B1-temel-sorular-3183b1335c3b">IaC Dünyası-2: Bazı Temel Sorular</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IaC World-2: Some Key Questions]]></title>
            <link>https://oziie.medium.com/iac-world-2-some-key-questions-b3d8ea453206?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3d8ea453206</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 20:39:37 GMT</pubDate>
            <atom:updated>2023-04-13T20:39:37.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*MDqgRzH7AhGqDLqA" /><figcaption>Photo by <a href="https://unsplash.com/@randyfath?utm_source=medium&amp;utm_medium=referral">Randy Fath</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Howdy!</p><p>In this article, we will talk about non-technical topics/Q&amp;As that covers anyway IaC concept.</p><p>Have you ever done any task without taking care cause and effect relation?</p><p>It’s of course not a poll but I’m a bit sure that most of you did this in somewhere your work/social life because of the situations that you faced. If we look at today’s trends, it can be a very valid situation especially for new concepts/architectures that we hear frequently, such as IaC. <em>“Let’s design our infrastructure by using IaC, write our application in accordance with microservice architecture, let’s use Go”</em> etc. But before that…</p><blockquote>- Do we really need to use it?<br>- “Why” should we apply it?<br>- What should we expect in the long/short term?<br>- Where should we start? How do we proceed with a plan?What should we pay attention to?</blockquote><p>These questions are perhaps some of the most fundamental/correct questions to ask before starting to use not only IaC but all similar approaches. In this article, we will try to find short answers to these questions in terms of the IaC concept, and aim to better understand and apply the IaC concept. Most of the views here reflect what I can see from my reading, listening and experience.</p><p>Before to start, if you’d like to check out first article of the series, click the below link. At the first article, we examined how to building infrastructure in stone age, disadvantages of it and revolutions that has been made against to them.</p><p><a href="https://oziie.medium.com/iac-world-terraform-101-985e5ff6852">IaC World: Terraform 101</a></p><p>Here is the questions and their possible answers…</p><h3>→ Do we really need to use it?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FUQ7hVY67RzQOtG0Hbo%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FUQ7hVY67RzQOtG0Hbo%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FUQ7hVY67RzQOtG0Hbo%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd45ca7c204d9addd68b1970d83ceaa4/href">https://medium.com/media/cd45ca7c204d9addd68b1970d83ceaa4/href</a></iframe><p>As you know, IaC enables you to deliver your IT infrastructure faster, it ensures that the effort and risks of making changes on your existing infrastructure are reduced with rational code usage approaches, just like the software code. At the same time, it aims to shorten problem solving times with correct resource use, reliable systems and less coupled structures. That sounds good…</p><p>Some companies and their teams say they haven’t made much changes once they’ve set up an infrastructure, and if they do, it’s very rare. Besides, there is only one way for them to build a system from scratch. At the same time, some people in workflows make change processes difficult, while others argue that change is temporary. Therefore, no matter how difficult and manual it is, they do not turn their processes into concepts such as IaC, by proceeding with the logic of <strong><em>“the beaten road is the safest”</em> </strong>and <strong><em>“it is as it should be”.</em></strong> In my opinion, this is understandable at some point. Knowing whether team/company really needs this or any concept, planning and fully implementing it requires a separate effort. And it should not be used when it is not necessary or when it is foreseen that it may bring more harm than good. For example, for a small company operating in many different delivery scenarios, making this transformation according to its current density and employee competence may become long and difficult due to their priorities (deadlines, project loads, financial concerns, etc.).</p><p>But what if feasibility study really says you should use it..? If we have talented and curious teammates who can do this job..? In this case, thinking that <strong><em>“the beaten road is the safest”, “it is as it should be” or “this is not our main job, we will do it sometime” </em></strong>mindset will not go beyond misconceptions and sometimes compaines/teams are doing mistake because of this. Change knock the door anyway. For example, during periods such as Black Friday; testing of infrastructure, services or rebuild requirements of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*GajVe3SJ0o2ysqlk5pjS3Q.png" /><figcaption>Source: <a href="https://dev.to/langyizhao/infrastructure-as-code-the-5-questions-to-ask-before-you-start-1i0p">https://dev.to/langyizhao/infrastructure-as-code-the-5-questions-to-ask-before-you-start-1i0p</a></figcaption></figure><h3>→ “Why” should we apply it?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fu8d6zUOWmWJxW6mlDJ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ftheoffice-the-office-tv-episode-802-u8d6zUOWmWJxW6mlDJ&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMGI1NjgxMTdjNGEzY2IwZWExZmNmZDRlNWNlY2FmNjAzMjEwMWFhNiZjdD1n%2Fu8d6zUOWmWJxW6mlDJ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="362" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eb149c647605092201726acc149ff2c/href">https://medium.com/media/8eb149c647605092201726acc149ff2c/href</a></iframe><p>Actually, this question has similar answers to the previous question. But here I wanted to emphasize one thing that is fundamental among many that we can show as reasons. “Changes”…</p><p>Even if you do not make any changes, your IT infrastructure includes situations that are constantly changing and require you to monitor and manage them. “Change” doesn’t just mean an update/patch made under your control. The data written to any log file or processed, the security weakness in the OS/tool, the necessary steps to be taken in the network/cluster to improve the performance values, and accordingly, all of the work done by all teams in their own scope that will indirectly/directly affect other teams which means “change”.</p><p>Due to the changes coming from so many different channels, it can be difficult to control them, test them and rebuild your infrastructure when necessary to keep your infrastructure stable. Therefore, it would be a correct approach to use IaC in order to keep track of the changes much easier. The fact that every change you apply in this approach is small, independent and non-monolithic, makes these changes manageable. At the same time, automating this concept by supporting it with VCS(Github, Gitlab etc.) and CI/CD(Jenkins, Argo etc.) means you can get maximum efficiency from the IaC approach.</p><p>As the simplest example, you can define your variables and write codes in declarative/imperative ways on different or the same code repository depending on deployment strategy of your product. Thus, you can monitor the changes for different deployments in a controlled manner and easily create your stacks from this repository when requested.</p><h3>→ What should we expect in the long/short term?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ofT5XR9pjLeLiZg9W%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fgilmoregirls-netflix-gilmore-girls-3ofT5XR9pjLeLiZg9W&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNmJkM2FiZTk4MDVjYjBjZTEyNjU3MjU1ZWQ4ODEyNzdmNmU3MzdiYSZjdD1n%2F3ofT5XR9pjLeLiZg9W%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="324" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc615f884fdbfe3384b506b988ff0ede/href">https://medium.com/media/fc615f884fdbfe3384b506b988ff0ede/href</a></iframe><p>Let’s look at the benefits for us in the long term… We can say that the IaC concept has become important as we start to use cloud and automation in every field and aiming to get maximum efficiency. Although it is possible to consider these three concepts separately, considering them together in the period that we can call “Cloud Age” allows us to achieve real efficiency. <strong><em>We must make use of speed to improve quality and productivity… and to achieve speed, we must create quality and efficiency…</em></strong> When we can do this, we will have achieved speed, quality and efficiency in the long run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDzB9z2ikLCpt8v3nDXgmA.png" /><figcaption>Source: <a href="https://www.oreilly.com/library/view/infrastructure-as-code/9781098114664/ch01.html">Infrastructure as Code, 2nd Edition</a>, Kief Morris</figcaption></figure><p>Of course, doing this will not be easy in the short term. The main reasons for this can be listed as different focus points, motivation and competencies. In addition, it takes time to automate the infrastructure, adapt the existing IaC approach, and learn how to do it and best practices in the first place. But in the end, while you will gain the benefits of flexibility, efficiency, quality and speed mentioned in the other questions in the long run, you will have started the transformation of building your infrastructure with this concept in the short term. For this reason, we can say “sooner better”…</p><h3>→ Where should we start? How do we proceed with a plan? What should we pay attention to?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F603cLZVdYomSgIBhB0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYjUwZjg3OTVjNjRmZTMzMjMzNWMzMmUwNDIyZTI3OTVmOWJjNzQzNCZjdD1n%2F603cLZVdYomSgIBhB0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F603cLZVdYomSgIBhB0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/a414be4145cdbc1cdfbd78d8bcd37fac/href">https://medium.com/media/a414be4145cdbc1cdfbd78d8bcd37fac/href</a></iframe><p>As might be expected, to start using such a concept from scratch; it is a challenging process where many choices are made and adaptation processes are experienced. It can be difficult to see the value of the work done in a short time, to convince some people and, as a result, to focus on your goals. In such cases, motivation should come from the answers of the above questions. These answers should be the points that drive teams and companies.</p><p>So where should we start? Questions such as <strong><em>“Which tool should we choose”, “Let’s choose an easy-to-integrate way for our X application/infrastructure platform”</em></strong>, may come to mind first. But I think the first step should be emphasized that <strong><em>“the concept is important and should be learned, not the tools.”</em></strong>. Of course, different tool selections for different purposes (configuration, provisioning, CI/CD, testing etc.) should be considered with their positive/negative aspects. But if you don’t know what you’re using for which purposes, you can’t get enough of it. It may even become a burden or a bond that you cannot break after a while.</p><p>After knowing roughly where to start, it’s time to make our plan and see some core points that we need to pay attention to while doing this… Although the “plan” part varies for different cases, the <strong><em>“3 core practices”</em></strong> should be applied for the plans created from the IaC concept.</p><ul><li><strong><em>Define everything as code</em></strong></li></ul><p>In order to make your changes applicable, fast and reliable, you should define all the infrastructure you have as code in your plan and build accordingly. Thus, you can use your code to create instances in different situations (crisis scenarios, tests, etc.). We can call this <strong>“reusability”</strong>. Also, your entire infrastructure does not become dependent on you. Other people get the same platforms as you using the same code. Thus, the result of your work will be more <strong>“consistent”</strong> and your platforms will be more stable. At the same time, you will have achieved <strong>“transparency”</strong> as your code and the changes you make can be seen by every person/team that concerned. In this way, you can get suggestions from healthier improvements and troubleshooting studies.</p><ul><li><strong><em>Continuously test and deliver the code</em></strong></li></ul><p>Teams that truly implement the IaC concept should pay attention to the testing and delivery phase. Test and delivery pipelines, which are usually created with automation, must be run after every transaction and change in order to get the best results. After CI merges done by the different teams, appropriate tests execute in the testing phase. On the other hand, CD works so that the created code base is always production-ready and deployable. Thus, the quality and reliability of the work is built with the matter of speed.</p><ul><li><strong><em>Build small, simple pieces</em></strong></li></ul><p>In large systems, many things are interconnected and therefore more complex than usual. The process of implementing changes is difficult and error-prone. To eliminate these risks and test each change in modular form more easily, we must code the infrastructure in small and simple pieces.</p><p>As a final word, what we are talking about here are the questions that arise roughly as a result of my own experiences and readings during the implementation of this concept on both a large and a small scale. I’m sure there are much more specific questions, different cases. I will try to experience and share them in time.</p><p>See you in the next..!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FFC4dBq6KGuQnK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMTJiMzE3ZjFhYTFhZDIxNGNmNjViMGFlN2IzN2E5YjQ2MzVjZTY1OCZjdD1n%2FFC4dBq6KGuQnK%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FFC4dBq6KGuQnK%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="336" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cad16c0ba7210dcf28ae211fd91d0c0/href">https://medium.com/media/0cad16c0ba7210dcf28ae211fd91d0c0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3d8ea453206" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IaC World: Terraform 101]]></title>
            <link>https://oziie.medium.com/iac-world-terraform-101-985e5ff6852?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/985e5ff6852</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Sat, 27 Feb 2021 19:13:22 GMT</pubDate>
            <atom:updated>2021-02-27T19:15:26.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>IaC World-1: Terraform 101</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6Diu0Qk1brL8Ei9v.jpeg" /></figure><p>Hello,<br>I thought of starting a new series that tackles topics that could be involved in the IaC (Infrastructure as Code) approach. I wanted to start this series with <strong>Terraform</strong> first. In fact, I wish you to read Terraform which has been heard and known by many people once again from me. In this first article of the series, you will see general information about IaC, general information about Terraform, and some examples of basic scenarios for Terraform. Also, according to my plans, I intend to share more than one article for any tool in this series.</p><h3><strong>About IaC</strong></h3><p>As the name suggests, Infrastructure as Code (IaC), it is the conversion of infrastructure into code. The “code” we are talking about here includes all runtime environments, network settings, resource needs and their parameters that our environments (infrastructures) may need. As the code changes over time, it is necessary to keep it in a VCS (Version Control System) like Git and to version it. These predefined files (manifests) are later used to set up the infrastructure quickly and flawlessly using different tools. The design and creation processes of the code may vary depending on the competencies and rules of the tool used. For example, in the past, IaC logic was used as IT workers could run scripting or commands one after the other. However, the methods that are valid today are related to the development and coding of this work with tools in a completely different framework. Here, we create and execute our codes within the framework of the rules and competencies of these tools.</p><p>So <strong>why</strong> and <strong>how</strong> do we do this? What are the <strong>benefits</strong> and <strong>differences of existing tools</strong>? Let’s try to understand the IaC better with answers to these questions.</p><h4>Problems… Why and How IaC?</h4><p>As in the past and today, one of the most important things that will always be is how the existing software-service will be offered. The success of the work is largely shaped accordingly. In the past, when companies mostly provided services on physical servers, the infrastructure they had was of the type that we can call <strong>“static”</strong>. When we say static infrastructure, let’s think of a data center. Disks, RAMs on the server; network elements such as routers, switches … Let’s consider the costs of setting up and configuring them from scratch for large companies that provide great services … Let’s consider the approval processes and hardware deliveries that need to go through in order to get new hardware for the purpose of capacity increase (horizontal-vertical scale) … Let’s think about the processes of integrating and configuring a lot of servers and routers… Anyway, let’s not think more :) :) These are really time and cash-wasting problems.</p><p>Fortunately, there are “<strong>dynamic”</strong> types of infrastructures that solve them today. The above problems are no longer worse for us. We can easily handle these with cloud providers, virtualization technologies, configuration management tools, perhaps with a single click. However, there are also problems for such structures, which we can call dynamic. To give a few examples:</p><ul><li>Although we can easily create the infrastructure in cloud providers or other virtualization environments, the speed and reliability of this process is still very important for us.</li><li>Infrastructure is ready. But still not configured. Doing this manually in an architecture we have many VMs is a huge waste of time.</li><li>What if we need to quickly install the same architecture we built on AWS on Azure, GCP, for example?</li><li>We prepared our infrastructure, but it happened that there was a problem and we need to re-install this entire infrastructure. How do we go back to the beginning and establish the first immutable form of this infrastructure?</li></ul><p>These problems we mentioned may be the answer to the question of “why we developed and use the IaC concept”. In fact, in the past, IaC logic was used as IT workers were able to run scripting or commands one after the other. But what we are talking about today is about the development and coding of this business with tools in a completely different framework.</p><h4>IaC Concepts</h4><p>Starting from the IaC, I want to explain a few concepts so that we don’t get confused in some matters. If you start reading about this, you are very likely to see these concepts.</p><p><strong><em>→ Mutable — Immutable Infrastructure</em></strong></p><p>First, let’s see what <strong>“mutable”</strong> and <strong>“immutable”</strong> mean.<br>The word <strong><em>“mutable”</em></strong> means “variable” and <strong><em>“immutable”</em></strong> means “constant, non-variable” as its opposite. When we say “mutable” infrastructure, we can give examples of traditional systems that are always open to configurations and other changes. When we think about it, when we set up a traditional system, then connect with SSH on this system and create updates, environment additions etc. in software packages. We were doing such processes one by one. Frankly, this is still the case in most places. That’s why we call these systems<strong> “mutable infrastructure”.</strong> In addition, although the operations we do for a group of servers in such an environment are the same, as a result, some servers can be completely different and unique. With this thin configuration that is difficult to diagnose and recreate, its errors are called<strong> “configuration drift”.</strong></p><p>On the other hand, <strong>“immutable infrastructure”</strong>; use ready-made structures such as VM or container image that creating by IaC tools such as Terraform or CloudFormation. These ready-made images, created with the help of tools such as Docker and VMware, contain all the necessary configurations of the infrastructure to be installed. Thus, there is no need for major configuration changes on the infrastructure after the installation. If there is a need for major configuration changes in the infrastructure, new images are created and as best practice, the images are versioned with a source control (eg Git). Servers are rebooted with the new image created and the old ones are terminated. Thus, the “configuration drift” situation is eliminated and the changes made are more reliable. This process is still somewhat slow.</p><p>Although there is no single truth between the concepts of mutable and immutable infrastructure, the benefits and disadvantages of these two types of infrastructure are different from each other. If you want to get more detailed information on the subject, I strongly recommend you to check the article <a href="https://medium.com/the-cloud-architect/immutable-infrastructure-21f6613e7a23"><strong>here</strong></a>.</p><p><strong><em>→ Declarative-Imperative(Procedural) Code</em></strong></p><p>Two of the other concepts are the concepts of <strong>“declarative” </strong>and <strong>“imperative (procedural)”</strong>. First of all, choosing the appropriate tool is very important in the IaC approach. You should choose the right tool according to your competencies, goals and the language used by this tool. Otherwise, the intended goals may not be achieved or you may have difficulties in this way. Therefore, these two concepts will help in tool selection.</p><p>In short, in the <strong><em>“declarative”</em></strong> approach, we list what we need in all details and specify what we need to have after code execution by coding in the language of the tool we use. While doing this, we do not need to tell the tool we use how the tool can do this job. In a way, we give the answer to the question of “what is necessary”. In the <strong><em>“imperative”</em></strong> (sometimes referred to as <strong><em>“procedural”</em></strong>) approach, we specify by coding how to create the necessary resources. Here, too, we answer the question of “how to do”.</p><p>With a small example, we can understand these two concepts better. For example, you wanted to have a coffee while reading this article at your table. How would you express this with <em>“declarative”</em> and <em>“imperative”</em> approaches…? To express such a situation with a <strong>“declarative”</strong> approach:</p><blockquote>“Can I have my flat white coffee on my table while reading Ozan’s Medium article titled ‘IaC World-1: Terraform’?” It is sufficient to declarative approach. The waiter in the cafe will bring your coffee to your table soon :)</blockquote><p>With the <strong><em>“imperative (procedural)”</em></strong> approach, we could express this situation as follows:</p><blockquote>“While reading Ozan’s Medium article titled” IaC World-1: Terraform “, I want to drink flat white coffee. To do this, you must do the following: Prepare 40ml of double espresso, heat 80ml of milk into cream, slowly pour cream milk over double espresso. Bring it to the table. ” It is required for the imperative (procedural) approach. The waiter in the cafe will soon bring your coffee to your table. :)</blockquote><p>Finally, we can understand the declarative-imperative approach through the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*dizyZUfLwRUBJg4nxCpS5w.png" /><figcaption>Source: <a href="https://www.copebit.ch/how-declarative-and-imperative-styles-differ-in-infrastructure-as-code/">https://www.copebit.ch/how-declarative-and-imperative-styles-differ-in-infrastructure-as-code/</a></figcaption></figure><p>Again, as in the “mutable-immutable” issue, there is no “clear truth” here. It may be better for you to define your infrastructure sometimes as “declarative” and sometimes as “imperative (procedural)”. There are different tools that use both approaches. Sometimes we even use these tools together. You should decide this according to your case. As a result, that coffee comes in all kinds so :)</p><p><strong><em>→ Configuration Management Tools — Provisioning Tools</em></strong></p><p>Finally, let’s look at the interpretation of these two different terms. Tools used in the IaC world are generally divided into <strong><em>“Configuration Management Tools”</em></strong> and <strong><em>“Provisioning Tools”</em></strong>.</p><p><em>“Configuration Management Tools”</em> are tools designed for configuring on <strong>existing infrastructure</strong>. Some of the things we can do with these tools are: Identifying users on the OS, changing the status of services (start-stop-restart), installing and updating packages for the software environment, etc.</p><ul><li>Chef</li><li>Puppet</li><li>Ansible</li><li>SaltStack</li></ul><p><em>“Provisioning Tools”</em>, on the other hand, can include all of the tools that prepare the items that make up <strong>your planned infrastructure</strong> (VM, database servers, load balancers, VPC, subnet, firewall, etc.). These tools usually call the APIs of providers (VMware, AWS, k8s etc.) and create the necessary infrastructure. Examples of these are:</p><ul><li>Terraform</li><li>CloudFormation</li><li>OpenStack Heat</li></ul><p>We can see a summary of all the titles so far and more in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*thZHSiG1Fo7RuonQ.png" /></figure><p>As you can see in the table above, there are many tool alternatives. Which of these should be used is entirely up to you. You should make the necessary evaluation from every angle and decide accordingly. One of the common thoughts is that this is the hardest and most important part of the job… Choosing the right vehicle… Also, there are other concepts that may be useful to know in the IaC world. However, I found it more correct to explain them to you in other articles so that this article does not get longer.</p><p>Now, let’s see what “Terraform” I have been working with recently…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gt5tF1disN_wjKFT.png" /></figure><h4>Quick Introduction</h4><p>Terraform was published as an initial release on July 28, 2014 by HashiCorp company. Along with being an open source tool, “Terraform Enterprise” version is also available. It is written in “Go” language. In its simplest form, if we talk about what it does, it allows you to make changes on this code by defining your existing or new infrastructure structures as declarative code and the changes you make to be tagged according to your environment type (test / prod, etc.). The code we are talking about here is the “HCL (Hashicorp Configuration Language)” developed by HashiCorp, which is very easy to read, write and understand. HCL is a syntax that is also used in other products of HashiCorp. Of course, this is one of the simplest definitions I can convey to you.</p><h4>Why Terraform in my opinion?</h4><p>Terraform is a preferred tool to perform mission-critic tasks with high reliability and to get rid of unnecessary workload in many different areas such as SDN (Software-Defined-Networking), the establishment of multi cloud structures, as well as working integrated with many DevOps tools. . For my part, there has not yet been a specific tool that I have to use due to its distinctive feature in the IaC world. But I would like to talk a little bit about why I started learning the IaC approach with a provisioning tool like Terraform. I can briefly list these reasons:</p><ul><li>HCL, the language in which terraform was written, seemed understandable to me.</li><li>Moreover, more importantly than this, Terraform could be integrated with a wide variety of providers.</li><li>Their documentation seemed very understandable and simple to me. You can see the detailed documentation page <a href="https://www.terraform.io/docs/index.html"><strong>here</strong></a>.</li><li>Creating immutable infrastructure by providing seamless infrastructure changes.</li><li>Ability to work with many providers. <a href="https://registry.terraform.io/browse/providers"><strong>Here</strong></a> you can see the list of all providers Terraform can work with.</li></ul><h4>Terraform Core Concepts</h4><p>There are a few concepts in Terraform that we need to know. According to these concepts, we write the code that will create our infrastructure. While explaining this part, I’ll be using my GitHub repository tag below. You can browse if you wish:</p><p><a href="https://github.com/oziie/my-terraform-labs/">oziie/my-terraform-labs</a></p><ul><li><strong>Variables</strong></li></ul><p>Variables refers to the inputs we use in Terraform. The variables we define according to our request are structures in the form of key-value that enable us to make all kinds of customization. In Terraform, we can store them in a file like <strong><em>“variables.tf”</em></strong>. For example, ext_port, storage name, container name, etc. Below you can see an example of how “int_port” and “ext_port” variables are used in the <strong><em>“main.tf” </em></strong>file in Terraform where we define the main code in Terraform:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e44dc328eddc0d25693170ad21d3fa75/href">https://medium.com/media/e44dc328eddc0d25693170ad21d3fa75/href</a></iframe><p>In addition, in the code example above, we can give the value of a variable in 2 different ways as “dev” and “prod”. We will examine how we say which one to use later in the article.</p><p><em>A quick note: we can think of it as if we were actually calling a different value with the “$” symbol. This is called “Interpolation syntax” and it is a condition frequently used in Terraform. More detailed information can be found </em><a href="https://www.terraform.io/docs/configuration/expressions.html"><strong><em>here</em></strong></a><em>.</em></p><ul><li><strong>Provider</strong></li></ul><p>We can say that they are plugins that enable Terraform to make API calls to use the services. Thanks to these plugins, we actually create our infrastructure by communicating with the services we want. We can give example for “provider” in Terraform like Docker, VMware or cloud services such as AWS. As I mentioned before, you can see <a href="https://www.terraform.io/docs/providers/index.html"><strong>here</strong></a> all the providers Terraform can work with.</p><ul><li><strong>Modules</strong></li></ul><p>It refers to the folder structures in which the Terraform files for which the Infrastructure is defined are created hierarchically. Thus, in Terraform, you can use configurations by calling them over and over without repeating the code. The best way to use your code in Terraform effectively, to test your code and to create a modular infrastructure is to use the “modules” structure.</p><p>By default, actually each Terraform configuration is defined in a module called “Root Module”. We can think of it as follows:</p><pre>root-module <em>(We don&#39;t have to name like this.)</em><br> └ main.tf<br> └ outputs.tf<br> └ variables.tf</pre><p>We can create modules for many different purposes in Terraform. For example, we can create separate modules for staging and production environments. As another example, when working with the Docker provider, we can define modules such as “image” and “container” and call them in a root module. We see this scenario in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/679c6a9390a9449fec241edc872eaeb0/href">https://medium.com/media/679c6a9390a9449fec241edc872eaeb0/href</a></iframe><p>You can better understand the file hierarchy from the link below:</p><p><a href="https://github.com/oziie/my-terraform-labs/tree/master/docker/basics/modules">oziie/my-terraform-labs</a></p><ul><li><strong>State</strong></li></ul><p>It contains cached information about the infrastructure and related configurations managed by Terraform. We will see a component named “Terraform Core” in the next title where I will explain the working logic of Terraform. “Terraform Core” keeps the latest state of the infrastructure in a state and applies it if there is a change (add, delete, update etc.) on your infrastructure configurations the next time you run your code. If not, your infrastructure will remain as it was. Also, in case you manually change your infrastructure, Terraform will rearrange the infrastructure according to its here, using the state type as reference the next time you run it. Thus, “immutable infrastructure” is provided.</p><ul><li><strong>Resources</strong></li></ul><p>It defines the objects (VM, container, DNS records, virtual networks etc.) that constitute the infrastructure and we configure. In fact, resources are defined as blocks and each block can contain one or more objects. Each resource may have many different features, but only a small part is sufficient for initial use. For example, if we are going to create an instance on AWS, we can do it as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c22355f9274916c48924867a0418c52/href">https://medium.com/media/6c22355f9274916c48924867a0418c52/href</a></iframe><ul><li><strong>Outputs</strong></li></ul><p>They are the return values that can be used by other Terraform modules of Terraform within a module. We can understand better with the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/219ed2af3261b584a88fd667090d61ea/href">https://medium.com/media/219ed2af3261b584a88fd667090d61ea/href</a></iframe><h4>Terraform Working Principle</h4><p>When we want to create an infrastructure using Terraform, our configuration files basically go through 4 stages and as a result, our infrastructure comes ready:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IhlhsKgO7IJGPF2P.jpeg" /><figcaption>Source: <a href="https://www.ovh.com/blog/private_cloud_and_hashicorp_terraform_part1/">https://www.ovh.com/blog/private_cloud_and_hashicorp_terraform_part1/</a></figcaption></figure><p><strong>Init →</strong> Initializes all Terraform files on Workspace.</p><p><strong>Plan → </strong>An execution plan is created to achieve a desired state of the infrastructure. Sometimes changes are made in configuration files or plans can be created with different parameters for different environments (dev or prod). In such a case, the “Plan” step is repeated and different plans are obtained.</p><p><strong>Apply →</strong> It is one of the stages where the infrastructure implements the changes in its actual/current state to achieve the desired status. “Apply” stage is completed through a Terraform “Plan”. After this stage, we have the desired infrastructure at hand.</p><p><strong>Destroy →</strong> It is used to delete all old infrastructure resources that need to be terminated after the “Apply” stage.</p><p>When we look at the architecture of Terraform, all the steps mentioned above are actually done by the component called “Terraform Core” through CLI with commands such as “terraform init”, “terraform plan”, “terraform apply”, “terraform destroy”. If you remember, we saw this as a structure that keeps the “state” in the above parts of the article.</p><p>Let’s take a look at how Terraform works step by step with the following Terraform architecture diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*UObGyEZOHbheHfUg.png" /><figcaption>Source: <a href="https://geekflare.com/terraform-for-beginners/">https://geekflare.com/terraform-for-beginners/</a></figcaption></figure><p>First, <em>“Terraform Core” </em>processes the configuration files you created. Thus, in the second step, <em>“Terraform Core” </em>updates the <em>“Terraform State”</em> and enables the infrastructure to state the desired current form. Afterwards, what needs to be done (update, add, delete) is determined and applied on the infrastructure. While doing these, of course, it performs the 4 stages <em>(init-plan-apply-destroy)</em> we mentioned above, depending on the situation. As a result, an infrastructure object is created on the provider we work with.</p><p>Finally, you can watch the video below, which is complementary. HashiCorp Co-Founder Armon Dadgar describes Terraform in a very simple and understandable way. Thus, you can complete the missing places in your mind.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fh970ZBgKINg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dh970ZBgKINg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fh970ZBgKINg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d595218d08913081caa535cc1595b5fa/href">https://medium.com/media/d595218d08913081caa535cc1595b5fa/href</a></iframe><h4>Docker Container Provisioning with Terraform</h4><p>In this section, I will show a basic example with Docker, one of the providers of Terraform.</p><p><strong><em>Important note! →</em></strong><em> I have worked with Terraform v0.11.13 at the time of writing this article. This version is an old Terraform version. There may be differences in syntax writing in Github repository with the current version. Therefore, if you are using a different version in your trials, you may get errors. You can find the necessary explanation </em><a href="https://www.terraform.io/upgrade-guides/0-13.html"><strong><em>here </em></strong></a><em>and </em><a href="https://github.com/hashicorp/terraform/blob/guide-v0.13-beta/draft-upgrade-guide.md#explicit-provider-source-locations"><strong><em>here</em></strong></a><em>. You can also check </em><a href="https://stackoverflow.com/questions/59038537/fix-interpolation-only-expressions-are-deprecated-warning-in-terraform#:~:text=Template%20interpolation%20syntax%20is%20still,of%20a%20single%20interpolation%20sequence."><strong><em>here </em></strong></a><em>for a solution to “interpolation syntax deprecated” errors. I will be updating the content of the repository from time to time. Thank you for your understanding…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*eBdi5XE0rqeJwXuT.png" /></figure><p>First of all, if Terraform is not installed in your environment, you can easily install it by following the steps below:</p><ul><li>You can download it <a href="https://www.terraform.io/downloads.html"><strong>here </strong></a>to install the latest release file for your preferred environment. I preferred Linux(CentOS) environment. You can also install it in environments such as Windows, MacOS:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2DBx1CMR_1_6edPx.png" /></figure><ul><li>Then we need to unzip the downloaded file and put the binary file under <strong><em>“/usr/local/bin” </em></strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/0*5Rfm_pMag4JCp3wr.png" /></figure><ul><li>We are now ready to use Terraform. You can test it as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/0*PWMQ3wn8ktqWQ3_A.png" /></figure><ul><li>For the demo, I will be using my following GitHub repository, folder is <strong><em>(docker → basics) </em></strong>:</li></ul><p><a href="https://github.com/oziie/my-terraform-labs">oziie/my-terraform-labs</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*sL_cpNTyG3N4ZCrz.png" /></figure><p><strong>Our scenario will be as follows:</strong> We will create containers with different features for our two different environments named “Prod” and “Dev”. While doing this, of course, we will create different Terraform plans and apply. I will try to specify the details in the other steps.</p><p>Below you can see the files used for this purpose:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38cabbbc87a98f7cb7cb7c5e5f29c42a/href">https://medium.com/media/38cabbbc87a98f7cb7cb7c5e5f29c42a/href</a></iframe><p>If we want to talk about the code above, we can say the following:</p><p>→ We will use different external ports for two different environments. We will be using port <strong>8081</strong> for the <strong><em>“dev”</em></strong> environment and <strong><em>80</em></strong> port for the<strong><em> “prod”</em></strong> environment. <strong><em>The internal port</em> </strong>we use will be the <strong><em>same for both environments.</em></strong><br>→ Likewise, we will be using <strong><em>“ghost: latest” image for “dev” </em></strong>environment and <strong><em>“ghost: alpine” image for “prod”</em></strong> environment.<br>→ Also, variables such as <strong><em>“container_name”, “image_name” </em></strong>will change according to the environment type.</p><p>In fact, when you examine all these properties, under <strong><em>“variables.tf”</em></strong>, a variable of type <strong><em>“map”</em></strong> is defined.</p><ul><li>First of all, we will go to the relevant folder and run our first command, <strong><em>“terraform init”</em></strong>. So Terraform will now know that we are working here.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*urdGKWn8prEqbmba.png" /></figure><p>Then, we can first create our plan for the <strong><em>“dev”</em></strong> environment. To do this, we need to run the command <strong><em>terraform plan -out=tfdev_plan -var env=dev .</em></strong> Here, as <strong><em>“-var env = dev”</em></strong>, we provide a variable that was not previously defined in the Terraform configuration but required as an input. We need to do this every time for the plan to create, for the resources to be destroyed (for Terraform version 0.11.3). As you can see Terraform has defined the resources to be created for us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*BNDcQ9lhFeahlxYu.png" /></figure><ul><li>As you can see, we have created a plan called <strong><em>“tfdev_plan”</em></strong>. Now, we can apply this plan we have created. As you can see in the picture below, all the planned resources have been created by Terraform for us. Also, at the bottom, under <strong><em>“Outputs”</em></strong>, we can see the outputs of the variables that we defined in the <strong><em>“outputs.tf”</em></strong> file:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VKEXUVZAfoTccJqo.png" /></figure><ul><li>When we check it on Docker, we can see that the container has been created. As we configured in Terraform, we used the port <strong><em>“8081” </em></strong>as an <strong><em>external port for the “dev” environment </em></strong>and <strong><em>this port is mapped to 2368 internally.</em></strong> The sample Ghost Blog page can be accessed by typing <strong><em>“IP: 8081”</em></strong> for the <strong><em>“dev”</em></strong> environment and <strong><em>“IP: 80”</em></strong> for the <strong><em>“prod”</em></strong> when our container comes up:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FaoSenwUEvGJRY4p.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f1iKWST_G6byvk1E.png" /></figure><ul><li>Later, we can destory the <strong><em>“dev”</em></strong> environment to create our other environment, or we can directly create our new <strong><em>“prod” </em></strong>plan and have Terraform re-create the infrastructure accordingly.<br>Here I prefer to destroy as more graceful. To do this, we need to run the following command:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NdH1bdkjrQV9vy4K.png" /></figure><ul><li>At this stage, we have a fresh environment again. So, we deleted the previous <strong><em>“dev”</em></strong> environment resources. Let’s create a plan for the <strong><em>“prod”</em></strong> environment:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*g_y_vgFxVTSLuf6O.png" /></figure><ul><li>We can apply this plan we have created in the same way as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DL5WukbWYxE8xtqv.png" /></figure><ul><li>Our container will be created as seen below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3iaRuDVnqNzIjHdv.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y-iIa67dpWOM5qj0.png" /></figure><ul><li>After we are done, we can remove this environment if we want. We will do this again with the “<strong><em>terraform destroy” </em></strong>command, but this time we can give the <strong><em>“-auto-approve”</em></strong> flag and delete it directly without waiting for us to confirm.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GefyzZswKylTvlW8.png" /></figure><p>We have come to the end of the article here. I will show you in next articles, how you can use Terraform to create and manage your Kubernetes, Docker, Jenkins and any cloud environments.</p><p>See you in the next article!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*9q-aBxKZcrF1zI5q.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=985e5ff6852" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IaC Dünyası-1: Terraform 101]]></title>
            <link>https://medium.com/devopsturkiye/iac-d%C3%BCnyas%C4%B1-1-terraform-101-15d7cafda1c1?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/15d7cafda1c1</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 14:23:30 GMT</pubDate>
            <atom:updated>2020-11-04T14:23:30.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jplGXRp5ba1-U3EJLipaIQ.jpeg" /></figure><p>Merhabalar,</p><p>Bugün itibariyle, IaC (Infrastructure as Code) yaklaşımına dahil olabilecek konuları ele alan yeni bir seri başlatmayı düşündüm. Bu seriye ilk olarak Terraform ile başlamak istedim. Aslında artık çoğu kişi tarafından duyulmuş ve bilinen Terraform’u birkez de benden okumanızı dilerim. Serinin bu ilk yazısında IaC ile ilgili genel bilgiler, Terraform ile ilgili genel bilgiler, ve Terraform için giriş seviyesinde bazı senaryo örnekleri göreceksiniz. Ayrıca planlarıma göre bu seri içerisinde herhangi bir tool için birden fazla yazıyı da sizlerle paylaşmayı düşünüyorum.</p><h3>IaC Hakkında</h3><p>Infrastructure as Code (IaC) isminden anlaşılacağı gibi kısaca altyapının code a dönüştürülmesidir. Burada bahsettiğimiz “code”, ortamlarımızın (infrastructures) ihtiyaç duyabileceği tüm runtime environmentlar, network ayarları, kaynak ihtiyaçları ve bunların parametrelerini içerir. Kodun zaman içerisinde değişmesine bağlı olarak da Git gibi bir VCS(Version Control System) içerisinde tutulması ve versiyonlanması gerekliliği de doğmaktadır. Bu ön tanımlı dosyalar(manifests) daha sonradan farklı toollar yardımıyla infrastructure ı hızlıca ve hatasız olarak kurgulamak için kullanılır. Code un tasarım ve oluşturma süreçleri, kullanılan aracın yetkinliklerine ve kurallarına bağlı olarak değişkenlik gösterebilir. Örneğin, geçmişte IT çalışanlarının scripting veya komutları ardı ardına çalıştırabilmesiyle IaC mantığı kullanılmaya başlanmıştı. Fakat bugün geçerli olan yöntemler, bu işin tamamen başka çerçevede tool lar ile gelişmesi ve kodlamaya dökülmesi ile alakalıdır. Burada bu tool ların kuralları ve yetkinlikleri çerçevesinde kodlarımızı oluşturuyor ve execute ediyoruz.</p><p>Peki bunu <strong>neden</strong> ve <strong>nasıl</strong> yapıyoruz? Var olan <strong>araçların sağladığı</strong> <strong>faydalar</strong>, <strong>farklılıklar</strong> nelerdir? Bu sorulara cevaplar arayak IaC’ı daha iyi anlamaya çalışalım.</p><h4>Sorunlarımız… Neden ve Nasıl IaC?</h4><p>Geçmişte ve günümüzde olduğu gibi gelecekte de her zaman ön planda olacak en önemli şeylerden biri var olan yazılımın-hizmetin nasıl sunulacağıdır. Yapılan işin başarısı büyük oranda buna göre şekillenir. Geçmişte şirketler çoğunlukla fiziksel sunucularda hizmetler verirken sahip oldukları altyapı <strong>static </strong>diyebileceğimiz türdeydi. Static infrastructure dediğimizde bir data center ı düşünelim. Server üzerindeki diskler, RAM’ler; network elemanlarından router lar, switchler … Bunları büyük hizmetler veren, büyük şirketler için sıfırdan kurmanın,configure etmenin getirdiği maliyeti düşünelim… Kapasite arttırımı amacıyla(horizantal-vertical scale) yeni hardware alınabilmesini için geçmesi gereken approval süreçlerini, donanım teslimlerini düşünelim…Sonra bu donanımları bu çooook sayıdaki serverlara-routerlara entegre ve configure etme süreçlerini düşünelim… Neyse daha fazla düşünmeyelim :):) Bunlar gerçekten zaman, cash kaybettiren sorunlar.</p><p>Neyse ki, günümüzde bunları çözen <strong>dynamic </strong>türde olan altyapılar var. Artık yukarıdaki sorunlar bizim gözümüzde büyümüyor. Bunları cloud provider lar, sanallaştırma teknolojileri, configuration management toolları sayesinde kolaylıkla belki de tek tıkla hallediyoruz. Yine de dynamic diyebileceğimiz bu türdeki yapılar için de sorunlar bulunmaktadır. Birkaç örnek vermek gerekirse:</p><ul><li>Her ne kadar infrastructure yapısını cloud providerlar veya diğer sanallaştırma ortamlarında kolayca oluştursak da bu sürecin hızı ve güvenirliği bizim için hala çok önemli.</li><li>Infrastructure hazır. Fakat hala configure edilmemiş halde. Birçok VM’miz olan bir mimaride bunu el ile yapmak büyük bir zaman kaybı.</li><li>Peki örneğin AWS üzerine kurduğumuz bir mimarinin aynısını hızlıca Azure, GCP üzerine de kurmamız gerekirse?</li><li>Altyapımızı hazırladık fakat oldu ki bir sorun oldu ve tüm bu altapıyı tekrar kurmamız gerekiyor. Başa dönerek bu infrastructure ın ilk saf-değişmez(immutable) halini nasıl kurarız?</li></ul><p>İşte bu bahsettiğimiz sorunlar “neden IaC kavramını geliştirdik ve kullanıyoruz” sorusunun cevabı olabilir. Aslında, geçmişte IT çalışanlarının scripting veya komutları ardı ardına çalıştırabilmesiyle IaC mantığı kullanılmaya başlanmıştı. Fakat bugün bahsettiğimiz şey, bu işin tamamen başka çerçevede tool lar ile gelişmesi ve kodlamaya dökülmesi ile alakalıdır.</p><h4>Bazı IaC Kavramları</h4><p>IaC’dan bashetmişken, bazı konularda anlam kargaşasına düşmememiz için birkaç kavramı açıklamak istiyorum. Eğer bu konuda birşeyler okumaya başlarsanız, bu kavramları görmeniz çok muhtemel.</p><p><strong><em>→ Mutable — Immutable Infrastructure</em></strong></p><p>İlk olarak <strong>“mutable”</strong> ve <strong>“immutable”</strong> ne demektir bunu bakalım.<br>“mutable” kelime olarak <em>“değişken”</em>, “immutable” ise zıttı olarak <em>“sabit,değişken olmayan”</em> anlamına gelir. “mutable” infrastructure dediğimizde configurasyon ve diğer değişikliklere her zaman açık olan tradational sistemleri örnek verebiliriz. Düşündüğümüzde bir traditional bir sistemi kurduğumuzda, daha sonra bu sistem üzerinde SSH ile bağlanarak yazılım paketlerinde güncellemeler, environment eklemeler vb. gibi işlemleri tek tek yapıyorduk. Açıkçası çoğu yerde durum hala böyle. Bu yüzden bu sistemlere değişken yani <strong>“mutable infrastructure”</strong> diyoruz. Ayrıca böyle bir ortamda bir grup server kümesi için yaptığımız işlemler aynı da olsa sonuç olarak bazı server lar birbirinden tamamen farklı, benzersiz olabiliyor. Bu teşhis edilmesi ve yeniden oluşturulması zor ince konfigürasyonla hatalarına “<strong>configuration drift”</strong> deniyor.</p><p>Diğer yandan <strong>“immutable infrastructure”; </strong>Terraform, CloudFormation<strong> </strong>gibi toollar tarafından VM veya container image ı gibi hazır yapılar kullanılarak oluşturulur. Docker, VMware gibi tool lar yardımıyla oluşturulmuş bu hazır image ler kurulacak altyapının gerekli tüm konfigürsayonlarını içerir. Böylece kurulum sonrasında infrastructure üzerinde büyük konfigürasyon değişiklikliklerine ihtiyaç duyulmaz. Eğer infrastructure da büyük konfigürasyonlarına değişikliklerine ihtiyaç duyulursa yeni image ler oluşturulur ve best practice olarak image ler bir source control(örneğin Git) sayesinde versiyonlanır. Serverlar oluşturulan yeni image ile tekrardan boot edilir ve eski olanlar terminate edilir. Böylece <em>“configuration drift” </em>durumu ortadan kalkar, yapılan değişiklikler daha güvenilir olur. Bu süreç yine de biraz yavaştır.</p><p>Mutable ve immutable infrastructure kavramları arasında tek bir doğru olmasa da, bu iki altyapı türünün getiri ve götürüleri birbirinden farklıdır. Konuyla alakalı daha fazla detaylı bilgiye ulaşmak isterseniz <a href="https://medium.com/@adhorn/immutable-infrastructure-21f6613e7a23"><strong>buradaki</strong></a> yazıya bakmanızı mutlaka tavsiye ederim.</p><p><strong><em>→ Declarative-Imperative(Procedural) Code</em></strong></p><p>Diğer kavramlardan ikisi ise<strong> “declarative”</strong> ve <strong>“imperative(procedural)”</strong> kavramları… IaC yaklaşımında her şeyden önce uygun araç seçimi çok önemlidir. Sizin için uygun olan aracı ise yetkinliklerinize, amaçlarınıza ve bu aracın kullandığı dilin özelliğine göre seçmelisiniz. Aksi halde hedeflenilen amaçlara ulaşılamayabilir veya bu yolda zorluklar çekebilirsiniz. Bu yüzden bu iki kavram tool seçiminde yardımcı olacaktır.</p><p>Kısaca <em>“declarative” </em>yaklaşımda, ne ihtiyacımız olduğunu tüm detaylarıyla listeleyerek code execution sonrasında elimizde ne olması gerektiğini kullandığımız aracın dilinde kodlayarak belirtiriz. Bunu yaparken ise aracın bu işi nasıl yapabileceğini kullandığımız araca söylememize gerek yoktur. Bir nevi “ne gerekli” sorusunun cevabını veriyoruz. <em>“imperative” </em>(bazen <em>“procedural” </em>olarak da bahsedilir.) yaklaşımda ise gerekli olan kaynakların nasıl oluşturulacağını kodlayarak belirtmiş oluruz. Burada da “nasıl yapılmalı” sorusuna cevap vermiş oluyoruz.</p><p>Ufak bir örnek ile bu iki kavramı daha iyi anlayabiliriz. Örneğin, masanızda bu yazıyı okurken bir kahve içmek istediniz. Bunu <em>“declarative” ve “imperative” </em>yaklaşımlarla nasıl ifade edersiniz…? Böyle bir durumu <em>“declarative”</em> yaklaşımla ifade etmek için:</p><blockquote>“ Ozan’ın ‘IaC Dünyası-1: Terraform&#39; başlıklı Medium yazısını okurken flat white kahvemi masama alabilir miyim?” şeklinde belirtmeniz declarative yaklaşım için yeterlidir. Kafedeki garson birazdan kahvenizi masanıza getirecektir :)</blockquote><p>Imperative(procedural) yaklaşımla ise bu durumu şöyle ifade edebilirdik:</p><blockquote>“ Ozan’ın ‘IaC Dünyası-1: Terraform’ başlıklı Medium yazısını okurken flat white kahve içmek istiyorum. Bunu yapabilmen için şunları yapmalısın: 40ml double espressoyu hazırla, 80ml sütü ısıt krema haline getir, krema sütü yavaşça double espresso üzerine dök. Masaya getir.” şeklinde belirtmeniz imperative(procedural) yaklaşım için gereklidir. Kafedeki garson birazdan kahvenizi masanıza getirecektir. :)</blockquote><p>Son olarak aşağıdaki resim üzerinden declarative-imperative yaklaşmını anlayabiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*dizyZUfLwRUBJg4nxCpS5w.png" /><figcaption>Source: <a href="https://www.copebit.ch/how-declarative-and-imperative-styles-differ-in-infrastructure-as-code/">https://www.copebit.ch/how-declarative-and-imperative-styles-differ-in-infrastructure-as-code/</a></figcaption></figure><p>Yine “mutable-immutable” konusunda olduğu gibi burada da “net bir doğru” yoktur. Bazen “declarative” olarak bazen ise “imperative(procedural)” olarak altyapınızı tanımlamak sizin için daha iyi olabilir. Her iki yaklaşımı da kullanan farklı toollar bulunmaktadır. Hatta bazen bu toolları beraber bile kullanıyoruz. Buna case inize göre siz karar vermelisiniz. Sonuç olarak o kahve her türlü geliyor yani :)</p><p><strong><em>→ Configuration Management Tools — Provisioning Tools</em></strong></p><p>Son olarak da bu iki farklı araç kategorisinin anlamlandırılmasına bakalım. IaC dünyasında kullanılan araçlar genel olarak <em>“Configuration Management Tools” ve “Provisioning Tools”</em> olarak ikiye ayrılır.</p><p><em>“Configuration Management Tools”,</em> <strong>var olan infrastructure üzerinde </strong>konfigürasyonlar yapmaya yönelik tasarlanmış araçlardır. Bu araçlar ile yapabileceğimiz işlerden bazıları: OS üzerinde kullanıcıları tanımlamak, servislerin durumunu değiştirmek(start-stop-restart), yazılımı ortamı için paketleri kurmak, güncellemek vb… Bunlara örnek olarak:</p><ul><li>Chef</li><li>Puppet</li><li>Ansible</li><li>SaltStack</li></ul><p>gibi araçları verebiliriz.</p><p><em>“Provisining Tools”</em> ise <strong>planlanılan infrastructure ınızı oluşturan </strong>öğeleri(VM, database servers, load balancers, VPC, subnet, firewall etc.) hazırlayan araçların tümünü bu kategoriye dahil edebiliriz. Bu araçlar genellikle provider ların (VMware,AWS,k8s etc.) API larına call yaparak gerekli infrastructure ı oluştururlar. Bunlara örnek olarak:</p><ul><li>Terraform</li><li>CloudFormation</li><li>OpenStack Heat</li></ul><p>Buraya kadar olan tüm başlıkların özetini ve daha fazlasını aşağıdaki resimde görebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xndAfaCENqYVxglTk7hrg.png" /></figure><p>Yukarıdaki tabloda da görebileceğiniz gibi, birçok tool alternatifi bulunmaktadır. Bunların hangisinin kullanılması gerektiği ise tamamen size kalmış. Gerekli olan değerlendirmeyi her açıdan yapıp ona göre karar vermelisiniz. Ortak olan düşüncelerden birisi ise işin en zor ve önemli kısmının burası olduğuyla alakalı… Doğru araç seçimi… Ayrıca, IaC dünyasında bilinmesi faydalı olabilecek başka kavramlar da bulunmaktadır. Fakat bu yazının daha fazla uzamaması için onları diğer yazılarda sizlere açıklamayı daha doğru buldum.</p><p>Şimdi son zamanlarda öğrenmeye çalıştığım <strong>“Terraform”</strong> nedir ona bakalım…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBr-dbpoLl-XkoyJdQX4dg.png" /></figure><h4>Kısa bir giriş…</h4><p>Terraform, initial release olarak 28 Temmuz 2014 yılında Hashicorp şirketi tarafından yayımlanmıştır. Open source bir tool olmasıyla beraber “Terraform Enterprise” versiyonu da mevcuttur. “Go” dili ile yazılmıştır. En basit haliyle ne iş yaptığından bahsedecek olursak, sizin için var olan veya yeni oluşturacağınız infrastructure yapılarınızı declerative kod olarak tanımlayarak bu kod üzerinde değişikler yapmanıza ve yaptığınız değişiklikleri de ortam türünüze göre( test/prod vb.) tag lenmesini sağlar. Burada kod olarak bahsettiğimiz, HashiCorp şirketi tarafından geliştirilmiş, okunması, yazılması ve anlaşılması oldukça kolay olan “<a href="https://www.terraform.io/docs/configuration/syntax.html"><strong>HCL</strong></a>(<em>Hashicorp Configuration Language)</em> dir. HCL, ayrıca HashiCorp şirketinin diğer ürünlerinde de kullanılan bir syntax. Tabii ki bu size aktarabileceğim en basit tanımlardan biri.</p><h4>Bana göre, neden Terraform?</h4><p>Terraform bakıldığında, birçok DevOps tool uyla entegre çalışmasının yanı sıra trend alanlardan olan SDN(Software-Defined-Networking), multi cloud yapılarının kurulması gibi farklı birçok farklı alanlarda mission-critic görevleri yüksek güvenilirlikle yerine getirmek , gereksiz iş yükünden kurtulmak için tercih edilen bir tooldur. Kendi adıma, IaC dünyasında belirgin bir özelliğinden dolayı kullanmaya zorunlu kaldığım spesifik bir tool henüz olmadı. Fakat IaC yaklaşımını öğrenmeye neden Terraform gibi bir provisioning tool u ile başladığımdan biraz bahsetmek isterim. Bu nedenleri kısaca söyle sıralayabilirim:</p><ul><li>Terraform’un yazıldığı dil olan HCL, bana anlaşılabilir-human readable gelmişti.</li><li>Ayrıca bundan daha da önemlisi, Terraform çok çeşitli ve sayıda provider ile entegre olabiliyordu.</li><li>Dökümantasyonları bana gayet anlaşılır ve basit geldi. Detaylı dökümantasyon sayfasını ise<strong> </strong><a href="https://www.terraform.io/docs/index.html"><strong>buradan</strong></a> görebilirsiniz.</li><li>Sorunsuz şekilde infrastructure üzerinde değişiklik sağlayarak immutable infrastructure oluşturması</li><li>Çok sayıda provider ile çalışabilmesi. Terraform’un çalışabildiği tüm providerların listesini <a href="https://registry.terraform.io/browse/providers"><strong>buradan</strong></a><strong> </strong>görebilirsiniz.</li></ul><p>Tüm bu nedenlerden ötürü öğrenmeye Terraform ile başladım.</p><h4>Terraform Core Consepts</h4><p>Terraform içinde bilmemiz gereken birkaç konsept var. Bu konseptlere göre infrastructure ımızı yaratacak olan kodu yazıyoruz. Bu kısmı açıklarken aşağıdaki Github repository imi kullanıyor olucam. İsteğinize göre göz atabilirsiniz:</p><p><a href="https://github.com/oziie/my-terraform-labs/">oziie/my-terraform-labs</a></p><p>Bu konseptler aşağıdaki gibidir:</p><ul><li><strong>Variables</strong></li></ul><p>Terraform içerisinde kullandığımız inputları ifade eder. İsteğimize göre tanımladığımız variables, her türlü özelleştirmeyi yapmamızı sağlayan key-value şeklindeki yapılardır. Terraform’da bunları <strong><em>“variables.tf”</em></strong> gibi bir dosyada saklayabiliriz. Örneğin, ext_port, storage adı, container adı vb. Aşağıda Terraform’da “int_port” ve “ext_port” değişkenlerinin Terraform’da main code u tanımladığımız yer olan <strong><em>“main.tf”</em></strong> dosyasında nasıl kullanıldığına dair bir örnek görebilirsiniz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c670cd1ed35f6137a3478fbbbebcd150/href">https://medium.com/media/c670cd1ed35f6137a3478fbbbebcd150/href</a></iframe><p>Ayrıca yukarıdaki code örneğinde “dev” ve “prod” olarak 2 farklı şekilde bir variable’ın değerini verebiliyoruz. Hangisini kullanacağımızı nasıl söylediğimizi ise yazının ilerleyen kısımlarında inceleyeceğiz.</p><p><em>Ufak bir not: “$” sembolü ile aslında farklı bir değeri çağırıyormuşuz gibi düşünebiliriz. Buna “Interpolation syntax” denir ve Terraform’da sıkça kullanılan bir durumdur. Daha fazla detaylı bilgiye </em><a href="https://www.terraform.io/docs/configuration/expressions.html"><strong><em>buradan</em></strong></a><em> ulaşabilirsiniz.</em></p><ul><li><strong>Provider</strong></li></ul><p>Terraform’un servisleri kullanmak için yaptığı API call larını gerçekleştirmesini sağlayan pluginler diyebiliriz. Bu pluginler sayesinde aslında istediğimiz servisler ile iletişime geçerek buralarda infrastructure ımızı oluşturuyoruz. “Provider” a örnek olarak Docker, Vmware veya AWS gibi cloud servislerini verebiliriz. Daha önce de bahsettiğim gibi Terraform’un çalışabildiği tüm provider ları <a href="https://www.terraform.io/docs/providers/index.html"><strong>buradan</strong></a> görebilirsiniz.</p><ul><li><strong>Modules</strong></li></ul><p>Infrastructure ın tanımlandığı Terraform dosyalarının hiyerarşik olarak oluşturulduğu klasör yapılarını ifade eder. Böylece Terraform’da code tekrarı olmadan konfigürasyonları tekrar tekrar çağırarak kullanabilirsiniz.Terraform’daki kodunuzu efektif olarak kullanmanın, kodunuzu test etmenin ve modüler bir infrastructure yaratmanın en iyi yolu “modules” yapısını kullanmaktır.</p><p>Default olarak aslında her bir Terraform konfigürasyonu “Root Module” olarak adlandırılan bir module içerisinde tanımlanır. Bunu aşağıdaki gibi düşünebiliriz:</p><pre>root-module <em>(Tabii bu şekilde adlandırma gibi bir zorunluluğumuz yok.)</em><br> └ main.tf<br> └ outputs.tf<br> └ variables.tf</pre><p>Terraform’da birçok farklı amaçla module oluşturabiliriz. Örneğin staging ve production environmentları için ayrı modüller oluşturabiliriz. Başka bir örnek olarak Docker provider ı ile çalışırken “image” ve “container” gibi modüller tanımlayarak bunları bir root module içerisinde çağırabiliriz. Aşağıdaki örnekte de bunu görüyoruz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36430cfe86e34dec17aaec1c3d3b7621/href">https://medium.com/media/36430cfe86e34dec17aaec1c3d3b7621/href</a></iframe><p>Aşağıdaki linkten dosya hiyerarşisini görerek daha iyi anlayabilirsiniz:</p><p><a href="https://github.com/oziie/my-terraform-labs/tree/master/docker/basics/modules">oziie/my-terraform-labs</a></p><ul><li><strong>State</strong></li></ul><p>Terraform tarafından yönetilen altyapı ve ilgili konfigürasyonlar hakkında önbelleğe alınmış bilgileri içerir. Terraform’un çalışma mantığını açıklayacağım bir sonraki başlıkta <strong><em>“Terraform Core”</em></strong> adında bir bileşen göreceğiz. “Terraform Core” infrastructure ın güncel son halini bir state üzerinde tutarak kodunuzu bir sonraki çalıştırışınızda eğer infrastructure konfigürasyonlarınız üzerinde bir değişiklik(ekleme,silme, güncelleme vs.) varsa bunu uygular. Eğer yok ise infrastructure ınız olduğu şekliyle kalır. Ayrıca manuel olarak infrastructure ınızı değiştirmeniz durumda, Terraform bir sonraki çalıştırmada state ti referans alarak, infrastructure ı buradaki haline göre yeniden düzenler. Böylece <strong><em>“immutable infrastructure”</em></strong> sağlanmış olur.</p><ul><li><strong>Resources</strong></li></ul><p>Infrastructure ı oluşturan, configure ettiğimiz objeleri(VM, container, DNS records, sanal ağlar etc.) tanımlar. Aslında resource lar bloklar şeklinde tanımlanır ve her blok bir veya birden fazla obje içerebilir. Her resource birçok farklı özelliği sahip olabilir fakat sadece ufak bir kısmı ilk kullanım (initial use) için yeterlidir. Örneğin AWS üzerinde bir instance yaratacaksak bunu aşağıdaki gibi yapabiliyoruz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d27bba9d80318ebcf9274a4930ef55f7/href">https://medium.com/media/d27bba9d80318ebcf9274a4930ef55f7/href</a></iframe><ul><li><strong>Outputs</strong></li></ul><p>Bir module içerisinde Terraform’un diğer Terraform modülleri tarafından da kullanılabilen dönüş değerleridir. Aşağıdaki örnekle daha iyi anlayabiliriz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556ebf125cb48355262a52130970b19e/href">https://medium.com/media/556ebf125cb48355262a52130970b19e/href</a></iframe><h4>Terraform Çalışma Prensibi</h4><p>Terraform kullanarak infrastructure oluşturmak istediğimizde konfigürasyon dosyalarımız temelde 4 aşamadan geçer ve bunun sonucunda infrastructure ımız hazır gelir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lefj8YHn8U6hh167w9wjdw.jpeg" /><figcaption>Source: <a href="https://www.ovh.com/blog/private_cloud_and_hashicorp_terraform_part1/">https://www.ovh.com/blog/private_cloud_and_hashicorp_terraform_part1/</a></figcaption></figure><ul><li><strong>Init → </strong>Workspace üzerindeki tüm Terraform dosyalarını initialize eder.</li><li><strong>Plan → </strong>Infrastructure ın<strong> </strong>istenen bir durumuna ulaşmak için bir execution plan oluşturulur. Bazen konfigürasyon dosyalarında değişiklikler yapılır veya farklı ortamlar için(dev veya prod) farklı parametreler ile plan oluşturulabilir. Böyle bir durumda “Plan” adımı tekrar yapılır ve farklı planlara sahip olunur.</li><li><strong>Apply → </strong>İstenilen durumu elde etmek için infrastructure ın gerçek / mevcut durumundaki değişiklikleri uyguladığı aşamalardan biridir. Apply bir Terraform “Plan” üzerinden yapılır. Bu aşamadan sonra elimizde arzu edilen infrastructure a sahip oluyoruz.</li><li><strong>Destroy → “</strong>Apply” aşamasından sonra, terminate edilmesi gerekli olan tüm eski altyapı kaynaklarını silmek için kullanılır.</li></ul><p>Terraform’un mimarisine baktığımızda yukarıda bashedilen tüm adımlar aslında “Terraform Core” adı verilen bileşen tarafından “terraform init”, “terraform plan”, “terraform apply”, “terraform destroy” gibi komutlar ile CLI üzerinden yapılır. Hatırlarsanız yazının yukariki kısımlarında bunu “state” i tutan bir yapı olarak görmüştük. Aşağıdaki Terraform mimarisi diyagramıyla Terraform’un adım adım nasıl çalıştığına bakalım:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*5GMPEJ1DGC3HPlpD8iatAw.png" /><figcaption>Source: <a href="https://geekflare.com/terraform-for-beginners/">https://geekflare.com/terraform-for-beginners/</a></figcaption></figure><p>İlk olarak <em>“Terraform Core”</em> sizin oluşturduğunuz konfigürasyon dosyalarını işler. Böylece ikinci adımda, <em>“Terraform Core”, “Terraform State” </em>i update ederek infrastructure ın istenilen güncel şeklinin state etmesini sağlar. Daha sonrasında ise yapılması gereken ne ise(güncelleme, ekleme, silme) infrastructure üzerinde bunları belirleyerek uygular. Bunları yaparken, tabii ki yukari kısımda bahsettiğimiz 4 aşamayı (init-plan-apply-destroy) duruma göre gerçekleştirir. Sonuç olarak da elimizde hangi provider ile çalışıyorsak onun üzerinde bir infrastructure objesi oluşmuş olur.</p><p>Son olarak tamamlayıcı nitelikte olan şağıdaki videoyu izleyebilirsiniz. HashiCorp Co-Founder’ı Armon Dadgar, Terraformu gayet basit ve anlaşılır anlatıyor. Böylece kafanızda eksik kalan yerleri tamamlayabilirsiniz.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fh970ZBgKINg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dh970ZBgKINg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fh970ZBgKINg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/890bb2b2d27f0dad7948bac120d694a9/href">https://medium.com/media/890bb2b2d27f0dad7948bac120d694a9/href</a></iframe><h4>Terraform ile Docker Container Provisioning</h4><p>Bu kısımda Terraform’un provider larından biri olan Docker ile basic bir örnek göstermiş olacağım.</p><p><strong><em>Önemli Not! → </em></strong><em>Bu yazıyı yazarken Terraform v0.11.13 ile çalıştım. Bu versiyon eski bir Terraform versiyonu. Github repositroyimdeki syntax yazımında güncel versiyon ile farklılıklar olabilir. Bu yüzden sizin denemelerinizde eğer farklı bir sürüm kullanıyorsanız hatalar alabilirsiniz. Gerekli açıklamayı </em><a href="https://www.terraform.io/upgrade-guides/0-13.html"><strong><em>burada</em></strong></a><em> ve </em><a href="https://github.com/hashicorp/terraform/blob/guide-v0.13-beta/draft-upgrade-guide.md#explicit-provider-source-locations"><strong><em>burada </em></strong></a><em>bulabilirsiniz. Ayrıca “interpolation syntax deprecated” hatalarına çözüm olarak </em><a href="https://stackoverflow.com/questions/59038537/fix-interpolation-only-expressions-are-deprecated-warning-in-terraform#:~:text=Template%20interpolation%20syntax%20is%20still,of%20a%20single%20interpolation%20sequence."><strong><em>buraya da</em></strong></a><strong> </strong>bakabilirsiniz<em>. Repository içeriğini zaman zaman güncelliyor olacağım. Anlayışınız için teşekkür ederim…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*U4z2hovLRsbS95KLK7Cwyg.png" /></figure><p>Öncelikle, eğer ortamınızda Terraform yüklü değil ise aşağıdaki adımları izleyerek kolayca yükleyebilirsiniz:</p><ul><li><a href="https://www.terraform.io/downloads.html"><strong>Buradan</strong></a><strong> </strong>tercih ettiğiniz ortam türüne göre en son release dosyasını kurmak için indirebilirsiniz. Ben Linux ortamını tercih ettim. Windows, MacOS gibi ortamlara da kurabilirsiniz:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hl49uix9yBn_j9VDrbfTfA.png" /></figure><ul><li>Daha sonra indirilen dosyayı unzip ederek çıkan binary dosyasını <em>“/usr/local/bin”</em> altına atmalıyız:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*9qLTpVri1wS8vx6H2c6T0w.png" /></figure><ul><li>Artık Terraform’u kullanmaya hazırız. Aşağıdaki gibi test edebilirsiniz:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*F7bm2Uy_SpwhNnlU_t-JmA.png" /></figure><ul><li>Demo için aşağıdaki Github repostory imi (<em>docker →basics) </em>kullanıyor olacağım:</li></ul><p><a href="https://github.com/oziie/my-terraform-labs">oziie/my-terraform-labs</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*f9ywrYYictx_xYJ7_qKynA.png" /></figure><p><strong>Senaryomuz şu şekilde olacak:</strong> <em>“Prod” </em>ve “<em>Dev”</em> adında iki farklı ortamımız için farklı özelliklere sahip containerlar oluşturucağız. Bunu yaparken tabiki farklı Terraform planları oluşturup, apply edeceğiz. Detayları diğer adımlarda belirtmeye çalışıcam. Aşağıda bunun için kullanılan dosyaları görebilirsiniz:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38cabbbc87a98f7cb7cb7c5e5f29c42a/href">https://medium.com/media/38cabbbc87a98f7cb7cb7c5e5f29c42a/href</a></iframe><p>Biraz yukarıdaki koddan bahsetmek istersek şunları söyleyebiliriz:</p><p>→ İki farklı ortam için farklı external portlar kullanacağız. <em>“dev”</em> ortamı için 8081 ve <em>“prod” </em>ortamı için ise 80 portunu kullanıyor olacağız. Kullandığımız internal port ise her iki ortam için de aynı olacak.<br> → Aynı şekilde <em>“dev” </em>ortamı için <em>“ghost:latest”,</em> <em>“prod”</em> ortamı için <em>“ghost:alpine”</em> imajını kullanıyor olacağız.<br> → Ayrıca “container_name”, “image_name” gibi değişkenler de ortam türüne göre değişiyor olacak.</p><p>Aslında incelediğinizde tüm bu özellikler <em>“variables.tf” </em>altında <em>“map” </em>türünde değişken tanımlanarak yapılmıştır.</p><ul><li>Öncelikle ilgili klasöre giderek ilk komutumuz olan “terraform init” komutunu çalıştıracağız. Böylece Terraform artık burada çalışıyor olduğumuzu bilmiş olacak.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*djQzwcBdyPf7r8T-tHoikg.png" /></figure><ul><li>Daha sonrasında ilk olarak <strong>“dev”</strong> ortamı için planımızı oluşturabiliriz. Bunu yapmak için terraform plan -out=tfdev_plan -var env=dev komutunu çalıştırmalıyız. Burada -var env=dev olarak daha önce Terraform konfigürasyonu içerisinde tanımlanmamış fakat gerekli olan bir değişkeni input olarak veriyoruz. Bunu oluşturalacak plan için, destroy edilecek resourcelar için her seferinde yapmamız gerekiyor.<em>(Terraform version 0.11.3 için). </em>Gördüğünüz gibi Terraform bizim için oluşturulacak resource ları tanımladı:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*qzqUjqaOqPfgK4bkgXAZ-Q.png" /></figure><ul><li>Gördüğünüz gibi <strong><em>“tfdev_plan”</em></strong> adında bir plan oluşturmuş olduk. Şimdi bu oluşturduğumuz planı uygulayabiliriz. Aşağıdaki resimde gördüğünüz gibi planlanan tüm resourcelar Terraform tarafından bizim için oluşturulmuş oldu. Ayrıca en altta <strong>“Outputs”</strong> altında daha önce <em>“outputs.tf” </em>dosyasında tanımlandığımız değişken çıktılarını görebiliriz:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9IDiWfeHNwLzDWPKe4a1Vw.png" /></figure><ul><li>Docker üzerinde kontrol ettiğimizde container’ın oluştuğunu görebiliyoruz. Terraform’da konfigure ettiğimiz gibi “dev” ortamı için “8081” portunu external port olarak kullandık ve bu port internal olarak 2368&#39;e map ediliyor. Container ımız ayağa kalktığında <em>“dev” </em>ortamı için “IP:8081” şeklinde, <em>“prod”</em> için “IP:80” yazılarak örnek Ghost Blog sayfasına ulaşılabilir:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7EUCxUAhOAfSve73vbUy0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63Cwuee33U2WcG-ZmX4phQ.png" /></figure><ul><li>Daha sonrasında diğer ortamımızı oluşturmak için <em>“dev” </em>ortamını destory edebiliriz veya direk olarak yeni <em>“prod” </em>planımızı oluştururak Terraform’un infrastructure ı buna göre yeniden modifiye etmesini sağlayabiliriz. Ben burada daha graceful olarak destroy etmeyi tercih ediyorum. Bunu yapmak için aşağıdaki komutu çalıştırmalıyız:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vdVzQ7icNhmpH9Xf7l2fRQ.png" /></figure><ul><li>Bu aşamada elimizde yine fresh bir ortam var. Yani önceki <em>“dev”</em> ortamı resourcelarını sildik. Şimdi <em>“prod”</em> ortamı için bir plan oluşturalım:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*Ku_dOXE57FHHXwhfG4eQWQ.png" /></figure><ul><li>Oluşturduğumuz bu planı aynı şekilde aşağıdaki gibi apply edebiliriz:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ByGTyLdlaLotmSr1mkkTDQ.png" /></figure><ul><li>Aşağıda da görüldüğü gibi containerımız oluşmuş olacak:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6kntp6OkWUaRjduBjyt7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVQJdQGMvHoUXk2Z_myrTA.png" /></figure><ul><li>İşimiz bittikten sonra bu ortamı da istersek kaldırabiliriz. Bunu yine terraform destroy komutuyla yapacağız fakat bu sefer -auto-approve flag i vererek bizden onay beklemeden direk silmesini sağlayabiliriz.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFNYHdDLydK9N5k22k9Ocw.png" /></figure><p>Bu yazının burada sonuna geldik. Terraform ile Kubernetes, Docker vb. providerlar ile nasıl çalışacabileceğimizin farklı örneklerini diğer yazılarda inceleyeceğiz.</p><p>Bir sonraki yazıda görüşmek üzere !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*f8WsoSzAyvzCuuMp3fd_Fg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d7cafda1c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/iac-d%C3%BCnyas%C4%B1-1-terraform-101-15d7cafda1c1">IaC Dünyası-1: Terraform 101</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Something Missed? : History of Container Technology]]></title>
            <link>https://oziie.medium.com/something-missed-history-of-container-technology-e978f202464a?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e978f202464a</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containerization]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Tue, 31 Mar 2020 21:51:52 GMT</pubDate>
            <atom:updated>2020-03-31T21:51:52.303Z</atom:updated>
            <content:encoded><![CDATA[<h3>Something Missed? : History of Container Technology</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vookZpZi3c6S4mchfVNQDQ.jpeg" /></figure><p>Nowadays, many applications and the environments where these applications are located have started to evolve quickly in accordance with the container architecture. When we look at it from a large frame, this technology which is in all other sectors, especially in the IT sector, has become a trend in the meeting process that started especially with Docker. When this is the case, it has become important to understand where today’s features of Docker come from. Knowing the history and development processes of this technology, it is possible to understand what we expect, to combine the missing parts, to see how the technologies we use today have evolved to their current state, or to develop new tools by adding them when necessary. Here is the history of “Container Architecture”…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*khj1aWOfs0W80edeXp-I8Q.png" /><figcaption>Source: <a href="https://www.plesk.com/wp-content/uploads/2016/12/conteinerization_plesk_infographic.png">https://www.plesk.com/wp-content/uploads/2016/12/conteinerization_plesk_infographic.png</a></figcaption></figure><p>As you can easily see from the diagram above, container technology has undergone many evolution. Let’s examine them in order:</p><h3>&gt; Chroot(UnixV7) — 1979</h3><p>Everything was actually a cloud of dust… “chroot” was introduced and added to UNIX systems. Thus, unique positions were created in the file system for processes and the first steps were taken for process isolation. With this technology, it was possible to isolate one process and its subprocesses from all other systems. To do this, the libraries to be used would be moved under a separate “root directory” and run under this folder. Thus, you could do whatever you want by acting as root in this specified environment without affecting the global system. However, root processes could easily leave the chromed environment. So it was a little lacking technology. In March 1982, Bill Joy put the chroot on Unix v7.0. You can better understand by looking at the simple picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*HsAy-lMNZXrZznizzBJjTA.gif" /><figcaption>chroot — Source: <a href="http://www.jmcresearch.com/src/articlehelper.php?action=print&amp;id=3">http://www.jmcresearch.com/src/articlehelper.php?action=print&amp;id=3</a></figcaption></figure><h3>&gt; Jail — 1990</h3><p>In the 1990s, security and network expert Bill Cheswick was researching how crackers could gain access by entering a computer system. He tried to solve how crackers reached their goals by creating a chroot environment that follows the key traces of crackers to do their research and follow them. Thus, the technology we call jail was created. In addition to the capabilities of the chroot, Jail created and used his own filesystem. You can often see the term “chrooted jail” or “chroot jail” as the term.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*HsAy-lMNZXrZznizzBJjTA.gif" /><figcaption>chroot jail — Source: <a href="https://linuxhill.wordpress.com/2014/08/09/014-setting-up-a-chroot-jail-in-crunchbang-11debian-wheezy/">https://linuxhill.wordpress.com/2014/08/09/014-setting-up-a-chroot-jail-in-crunchbang-11debian-wheezy</a></figcaption></figure><h3>&gt; FreeBSD Jails — 2000</h3><p>It is the technology created by adding chroot to Free BSD systems and adding a few extra features. Although it is largely similar to chroot; The file system made a difference by isolating users and the network and creating environments for custom applications. Moreover, thanks to these features, security has been further enhanced on this technology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*UPFZ3yjR3KG47D13EIt4JQ.jpeg" /><figcaption>FreeBSD Jails — <a href="https://www.adminbyaccident.com/virtualization/freebsd-jails/">https://www.adminbyaccident.com/virtualization/freebsd-jails/</a></figcaption></figure><h3>&gt; Linux vServer — 2001</h3><p>Linux vServer was introduced in 2001, with operating system level virutalization features available in Linux kernel. Linux vServer uses the same features of chroot and in addition CPU time, memory, network addresses, etc. is a technology that can safely partition resources on the system. Each partition is called “security partition” and the virtualized system in it is called “virtual private server”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*AxHpsBUl0Grk8CCuzXxsmA.png" /><figcaption>Linux vServer</figcaption></figure><h3>&gt; Oracle Solaris Containers — 2004</h3><p>Oracle Solaris Containers has started to be used to divide system resources, limit their use and divide them into areas. In addition, thanks to Oracle Solaris Containers, cloning and snapshot features have been introduced over ZFS (ZetaByte Filesystem). The concept of “zone” is used to define resource limitations. With zones, you can access operating system resources or filesystem for application. However, the application can only see what is happening in its region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*bGK-Tby4fS_u_KQv_b80_Q.png" /><figcaption>Oracle — <a href="https://www.g2.com/products/solaris-zones/reviews">https://www.g2.com/products/solaris-zones/reviews</a></figcaption></figure><h3>&gt; OpenVZ(Open Virtuozzo) — 2005</h3><p>OpenVZ uses OS-level virtualizing, similar to Linux vSever. Since it uses OS-level virtualization, there are some restrictions. Since the containers share the same architecture and kernel version, this creates a disadvantage if the host needs another kernel version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*vHZMP1qobX9ymm14eGJ-YQ.png" /><figcaption>OpenVZ</figcaption></figure><h3>&gt; Google Containers — 2006 / Cgroups — 2007</h3><p>In 2006, Google engineers announced “process containers” that they designed and developed for the isolation and limitation of resources (CPU, RAM, network, I / O etc.). In 2007, this definition of “process containers” was renamed “cgroup(control groups)”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkPZZS4ttok6gOrfTasv2w.jpeg" /><figcaption>Google Containers</figcaption></figure><blockquote>Let’s open a parenthesis for “cgroups” here and examine it a little more deeply…</blockquote><p>Different definitions can be made for Cgroups. For example “control groups”, “subsystems” or “resource controller” etc.… The important thing here is that we understand what we are doing. Cgroups control a process’s access to resources, isolate it, and limit it. This subject is really detailed and, as far as I can see, is a bit difficult to understand. It may be a completely different article. But we can briefly say:</p><p>Cgroups came with Linux kernel v2.624 and Linux kernel v3.0 was announced as Cgroups v2. We shouldn’t think of Cgroups as a single structure. As you can see below, it is included in more than one cgroup Linux kernel. All of them have different tasks and in order to use them, it is necessary to examine in more detail. For now, let’s just look at what some of them do:</p><p><strong>blkio:</strong> This cgroup is used to limit the amount of I / O for each process group.<br><strong>CPU:</strong> This cgroup monitors the usage rates of the CPU, determines the usage weights and limits the access to the CPU resource.<br><strong>cpuacct:</strong> This cgroup generates automatic reports on CPU usage of a process or process group.<br><strong>cpuset:</strong> This cgroup takes over the task of fixing a CPU to a process or process groups.<br><strong>devices:</strong> This cgroup is used to allow or restrict access of a task to the device. This means … With this cgroup, you can set permissions for any process, such as writing and reading, on a device.<br><strong>freezer:</strong> This allows cgroup process to be suspend or resume.<br><strong>memory:</strong> This cgroup allows us to keep track of how much memory a process is using. It also creates automatic reporting accordingly.<br><strong>net_cls:</strong> This cgroup tags the network packets with “classid”, which enables the identification of packets originating from a specific process group task. This means that traffic control can be configured to assign different packages to different priorities. We can think of it as a kind of QoS (Ouality of Service).<br><strong>net_prio:</strong> This cgroup provides a way to dynamically set the priority of network traffic for each network unit.<br>In order to be useful, I leave the links that I find nice about the subject below:</p><p><a href="https://sysadmincasts.com/episodes/14-introduction-to-linux-control-groups-cgroups">Introduction to Linux Control Groups (Cgroups)</a></p><p><a href="https://events.static.linuxfound.org/sites/events/files/slides/cgroup_and_namespaces.pdf">https://events.static.linuxfound.org/sites/events/files/slides/cgroup_and_namespaces.pdf</a></p><h3>&gt; LXC(Linux Containers) — 2008</h3><p>In 2008, the first version of LXC (Linuxc Containers) was introduced. LXC; We can say similar to OpenVZ, Solaris Conatiners and Linux VServer. However, LXC already uses cgroups already in the Linux kernel. LXC is “operating system level (OS-Level Virtualization)” virtualization, which enables running multiple isolated Linux environments (containers) in a common Linux kernel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*vVlIyfvXvC_d7uZPfWyj1w.png" /><figcaption>LXC — Linux Containers</figcaption></figure><h3>&gt; CloudFoundry Warden — 2011</h3><p>Warden is an API technology used by CloudFoundry to manage isolated, temporary-rebuild, resource-controlled environments created in 2011. It used the LXC infrastructure in his early days and later developed its own implantation. It developed a client-server model to manage container and container groups. It also has a service to manage cgroups, namespace and process life cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlKUKFOZklQDQVfakPMv9Q.png" /><figcaption>Cloud Foundry</figcaption></figure><h3>&gt; Google Let Me Contain For You(LMCTFY) — 2013</h3><p>In 2013, Google once again changed the open source container technology history. This technology, which came out as an open source in Google’s container technologies, provided Linux application containers. Applications running in this architecture could be designed as “container aware” and gained the ability to manage by creating their own subcontainers. LMCTFY runs applications by isolating them on the same Linux Kernel and using “cgroups”, “namespaces”, and other Linux Kernel processes. The development of this technology was officially stopped in 2015. But after that, Google started to contribute by transferring the core principles of LMCTFY to “libcontainer”. Accordingly, it also contributed to Docker. Libcontainer is now part of the Open Container Initiative (OCI).<br><em>(P.S. libcontainer informations can be found in the Docker section.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkPZZS4ttok6gOrfTasv2w.jpeg" /><figcaption>Google — LMCTFY</figcaption></figure><h3>&gt; Docker — 2013</h3><p>Docker was introduced in 2013 by an San Francisco company that offers PaaS cloud services named dotCloud as an open-source project, and its founder is Solomon Hykes. When it first came out, it aimed to convert monolitich applications into image and container structure by using LXC (Linux containers). Later on, it started to develop his own container runtime, libcontainer, and after this stage, libcontainer was started to be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*mWmukdEnJ_GZEzbkeZXk0Q.png" /><figcaption>Docker</figcaption></figure><p>By the way, let’s talk about <strong>“libcontainer”…</strong></p><p><strong>Libcontainer</strong> is a library written by <strong>Docker</strong> in Go and C / C ++ languages. The purpose of writing was to create a broader isolation technology, to create a container using features such as <strong>cgroup, namespaces</strong> already in the Linux Kernel, and to give full control over the lifecycle of this container. It was supported by the<strong> OCI (Open Container Initiative)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsONXSTMlJknvrkiKF0bxA.png" /><figcaption>Docker Drivers</figcaption></figure><p>Since the first versions of <strong>Libcontainer</strong> Docker (first Docker March 0.9–2014), it has been connected to <strong>Docker Engine</strong>. But later on, Docker developed a driver-library called <strong>runC</strong>, completely independent of Docker Engine, and included libcontainer. The aim of such a development was the efforts of containers to use a common driver and to achieve standardization. <strong>RunC</strong> was also supported by the <strong>OCI (Open Container Initiative)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*LRzIHXsmI4MwhFO8Y3q5Pw.png" /><figcaption>Libcontainer in runC repo</figcaption></figure><p>As I mentioned earlier, actors developing container technologies (Docker, Redhat, Vmware, Oracle, AWS etc.) have always tried to achieve standardization. So, how are we last by looking at Docker ..?</p><p>Finally, after giving the <strong>runC</strong> project it developed to OCI, Docker started using containerd since <strong>2016</strong>. Meanwhile, <strong>runC OCI started to be used as a standard runtime</strong>. <strong>Containerd</strong> <strong>works like an interface for runC, which runs low-level</strong>. It also has control over other OCI runtimes. Containerd uses runC to run containers, but it also provides other top-level features such as image management and high-level APIs. At the final point,<strong> with the adoption of Docker, containerd is the industry standard for the implementation of OCI. It is currently available for Linux and Windows.</strong></p><blockquote>You can see the runtime you have as a “Default runtime:” parameter using the command on the network:</blockquote><pre>docker info| grep -i runtime</pre><blockquote>In general, we should understand well here: As can be seen, Docker did not stop using existing projects completely. This is not the case. Over time, only other projects have been replaced by existing projects and new projects have been produced by making improvements to the existing ones. Although it is a little difficult to understand and follow the changes, relationships and differences between the projects, the parts settle down in time.</blockquote><p>To better understand the latest situation, we can see the high-low level runtime that Docker has today by looking at the following images:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1VhJqrkALM14gUHmMKI8Q.png" /><figcaption>Source: <a href="https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5">https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnOjBgas7NBNUqQgImxumQ.png" /><figcaption>Source: <a href="https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5">https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5</a></figcaption></figure><blockquote>To simplify, we can summarize all this as follows:</blockquote><ul><li><strong>LXC</strong> was used in the first versions of Docker. Later on, it started using themby making <strong>libcontainer, runC and containerd </strong>respectively.</li><li>In versions prior to Docker 1.11.0, Docker was a monolith, and all jobs were run by Docker Engine. At the new point we have reached today, Docker is basically divided into 4 parts and the tasks of these parts are as follows:</li></ul><p>1-<strong> Docker Engine → </strong>Creating containers over images and transferring their control over containerd.</p><p>2- <strong><em>containerd → </em></strong>It is responsible for areas such as managing containers’ life-cycle, Image push-pull, storage control, network management, namespace management and so on. It also has control over OCI runtime and runC. Today, it can be used in both Linux and Windows environments as an OCI standard.</p><p>3- <strong><em>runC → </em></strong>It can actually be seen as part of containerd. runC is a runtime that packs applications running in low level according to OCI format and can be implemented in these environments. When we want to configure the container, we do this with bundles. A bundle consists of a “config.json” file containing some config and a root filesystem.</p><p>4- <strong><em>conrainerd-shim→ </em></strong>It provides container operation by using runC. It also provides a “Daemonless container” environment. This means that there is no need for a long-running runtime process for containers. There are 2 benefits of running a Daemonless container container:</p><ol><li><em>runC</em> stops after container starts and and it doesn’t have to work during the working container process.</li><li><em>containerd-shim;</em> It keeps file information such as stdin (standard input), stdout (standard output), stderr (standard error), even if Docker or containerd becomes inoperable for any reason.</li></ol><p><strong>Let’s solve the confusion a little more … </strong>When we look at it, there are many runtime definitions in our story. For example, although <strong>containerd</strong> and <strong>runC</strong> are both runtime, <strong>why did Docker do something to separate them? Couldn’t it use one for the other? Our answer is actually simple: runtime are divided into high-level and low-level. Each runtime has its own unique features and uses. As we call low-level, lightweight, like runC, should come to mind a runtime that works fast and in harmony with high-level runtime. In order to standardize the container ecosystem, low-level runtime only allows running containers.</strong></p><p>When we say <strong>high-level</strong>, we can talk about <strong>“containerd”</strong>. We can better understand the Runtime levels with the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*yVq80WZV04ADnVVLBbs0pA.png" /><figcaption>Source: <a href="https://www.ianlewis.org/en/container-runtimes-part-1-introduction-container-r">https://www.ianlewis.org/en/container-runtimes-part-1-introduction-container-r</a></figcaption></figure><p>If desired, other runtime that are OCI standard or not can be used instead of any runtime. It all depends on the prons and cons, what is expected. To do this, the following command should be run on Docker:</p><pre>sudo dockerd --add-runtime=&lt;runtime-name&gt;=&lt;runtime-path&gt;</pre><p>For example:</p><pre>sudo apt-get install nvidia-container-runtime<br>sudo dockerd --add-runtime=nvidia=/usr/bin/nvidia-container-runtime</pre><p>Also, if you want to know more, you can take a look at:</p><ul><li><a href="http://alexander.holbreich.org/docker-components-explained/">Docker components explained</a></li><li><a href="https://stackoverflow.com/questions/41645665/how-containerd-compares-to-runc">How containerd compares to runC</a></li><li><a href="https://stackoverflow.com/questions/34152365/difference-between-lxc-and-libcontainer">Difference between LXC and libcontainer</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FVWuHWfEB6ro%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVWuHWfEB6ro&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FVWuHWfEB6ro%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/63e3ffb7d86c64f34528fa7b93081b60/href">https://medium.com/media/63e3ffb7d86c64f34528fa7b93081b60/href</a></iframe><p>When we look at the history of containers in general, we can say that the popularization and rapid development of containers has been achieved thanks to Docker. Thanks to the new features and environment it provides, Docker has assumed the leadership position among container technologies.</p><h3>&gt; Rocket — 2014</h3><p>Rkt is a secure and lightweight Docker alternative container system developed by CoreOS. It is built on a container standard known as “App Container” or “appc”. For this reason, rkt images can be run on container systems that support the “appc” format. It can be examined in more detail <a href="https://coreos.com/rkt/docs/latest/devel/architecture.html"><strong>here</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*RawoOZ8VDHU5BmDK3eldXg.png" /><figcaption>Rocket (rkt)</figcaption></figure><p><strong>So what are the differences from other container technologies?</strong></p><p><strong><em>→ It is designed to be much more suitable for production systems with security in the foreground:</em></strong></p><p>As it is known, containers are process groups that can be created by granting some rights to users on the system or by processing with root. In addition, the operation of a user in one container is not seen by the other container. Users are safe in this way as long as there is no abuse on the Linux kernel. <strong>However, </strong>in some systems such as Docker, malicious users who can get out of the container through an abuse on the kernel can ruin everything. Such a risk exists despite measures.</p><p><strong>Unlike Docker, rkt runs containers with un-privileged users (unlike priority… Unlike Docker…). Thus, even if there is a kernel level deficit and the user can get out of the container, this does not affect other containers and users.</strong></p><p>In addition, rkt allows cryptographic signature control over downloaded images. As a result, only reliable containers can run on the server.</p><p><strong><em>→ It has a lightweight structure suitable for packaging applications:</em></strong></p><p>It packs the imaged applications more effectively and makes them executable.</p><p><strong><em>→ Portable image format… Image structure that can be easily moved to other container systems:</em></strong></p><p>In rapidly developing container technology, it uses the <strong>“appc”</strong> format, which makes it easier to move images to a better container technology in the future. Thus, all kinds of images actually become an image that can be run for rkt.</p><p><strong><em>→ Manageable features… Different features from different sources:</em></strong></p><p>According to the work done, the features needed in one container system may not be needed in another. In such a situation, Docker has some problems. The first is that this large application developed by a provider is likely to have bugs. The second is the possibility that the features in Docker remain limited depending on the perspective of the provider that developed the system. In such a case, alternatives such as rkt will always have more features. Because different providers can develop this system by adding additions to modify different features themselves.<strong>This is an advantage of rkt with “pluggable architecture”. For example,</strong> <strong>rkt can enable “Intel Clear Container”</strong> support or enable a feature on the VMware that will provide hardware-level isolation. In this way, features suitable for the work to be done are provided. In addition, the risk of vulnerabilities is also reduced.</p><h3>&gt; Windows Containers — 2016</h3><p>In 2015, Microsoft attempted to develop windows-based applications for Windows Server and called this container technology Microsoft Containers. With the latest developments in 2016, Microsoft announced the overall availability of Docker containers on Windows Server 2016, so that Docker Engine containers became native to Windows.</p><p>With this application, Docker has been able to run Docker containers for Microsoft without having to install a virtual machine to run Docker. There are also many additional features and components on Azure that can run Docker containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*YeijAQ7UWGaK-eO1ZZn1dw.png" /><figcaption>Microsoft Containers</figcaption></figure><p>The following sources can be examined to have more information:</p><ul><li><a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/">About Windows containers</a></li><li><a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/">Containers on Windows Documentation</a></li><li><a href="https://www.docker.com/blog/build-your-first-docker-windows-server-container/">Build and Run Your First Docker Windows Server Container | Docker Blog</a></li></ul><h3>&gt; What’s Next: Podman and Buildah</h3><p>If you remember, we have seen that some runtime can work like this by explaining the concept of “daemonless” in Docker related article. <strong>However, Docker works as a native connected to a daemon (docker daemon-dockerd). </strong>Its job is to transmit all basic operations to the sub-units with the commands it receives over CLI and to make sure that they are done. If the daemon does not work somehow, it means that you cannot perform basic operations. We can better understand this from the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*8mO-B3r23f5xBneqkFQMHQ.png" /><figcaption>Docker Architecture</figcaption></figure><p>When we look at this architecture, we see places that will cause a few problems. A few of them are as follows:</p><ul><li>At the point where no news is received from Daemon, there will be no access to the processes.</li><li>All Docker operations are performed by one or more users with the same root privileges. This could create a vulnerability.</li></ul><p>Podman, a new container platform that has eliminated these risks, has been developed. <strong>Podman works with the “runC” we mentioned earlier so it works in accordance with the “daemonless” concept.</strong></p><p>In addition, Podman image creation, etc. it does not look at having a user’s root privilege for transactions. <strong>To do this, it uses namespaces in the Linux kernel.</strong> <strong>Namespace is a kernel feature that briefly controls the access of resources running on Linux to resources.</strong> <strong>So how does Podman use namespaces?</strong> Namespaces do UID / GID mapping for users. The UID / GID range defined for a non-privileged user is kept on the host. The user with root privilege in the container can use the privileges required to create an image by mapping it to the namespace (UID / GID = 0). Also, since this user’s privileges are defined and limited on the host, the root user in the container can actually only use certain commands (eg build command). Thus, a security vulnerability that may arise due to the container on the host is prevented.</p><p>In addition, when using Podman, build, stop etc. used in Docker. CLI commands can be used exactly. Podman commands are available to non-root users. For this, there is a repo under the directory <strong>“<em>~/.local /share / containers”.</em></strong></p><pre>docker images --&gt; podman images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y61_COOOit5V92Y5pTTFEw.png" /><figcaption>Podman</figcaption></figure><p>For more information, I recommend you to review the link below:</p><ul><li><a href="https://blog.giantswarm.io/building-container-images-with-podman-and-buildah/">Building Container Images with Podman and Buildah</a></li><li><a href="https://servicesblog.redhat.com/2019/10/09/say-hello-to-buildah-podman-and-skopeo/">Say &quot;Hello&quot; to Buildah, Podman, and Skopeo</a></li><li><a href="https://github.com/containers/libpod">containers/libpod</a></li></ul><h4>What’s the Buildah?</h4><p><strong>Buildah</strong> is a common containerize tool for container systems that comply with the <strong>OCI (Open Container Initiative)</strong> standards and <strong>is actually one of the reasons for its development, and perhaps the most important is its power in building container images. In addition, it also has many different commands and thus gives freedom, which makes it powerful.</strong> So, why is this tool really necessary? Docker and Podman can also build. We can explain the difference between them and their relationship with Podman as follows …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*fRFZyX4JwBSFF1fR7V8Vwg.png" /><figcaption>Buildah</figcaption></figure><p>As you know, we can build images with Dockerfile. It has features that make it possible to use Bash script in addition to Dockerfile while building Buildah images. It is possible to do this just like Dockerfile writer. In this way, you can also convert and use your scripted works with Buildah.</p><p>It is much more sensitive and powerful, as it has many different commands for creating and managing container images. The build commands in Podman are actually a subset of Buildah commands and they use the same codes.</p><pre>buildah bud -t hello</pre><p>It is possible to produce a new image by making changes on the existing container with Buildah.</p><pre>With &quot;buildah mount&quot; or &quot;buildah config&quot; commands</pre><p>Buildah can also produce images as scratches. This means producing an image that is completely hallow. If we look inside, we will see a completely empty folder. It is possible to do this with the following command:</p><pre>buildah run from scratch</pre><p>Flags such as port mapping and volume mounting are not used for the “run” command on the buildah command set. For this, if we want to make a change, we need to give Linux commands with the command “buildah run”. For example:</p><pre>buildah run dnf -y install nginx</pre><p>Buildah also works as rootless and daemonless.</p><p><strong>You can have CLI uses, examples and more information from the link below:</strong></p><ul><li><a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/building_running_and_managing_containers/building-container-images-with-buildah_building-running-and-managing-containers">Chapter 6. Building container images with Buildah Red Hat Enterprise Linux 8 | Red Hat Customer Portal</a></li><li><a href="https://github.com/containers/buildah">GitHub - containers/buildah: A tool that facilitates building OCI images.</a></li></ul><h4><strong><em>That’s all about containers for now…</em></strong></h4><p>See you in next stories… <br>Goodbye..!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e978f202464a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kaçırdığımız Birşeyler mi Var? : Container Mimarisi Tarihi]]></title>
            <link>https://medium.com/devopsturkiye/ka%C3%A7%C4%B1rd%C4%B1%C4%9F%C4%B1m%C4%B1z-bir%C5%9Feyler-mi-var-container-mimarisi-tarihi-2a270aa86029?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a270aa86029</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 18:45:56 GMT</pubDate>
            <atom:updated>2022-02-27T22:29:31.124Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kaçırdığımız Birşeyler mi Var? : Container Mimarisi Tarihi</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vookZpZi3c6S4mchfVNQDQ.jpeg" /></figure><p>Günümüzde baktığımızda artık birçok uygulama ve bu uygulamaların çalıştığı ortamlar hızlı bir şekilde container mimarisine uygun olarak evrimleşmeye başladı. Özellikle Docker ile birlikte başlayan tanışma sürecinde, büyük çerçeveden baktığımızda başta IT sektörü olmak üzere diğer tüm sektörlerde olan bu teknoloji bugün trend haline geldi. Durum böyle olunca da örneğin Docker’ın sahip olduğu bugünkü özelliklerinin nerelerden geldiğini anlamış olmak önemli hale geldi. Bu teknolojinin geçmişini bilerek ve gelişme sürecine hakim olarak neler beklediğimizi anlayabilmek, eksik kalan parçaları birleştirmek, bugün kullandığımız teknolojilerinin nasıl bugünkü haline evrimleştiğini görebilmek veya gerektiğinde bunların üzerine katarak yeni araçlar geliştirmek mümkündür. İşte “Container Mimarisi” tarihi…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*khj1aWOfs0W80edeXp-I8Q.png" /><figcaption>Source: <a href="https://www.plesk.com/wp-content/uploads/2016/12/conteinerization_plesk_infographic.png">https://www.plesk.com/wp-content/uploads/2016/12/conteinerization_plesk_infographic.png</a></figcaption></figure><p>Yukarıdaki şemadan da rahatlıkla görebileceğiniz gibi container teknolojisi birçok evrim geçirmiş. Şimdi sırayla bunları inceleyelim:</p><h3>&gt; <strong>Chroot(UnixV7) - 1979</strong></h3><p>Herşey aslında bir toz bulutuydu… “chroot” tanıtıldı ve UNIX sistemlere eklendi. Böylece prosesler için dosya sisteminde özgün konumlar oluşturuldu ve proses izolasyonu için ilk adımlar atılmış oldu. Bu teknoloji ile birlikte bir process ve onun alt proseslerini diğer tüm sistemden izole etmek mümkündü. Bunu yapabilmek için kullanılacak kütüphaneler ayrı bir “root directory” altına taşınır ve bu klasör altında çalışırdı. Böylece global sistem etkilenmeden, bu belirlenen ortamda root gibi davranarak istediğinizi yapabilirdiniz. Bununla beraber root process leri kolayca chroot yapılmış ortamdan çıkabiliyordu. Bu nedenle biraz eksik kalmış bir teknolojiydi. Mart 1982&#39;de Bill Joy chroot u Unix v7.0&#39; a koymuştur. Aşağıdaki basit resme bakarak daha iyi anlayabilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*HsAy-lMNZXrZznizzBJjTA.gif" /><figcaption>chroot — Source: <a href="http://www.jmcresearch.com/src/articlehelper.php?action=print&amp;id=3">http://www.jmcresearch.com/src/articlehelper.php?action=print&amp;id=3</a></figcaption></figure><p><strong>chroot </strong>ile ilgili bir örneği, yazının uzamaması açısından farklı bir story de göstereceğim.</p><h3>&gt; <strong>Jail - 1990</strong></h3><p>1990&#39;lara geldiğimizde Bill Cheswick ismindeki güvenlik ve network uzmanı <strong>cracker</strong> ların bir bilgisayar sistemine girerek nasıl yetki kazanabildiği üzerine araştırmalar yapıyordu. Araştırmalarını yapmak ve onları takip etmek üzere cracker ların tuş izlerini takip eden bir chroot ortam oluşturup burayı nasıl modifiye ederek amaçlarına ulaştıklarını çözmeye çalıştı. Böylece jail dediğimiz teknoloji oluşturulmuş oldu. Jail, chroot un yeteneklerine ek olarak kendi filesystem ini oluşturuyor ve kullanıyordu. Çoğu zaman terim olarak “chrooted jail” veya “chroot jail” olarak kullanıldığını görebilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*NKo8ZNyHeeigblHs5D86vA.gif" /><figcaption>chroot jail — Source: <a href="https://linuxhill.wordpress.com/2014/08/09/014-setting-up-a-chroot-jail-in-crunchbang-11debian-wheezy/">https://linuxhill.wordpress.com/2014/08/09/014-setting-up-a-chroot-jail-in-crunchbang-11debian-wheezy</a></figcaption></figure><h3>&gt; <strong>FreeBSD Jails - 2000</strong></h3><p>Free BSD sistemlerine chroot un eklenmesi ve birkaç ekstra özellik kazandırılmasıyla oluşturulmuş teknolojidir. Büyük oranda chroot a benzemesine rağmen; file sistemi,kullanıcıları ve network ü izole etmesiyle ve custom uygulamalar için ortamlar oluşturabilmesiyle fark yaratmıştır. Ayrıca bu özellikler sayesinde güvenlik bu teknoloji üzerinde daha da arttrılmış oldu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*UPFZ3yjR3KG47D13EIt4JQ.jpeg" /><figcaption>FreeBSD Jails - <a href="https://www.adminbyaccident.com/virtualization/freebsd-jails/">https://www.adminbyaccident.com/virtualization/freebsd-jails/</a></figcaption></figure><h3>&gt; <strong>Linux vServer — 2001</strong></h3><p>İşletim sistemi seviyesinde sanallaştırma(operating system level virutalization) özelliklerinin Linux kernel ında kullanılabilmesiyle beraber 2001 yılında chroot un aynı özelliklerini kullanan ve ek olarak CPU time,memory,network adresleri vb. sistem üzerindeki kaynakları güvenli şekilde bölümlendirebilen <strong>Linux vServer </strong>tanıtıldı. Her bölüme “security partition” denir ve içindeki sanallaştırılmış sistem “virtual private server” olarak adlandırılır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*AxHpsBUl0Grk8CCuzXxsmA.png" /><figcaption>Linux vServer</figcaption></figure><h3>&gt; <strong>Oracle Solaris Containers - 2004</strong></h3><p>Sistem kaynaklarını bölmek, kullanımını sınırlandırmak ve alanlara ayrılması işlevleri kullanılmaya başlanmıştır. Bununla beraber <strong>Oracle Solaris Containers</strong> sayesinde ZFS(ZetaByte Filesystem) üzerinden klonlama ve snapshot özellikleri kullanılmaya başlanmıştır. Kaynak sınırlamalarını tanımlamak için “zone” kavramı kullanılmıştır. Zone lar ile uygulama için işletim sistemi kaynaklarına, filesystem a erişim sağlayabilirsiniz. Ancak, uygulama yalnızca kendi bölgesinde neler olduğunu görebilir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*bGK-Tby4fS_u_KQv_b80_Q.png" /><figcaption>Oracle - <a href="https://www.g2.com/products/solaris-zones/reviews">https://www.g2.com/products/solaris-zones/reviews</a></figcaption></figure><h3>&gt; <strong>OpenVZ(Open Virtuozzo) - 2005</strong></h3><p>OpenVZ, Linux vSever a benzer şekilde OS-level virtualizing kullanır. OS-level virtualization kullandığı için burada bazı kısıtlamalar oluşmaktadır. Containerlar aynı mimarityi ve kernel versiyonunu paylaştığı için eğer host başka bir kernel versiyonuna ihtiyaç duyarsa bu bir dezavantaj oluşturmaktadır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*vHZMP1qobX9ymm14eGJ-YQ.png" /><figcaption>OpenVZ</figcaption></figure><h3><strong>&gt; Google Containers - 2006 / Cgroups - 2007</strong></h3><p>Google mühendisleri 2006 yılında kendilerinin kaynakların(CPU, RAM, network, I/O vb.) izolasyonu ve limitlenmesi için tasarlayıp geliştirdikleri <strong>“process containers”</strong> duyurdu. 2007 yılında bu “process containers” tanımı adı “control groups” tan gelen <strong>“cgroup” </strong>olarak tekrar isimlendirildi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkPZZS4ttok6gOrfTasv2w.jpeg" /><figcaption>Google Containers</figcaption></figure><blockquote>Burada <strong>“cgroups” için bir parantez açalım ve biraz daha derinlemesine inceleyelim</strong>…</blockquote><p>Cgroups için farklı tanımlamalar yapılabilir. Örneğin “control groups”,“subsystems” veya “resource controller” vb… Burada önemli olan bizim neyi yaptığını anlamamızdır. <strong>Cgroups bir process in kaynaklara olan erişimini kontrol eder, izolasyonunu sağlar ve limitler.</strong> Bu konu gerçekten detaylı ve gördüğüm kadarıyla anlaşılması biraz zor. Tamamıyla farklı bir yazı konusu olabilir. Fakat kısaca şunları söyleyebiliriz:</p><p>Cgroups Linux kernel v2.624 ile beraber geldi ve Cgroups v2 olarak Linux kernel v3.0 da duyuruldu. Cgroups u tek bir yapı olarak düşünmememiz gerekir. Aşağıda da görebileceğiniz gibi, birden fazla cgroup Linux kernel ı içerisinde yer almaktadır. Bunların hepsinin farklı görevleri vardır ve kullanabilmek için daha detaylı incelemek gerekir. Biz şimdilik sadece bazılarının ne işe yaradıklarına bakalım:</p><p><strong>blkio:</strong> Bu cgroup her bir işlem grubu için I/O miktarını ölçmek limitlemek için kullanılır.<br><strong>cpu: </strong>Bu cgroup CPU’nun kullanım oranlarını monitor etmek ve CPU için ağırlıkları belirleyerek processlerin CPU kaynağına erişimini limtler.<br><strong>cpuacct:</strong> Bu cgroup process veya process ler topluluğunun CPU kullanımıyla ilgili otomatik raporlar oluşturur.<br><strong>cpuset:</strong> Bu cgroup bir CPU’yu bir process veya process gruplarına sabitleme görevini üstlenir.<br><strong>devices:</strong> Bu cgroup bir görevin cihaza erişimini izin vermek veya kısıtlamak için kullanılır. Bu şu anlama geliyor… Bu cgroup ile herhangi bir process in bir cihaza yazma ve okuma gibi izinlerini ayarlayabilirsiniz.<br><strong>freezer:</strong> Bu cgroup process in suspend veya resume edilmesini sağlar.<br><strong>memory: </strong>Bu cgroup bir process in ne kadar bellek kullandığını takip etmemizi sağlar. Ayrıca buna bağlı olarak otomatik raporlamalar oluşturur.<br><strong>net_cls: </strong>Bu cgroup, ağ paketlerini belirli bir process group görevinden kaynaklanan paketlerin tanımlanmasını sağlayan <strong>“classid”</strong> ile etiketler. Bu, trafik kontrolünün farklı paketlere farklı önceliklere atayacak şekilde yapılandırılabileceği anlamına gelir. Bir nevi QoS(Ouality of Service) olarak düşünebiliriz.<br><strong>net_prio: </strong>Bu cgroup ağ trafiğinin önceliğini her ağ birimi için dinamik olarak ayarlamanın bir yolunu sunar.</p><p>Faydalı olması açısından konuyla ilgili güzel bulduğum linkleri aşağıya bırakıyorum:</p><p><a href="https://sysadmincasts.com/episodes/14-introduction-to-linux-control-groups-cgroups">Introduction to Linux Control Groups (Cgroups)</a></p><p><a href="https://events.static.linuxfound.org/sites/events/files/slides/cgroup_and_namespaces.pdf">https://events.static.linuxfound.org/sites/events/files/slides/cgroup_and_namespaces.pdf</a></p><h3><strong>&gt; LXC(Linux Containers) - 2008</strong></h3><p>2008 yılında LXC(Linuxc Containers) ilk versiyonu tanıtıldı. LXC; OpenVZ, Solaris Conatiners ve Linux VServer e benzer diyebiliriz. Ancak LXC, zaten halihazırda Linux kernel ında yer alan <strong>cgroups </strong>kullanmaktadır. LXC, ortak bir Linux kernal ında birden fazla izole edilmiş Linux ortamını(containers) çalıştırmayı sağlayan <strong>“işletim sistemi seviyesinde (OS-Level Virtualization) ”</strong> sanallaştırmadır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*vVlIyfvXvC_d7uZPfWyj1w.png" /><figcaption>LXC — Linux Containers</figcaption></figure><h3><strong>&gt; CloudFoundry Warden - 2011</strong></h3><p>Warden, CloudFoundry tarafından 2011 yılında oluşturulan izole edilmiş, geçici-tekrar oluşturulabilen, kaynak kontrolü sağlanabilen ortamları yönetmek için kullanılan bir API teknolojisidir. İlk zamanlarında LXC altyapısını kullanmış ve daha sonralarında ise kendi implemantasyonunu geliştirmiştir. Container ve container gruplarını yönetmek için bir “client-server” modeli geliştirmiştir. Ayrıca cgroups, namespace ve process life cycle yönetmek için bir servise sahiptir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlKUKFOZklQDQVfakPMv9Q.png" /><figcaption>Cloud Foundry</figcaption></figure><h3><strong>&gt; Google Let Me Contain For You(LMCTFY) - 2013</strong></h3><p>2013 yılında Google bir kez daha open source container teknoloji tarihini değiştirmiştir. Google’ın container teknolojilerinde open source olarak çıkan bu teknoloji, Linux uygulama container ları(Linux application containers) sağlıyordu. Bu mimaride çalışan uygulamalar “container aware” olarak tasarlanabildi ve kendi alt container yapılarını(subcontainers) oluşturarak yönetme kabilitiyetini kazandılar. LMCTFY, uygulamaları aynı Linux Kernel’de izole ederek ve “cgroups”, “namespaces”, ve diğer Linux Kernel işlemlerini kullanarak çalıştırır. Bu teknolojinin geliştirilme süreci 2015 yılında resmi olarak durduruldu. Fakat bundan sonra Google LMCTFY’nun core prensiplerini <strong>“libcontainer”</strong> a aktararak katkı vermeye başladı. Buna bağlı olarak aynı zamanda Docker’a da katkı vermiş olmaktadır. Libcontainer şuan <strong>Open Container Initiative (OCI)’in </strong>bir parçasıdır.<br><em>(P.S. </em><strong><em>libcontainer </em></strong><em>ile ilgili bilgiler Docker kısmında yer almaktadır.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkPZZS4ttok6gOrfTasv2w.jpeg" /><figcaption>Google — LMCTFY</figcaption></figure><h3>&gt; Docker - 2013</h3><p>Docker, 2013 yılında open-source bir proje olarak dotCloud isimli PaaS cloud hizmetleri sunan bir San Francisco firması tarafından tanıtıldı ve kurucusu Solomon Hykes’tı. İlk çıktığı zamanlarda <strong>LXC(Linux containers)</strong> kullanarak monolitich uygulamaları image ve container yapısına dönüştürmeyi hedeflemişti. Daha sonradan ise kendi container runtime ı olan <strong>libcontainer</strong> <strong>ı </strong>geliştirmeye başladı ve bu aşamadan sonra libcontainer kullanılmaya başlandı.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*w-15qCvRLqVvyo7upWy2fA.png" /><figcaption>Docker</figcaption></figure><p>Yeri gelmişken <strong>“libcontainer” </strong>dan da bahsedelim…</p><p><strong>Libcontainer,</strong> Go ve C/C++ dillerinde <strong><em>Docker </em></strong>tarafından yazılmış bir kütüphanedir . Yazılma amacı, daha geniş olarak bir izolasyon teknolojisi yaratmak, Linux Kernel’ında hali hazırda yer alan <strong>cgroup, namespaces vb. </strong>özellikleri kullanarak bir container oluşturmak ve oluşturulan bu container ın yaşam döngüsü üzerinde tam anlamıyla bir kontrol sağlamaktı. <strong>OCI(Open Container Initiative)</strong> tarafından desteklenmekteydi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsONXSTMlJknvrkiKF0bxA.png" /><figcaption>Docker Drivers</figcaption></figure><p><strong>Libcontainer</strong> Docker’ın ilk versiyonlarından itibaren<a href="https://www.docker.com/blog/docker-0-9-introducing-execution-drivers-and-libcontainer/">(ilk olarak Docker 0.9–2014 Mart)</a> <strong>Docker Engine’e </strong>bağlı olarak çalışmıştır. Fakat daha sonradan da Docker, Docker Engine’dan tamamen bağımsız olarak <strong>runC</strong> adında bir driver-kütüphane geliştirmiş ve libcontainer ı da içerisine katmıştır. Böyle bir geliştirilme yapılmasının amacı, container ların ortak bir driver kullanılması ve standartizasyonun yakalanması çabalarıydı. Ayrıca <strong>runC, OCI(Open Container Initiative)</strong> tarafından desteklenmekteydi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*LRzIHXsmI4MwhFO8Y3q5Pw.png" /><figcaption>Libcontainer in runC repo</figcaption></figure><p>Az önce de belirttiğim gibi container teknolojilerini geliştiren <a href="https://www.opencontainers.org/about/members">aktörler</a>(Docker, Redhat, Vmware, Oracle, AWS vb.) her zaman standartizasyonu yakalamaya çalıştılar. Peki Docker’a da bakarak en son ne durumdayız..?</p><p>Son olarak Docker geliştirdiği <strong>runC </strong>projesini OCI’ye verdikten sonra, <strong>2016 </strong>yılından itibaren <strong>containerd</strong> kullanmaya başladı. Bu sırada <strong>runC OCI standart runtime olarak kullanılmaya başlandı. </strong>Containerd low-level olarak çalışan runC için bir arayüz gibi çalışmaktadır. Ayrıca <strong>diğer OCI runtime ları üzerinde de kontrole sahiptir.</strong> Containerd containerları çalıştırmak için runC kullanır, ancak image ların yönetimi ve high-level API’ler gibi diğer üst düzey özellikleri de sağlar. Gelinen son noktada, Docker sayesinde benimsenmesiyle beraber,<strong> containerd, OCI’nin uygulanması için endüstri standardıdır. Şu anda Linux ve Windows için kullanılabilir durumdadır.</strong></p><blockquote>Sahip olduğunuz runtime ı ağıdaki komutu kullanarak “Default runtime:” parametresi olarak görebilirsiniz:</blockquote><pre>  docker info|grep -i runtime</pre><blockquote><strong>Genel olarak burada şunu iyi anlamalıyız: Görüldüğü gibi, Docker var olan projeleri tamamen kullanmayı bırakmadı. Böyle bir durum söz konusu değil. Sadece var olan projelerin, teknolojilerin yerini zamanla başka projeler aldı ve var olana geliştirmeler yapılarak yeni projeler üretildi. Projeler arasındaki değişimi, ilişkiyi ve farkları anlamak, takip etmek biraz zor olsa da zamanla parçalar yerine oturuyor.</strong></blockquote><p>Son durumu daha iyi anlamak için aşağıdaki görsellere bakarak Docker’ın bugün sahip olduğu high-low level runtime ları görebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1VhJqrkALM14gUHmMKI8Q.png" /><figcaption>Source: <a href="https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5">https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnOjBgas7NBNUqQgImxumQ.png" /><figcaption>Source: <a href="https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5">https://medium.com/faun/the-missing-introduction-to-containerization-de1fbb73efc5</a></figcaption></figure><blockquote>Basitleştirmek adına tüm bunları aşağıdaki gibi özetleyebiliriz :</blockquote><ul><li>Docker ilk versiyonlarında <strong>LXC</strong>, sonrasında sırayla <strong>libcontainer</strong>, <strong>runC</strong> ve <strong>containerd </strong>geliştirmeleri yaparak bunları kullanmaya başlamıştır.</li><li>Docker 1.11.0&#39;dan önceki versiyonlarda Docker monolith bir yapıdaydı ve tüm işler Docker Engine tarafından yürütülüyordu. Bugün geldiğimiz yeni noktada Docker temel olarak 4 parçaya ayrılmış ve bu parçaların görevleri sırayla şu şekilde çalışmaktadır:</li></ul><p>1- <strong><em>Docker Engine → </em></strong>Image lar üzerinden container yaratmak ve bunların kontrolünü containerd üzerine aktarmak.</p><p>2- <strong><em>containerd → </em></strong>Container ların life-cycle nı yönetmek ile görevlidir. Image push-pull, depolama kontrolü, network yönetimi, namespace yönetimi ve gibi alanlardan sorumludur. Ayrıca <strong>OCI runtime ları ve runC </strong>üzerinde kontrole sahiptir. Bugün gelinen noktada bir <strong>OCI standartı olarak hem Linux hem de Windows ortamlarda kullanılabilmektedir.</strong></p><p>3- <strong><em>runC →</em></strong> Aslında containerd nin bir parçası olarak da görülebilir. runC low level da çalışan uygulamaları <strong>OCI format</strong> ına göre paketleyen ve bu ortamlara implementasyonunu sağlayabilen bir runtime dır. Container ı yapılandırmak istediğimizde bunu paketler(bundle) ile yaparız. Bir bundle, içerisinde bazı configleri barındıran <strong>“config.json” </strong>dosyası ve bir root filesystem ından oluşur.</p><p>4- <strong><em>conrainerd-shim→</em></strong> runC’yi kullanarak container çalışıtırılmasını sağlar. Ayrıca “Daemonless container” ortamı sağlar. Bu şu anlama gelmektedir: Container lar için uzun zamanlı çalışan bir runtime process e ihtiyaç yoktur. Daemonless container container çalıştırmanın getirdiği 2 fayda vardır:</p><p><em>1. runC, </em>container başladıktan sonra başladıktan sonra durur ve çalışan container prosess i boyunca çalışmasına gerek kalmaz.<em><br>2. containerd-shim; </em>stdin(standart input), stdout(standart output), stderr(standart error) gibi file bilgilerini Docker veya containerd herhangi bir nedenle çalışmaz hale gelse dahi tutar.</p><p><strong>Kafa karışıklığını biraz daha giderelim…</strong> Baktığımızda hikayemizde birçok “runtime” tanımı var. Örneğin hala containerd ve runC nin ikisi de runtime olmasına rağmen Docker neden bunları ayırmak gibi birşey yaptı?Bakıldığında ikisi de runtime. Birini diğerinin yerine kullanamaz mıydı? <strong>Cevabımız aslında basit: Burada runtime lar high-level ve low-level olarak ayrılıyor.</strong> Her runtime ın kendine has özellikleri ve kullanım alanları mevcuttur. <strong>Low-level dediğimiz de “runC” gibi lightweight, hızlı ve high-level runtime lar ile uyum içerisinde çalışan bir runtime aklımıza gelmelidir. Container ekosistemini standart hale getirmek adına, low-level runtimelar sadece container ları çalıştırmaya izin verir.</strong></p><p><strong>High-level dediğimizde ise “containerd” den bahsedebiliriz. </strong>Runtime level larını aşağıdaki görsel ile daha iyi anlayabiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*MoSZTFr4lGUxODUjNdmVXw.png" /><figcaption>Source: <a href="https://www.ianlewis.org/en/container-runtimes-part-1-introduction-container-r">https://www.ianlewis.org/en/container-runtimes-part-1-introduction-container-r</a></figcaption></figure><p>Eğer istenirse herhangi bir runtime yerine OCI standartında olan veya olmayan başka runtime lar da kullanılabilir. Bu tamamen + ve - lere, neler beklenildiğine göre değişir. Bunu yapabilmek için Docker üzerinde aşağıdaki komut çalıştırılmalıdır:</p><pre>sudo dockerd --add-runtime=&lt;runtime-name&gt;=&lt;runtime-path&gt;</pre><p>Örneğin:</p><pre>sudo apt-get install nvidia-container-runtime<br>sudo dockerd --add-runtime=nvidia=/usr/bin/nvidia-container-runtime</pre><p>Ayrıca, aşağıdaki linklere bakarak daha fazla bilgiye sahip olabilirsiniz:</p><ul><li><a href="http://alexander.holbreich.org/docker-components-explained/">Docker components explained</a></li><li><a href="https://stackoverflow.com/questions/41645665/how-containerd-compares-to-runc">How containerd compares to runC</a></li><li><a href="https://stackoverflow.com/questions/34152365/difference-between-lxc-and-libcontainer">Difference between LXC and libcontainer</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FVWuHWfEB6ro%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVWuHWfEB6ro&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FVWuHWfEB6ro%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/da32abd58fb22a029118b1b964737dbe/href">https://medium.com/media/da32abd58fb22a029118b1b964737dbe/href</a></iframe><p>Genel olarak container tarihine baktığımızda, containerların popüler hale gelmesi ve hızla gelişimi Docker sayesinde olmuştur diyebiliriz. Docker getirdiği yeni özellikler ve sağladığı ortam sayesinde container teknolojileri arasında liderlik görevini üstlenmiştir.</p><h3>&gt; Rocket - 2014</h3><p>Rkt, CoreOS tarafından geliştirilen, secure ve lightweight bir Docker alternatifi bir container sistemidir. “App Container” veya “appc” olarak bilinen bir container standardı üzerine inşa edilmiştir. Bu sebeple rkt image ları “appc” formatını destekleyen container systemleri üzerinde çalıştırılabilir. <a href="https://coreos.com/rkt/docs/latest/devel/architecture.html">Buradan</a> daha detaylı incelenebilir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*RawoOZ8VDHU5BmDK3eldXg.png" /><figcaption>Rocket (rkt)</figcaption></figure><h4>Peki diğer container teknolojilerinden farkları nelerdir?</h4><p>→ <strong><em>Güvenlik ön planda olacak şekilde production sistemlere çok daha uygun olması için tasarlanmıştır:</em></strong></p><p>Bilindiği üzere container lar sistem üzerindeki kullanıcılara bazı haklar kazandırılarak veya root ile işlem yapılarak oluşturulabilinen process gruplarıdır. Ayrıca bir kullanıcının bir container içerisinde yaptığı işlem diğer container tarafından görülmez. Kullanıcılar Linux kernel ı üzerinde herhangi bir istismar olmadığı sürece bu şekilde güvendedir. <strong>Fakat,</strong> Docker gibi bazı sistemlerde kernel üzerindeki bir istismar üzerinden container dışına çıkabilecek art niyetli kullanıcılar herşeyi mahvedebilir. Böyle bir risk önlemlere rağmen söz konusudur.</p><p><strong>rkt</strong> <strong>ise Docker’dan farklı olarak container ları un-privileged kullanıcılar ile (öncelliğe sahip olmayan… Docker’ın aksine…) çalıştırır. Böylece kernel seviyesinde bir açık olsa ve kullanıcı container dışarısına çıkabilse dahi bu durum diğer container ları ve kullanıcıları etkilemez.</strong></p><p><strong>Ayrıca güvenlik adına rkt, indirilen image lar üzerinde cryptographic imza kontrolüne izin verir. Sonuç olarak, sadece güvenilir container lar server üzerinde çalışabilir.</strong></p><p>→ <strong><em>Uygulamaların paketlenmesi için uygun lightweight bir yapıya sahiptir:</em></strong></p><p>Image haline getirilen uygulamaları daha efektif olarak paketler ve çalıştırılabilir hale getirir.</p><p>→ <strong><em>Portable image formatı. Diğer container sistemlerine kolayca taşınabilen image yapısı:</em></strong></p><p>Hızla gelişen container teknolojisinde, ileride gelebilecek daha iyi bir container teknolojisine image ların taşınmasını daha kolay kılan <strong>“appc” formatını </strong>kullanır. Böylece her türlü image aslında <strong>rkt </strong>için çalıştırılabilen bir image haline gelmektedir.</p><p>→ <strong><em>Yönetilebilir özellikler… Farklı kaynaklardan, farklı özellikler:</em></strong></p><p>Yapılan işe göre bir container sisteminde ihtiyaç duyulan özellikler bir diğerinde aslında ihtiyaç duyulmayabilir. Böyle bir durum <strong>Docker bazı sorunlara sahiptir. Bunlardan birincisi,</strong> bir provider tarafından geliştirilen bu büyük uygulamanın bug lara sahip olması olasıdır. <strong>İkincisi ise, </strong>Docker içerisinde yer alan özelliklerin sistemi geliştiren provider ın bakış açısına bağlı olarak kısıtlı kalma olasılığı. Böyle bir durumda <strong>rkt </strong>gibi alternatifler her zaman daha fazla özelliğe sahip olacaktır. Çünkü farklı provider lar farklı özellikleri kendileri modifiye edecek şekilde eklemeler yaparak bu sistemi kendilerine göre geliştirebilir.Bu <strong>pluggable architecture özelliğine sahip olan rkt nin bir avantajıdır. </strong>Örneğin, <strong>rkt “Intel Clear Container”</strong> supportunu enable edebilir veya VMware üzerinde hardware seviyesinde izolasyonu sağlayacak bir özelliği enable edebilir. Böylece yapılacak işe uygun şekilde özellikler sağlanmış olur. Ayrıca, güvenlik açığı riski de daha aza indirilmiş olur.</p><h3>&gt; Windows Containers - 2016</h3><p>Microsoft 2015 yılında Windows Server için windows tabanlı uygulamaları geliştirmek için girişimde bulundu ve bu container teknolojisini <strong>Microsoft Containers </strong>olarak adlandırdı. 2016 yılındaki son gelişmelerle beraber Microsoft, Windows Server 2016 üzerinde Docker container larının genel kullanılabilirliğini duyurdu ve böylece Docker Engine containerları native olarak Windows üzerinde çalışabilir hale geldi.</p><p>Bu uygulama ile Docker, Docker’ı çalıştırmak için bir sanal makine kurmaya gerek kalmadan Docker containerlarını Microsoft için çalıştırabilir hale geldi. Ayrıca Azure üzerinde Docker container larını çalıştırabilecek ek bir çok özellik ve bileşen bulunmaktadır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*YeijAQ7UWGaK-eO1ZZn1dw.png" /><figcaption>Microsoft Containers</figcaption></figure><p>Daha fazla bilgiye sahip olmak için aşağıdaki kaynaklar incelenebilir:</p><ul><li><a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/index">About Windows containers</a></li><li><a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/">Containers on Windows Documentation</a></li><li><a href="https://www.docker.com/blog/build-your-first-docker-windows-server-container/">Build and Run Your First Docker Windows Server Container | Docker Blog</a></li></ul><h3>&gt; Sırada Ne Var?: Podman ve Buildah</h3><p>Hatırlarsanız yazının Docker ile ilgili kısmında “daemonless” kavramını açıklayarak bazı runtime ların böyle çalışabildiğini görmüştük.<strong> Fakat Docker native olarak bir daemon a(docker daemon-dockerd) bağlı olarak çalışır.</strong> Yaptığı iş ise CLI üzerinden aldığı komutlar ile tüm temel işlemleri alt birimlere iletmek ve yapıldığından emin olmak. Eğer daemon bir şekilde çalışmazsa bu temel işlemleri yapamayacağınız anlamına gelir. Aşağıdaki resimden bunu daha iyi anlayabiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*pebo5ZC35HDY6osrty5F8A.png" /><figcaption>Docker Architecture</figcaption></figure><p>Bu mimariye baktığımızda birkaç sorun teşkil edecek yerler görmekteyiz. Bunlardan birkaçı şöyledir:</p><ul><li>Daemon dan haber alınamadığı noktada, process lere erişim olamayacaktır.</li><li>Tüm Docker işlemleri bir veya bir den fazla kullanıcı tarafından aynı root yetkilerine sahip olarak yapılmaktadır. Bu da bir güvenlik açığı oluşturabilir.</li></ul><p>Bu riskleri elimine eden yeni bir container platformu olan <strong>Podman</strong> geliştirilmiştir. <strong>Podman daha önce de bahsettiğimiz “runC” ile çalışmaktadır ve böylece “daemonless” kavramına uygun olarak çalışır.</strong></p><p>Ayrıca Podman image yaratmak vb. işlemler için bir kullanıcının root privilige ına sahip olma kısmına bakmaz. Bunu yapabilmek için Linux kernel ında bulunan <strong>namespace</strong> leri kullanır. <strong>Namespace,</strong> kısaca Linux üzerindeki çalışan processlerin kaynaklara erişimini kontrol eden bir kernel özelliğidir. <strong>Peki Podman namespace leri nasıl kullanıyor? </strong>Namespace ler kullanıcılar için UID/GID mapping yapar. Host üzerinde non-privileged bir user için tanımlanan UID/GID aralığı tutulur. Container içerisindeki root privilege a sahip kullanıcının namespace (UID/GID=0) ile bunu eşleyerek image yaratmak için gerekli privilege ları kullanabilmiş olur. Ayrıca host üzerinde bu kullanıcının yetkileri tanımlı ve sınırlı olduğundan, container içerisindeki root kullanıcısı aslında sadece belli komutları(örneğin build komutu) kullanabilecektir. Böylece host üzerinde container sebebiyle çıkabilecek bir güvenlik açığı engellenmiş olur.</p><p>Ek olarak Podman i kullanırken Docker içerisinde kullanılan <strong>build, stop vb. CLI komutları aynen kullanılabilmektedir. Podman komutlarını root olmayan kullanıcılar kullunabiliyor. Bunun için </strong>“~/.local/share/containers” dizini altında bir repo bulunuyor.</p><pre>docker images --&gt; podman images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y61_COOOit5V92Y5pTTFEw.png" /><figcaption>Podman</figcaption></figure><p>Daha fazla bilgi için aşağıdaki linki incelemenizi tavsiye ederim:</p><ul><li><a href="https://blog.giantswarm.io/building-container-images-with-podman-and-buildah/">Building Container Images with Podman and Buildah</a></li><li><a href="https://servicesblog.redhat.com/2019/10/09/say-hello-to-buildah-podman-and-skopeo/">Say &quot;Hello&quot; to Buildah, Podman, and Skopeo</a></li><li><a href="https://github.com/containers/libpod">containers/libpod</a></li></ul><h4>Buildah Nedir?</h4><p><strong>Buildah,</strong> OCI(Open Container Initiative) standartlarına uygun olan container sistemleri için ortak bir containerize tooludur ve <strong>aslında geliştirilme sebeplerinden biri ve belki de en önemlisi container image larının build edilmesindeki gücüdür. Bunun yanında ayrıca birçok farklı özellikte command lere sahip olması ve böylece özgürlük kazandırması da onu güçlü kılar. </strong>Peki neden böyle gereksinime ihtiyaç duyulmuştur? Docker ve Podman de build işlemlerini yapabilmektedir. Aralarındaki farkı ve Podman ile ilişkisini şöyle açıklayabiliriz…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*fRFZyX4JwBSFF1fR7V8Vwg.png" /><figcaption>Buildah</figcaption></figure><p>Bildiğiniz gibi <strong>Dockerfile </strong>ile image build edebiliyoruz. Buildah image ları build ederken Dockerfile ın yanı sıra Bash script i kullanmayı da mümkün kılan özelliklere sahiptir. Aynı Dockerfile yazar gibi bunu yapmak mümkündür. Böylece birçok scripte bağlı işlerinizi de Buildah ile image haline getirebilir ve kullanabilirsiniz.</p><p>Container imageları oluşturma ve yönetme ile ilgili birçok farklı command a sahip olduğundan dolayı çok daha hassas ve güçlüdür. Podman içerisindeki build komutları aslında Buildah komutlarının bir alt kümesidir ve aynı kodları kullanmaktadırlar.</p><pre>buildah bud -t hello </pre><p>Var olan container üzerinde değişiklikler yaparak yeni bir image üretmek yine Buildah ile mümkündür.</p><pre>&quot;buildah mount&quot; veya &quot;buildah config&quot; komutları ile</pre><p>Buildah aynı zamanda scratch olarak image üretebilir. Bu tamamen içi boş olan image üretmek demektir. Eğer içerisine bakarsak tamamen boş bir klasör göreceğiz. Aşağıdaki komut ile bunu yapmak mümküdür:</p><pre>buildah run from scratch</pre><p>Buildah command set i üzerindeki “run” command i için port mapping, volume mounting gibi flagler kullanılmamaktadır. Bunun için eğer bir değişiklik yapmak istiyorsak Linux command lerini “buildah run” command i ile vermemiz gerekiyor. Örneğin:</p><pre>buildah run dnf -y install nginx</pre><p>Ayrıca Buildah, rootless ve daemonless olarak çalışmaktadır.</p><p><strong>Aşağıdaki linkten CLI kullanımlarına, örneklere ve daha fazla bilgiye sahip olabilirsiniz:</strong></p><ul><li><a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/building_running_and_managing_containers/building-container-images-with-buildah_building-running-and-managing-containers">Chapter 6. Building container images with Buildah Red Hat Enterprise Linux 8 | Red Hat Customer Portal</a></li><li><a href="https://github.com/containers/buildah">GitHub - containers/buildah: A tool that facilitates building OCI images.</a></li></ul><p><strong>Ek olarak DevOps Türkiye Medium hesabında Emre Özkan’ın Podman ve Buildah hakkındaki yazılarını mutlaka okumanızı tavsiye ederim. <br>Katkıların için teşekkürler Emre Abi :)</strong></p><ul><li><a href="https://medium.com/devopsturkiye/docker%C4%B1n-yerini-podman-m%C4%B1-al%C4%B1yor-podman-nedir-podman-kurulumu-41b2b69a5ae7">Docker’ın yerini Podman mı alıyor? Podman Nedir ? Podman Kurulumu</a></li><li><a href="https://medium.com/devopsturkiye/buildah-nedir-containerlar%C4%B1n%C4%B1z%C4%B1-buildah-ile-kolayca-olu%C5%9Fturun-4817b5746c4e">Buildah nedir? Container’larınızı Buildah ile kolayca oluşturun</a></li></ul><p><strong>Bir sonraki yazıda görüşmek üzere… Hoşçakalın…</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a270aa86029" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/ka%C3%A7%C4%B1rd%C4%B1%C4%9F%C4%B1m%C4%B1z-bir%C5%9Feyler-mi-var-container-mimarisi-tarihi-2a270aa86029">Kaçırdığımız Birşeyler mi Var? : Container Mimarisi Tarihi</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenStack_Serisi #2 — Temel ve İsteğe Bağlı Servisler]]></title>
            <link>https://medium.com/devopsturkiye/openstack-serisi-2-temel-ve-i%CC%87ste%C4%9Fe-ba%C4%9Fl%C4%B1-servisler-5bd5bafe2e5a?source=rss-ebf1e32e203a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd5bafe2e5a</guid>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[openstack]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ozan Eren]]></dc:creator>
            <pubDate>Sun, 21 Jul 2019 19:41:09 GMT</pubDate>
            <atom:updated>2019-07-21T19:41:09.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenStack_Serisi #2 — Temel ve İsteğe Bağlı Servisler</h3><p>Merhaba,uzun bir aradan sonra OpenStack serisinin 2.yazısıyla devam ediyoruz.Bir önceki yazıda OpenStack hakkında genel bilgiler ve kullanım alanlarıyla ilgili genel bilgileri sizinle paylaşmıştım:</p><p><a href="https://medium.com/devopsturkiye/openstack-serisi-1-nedir-42c448db30e4">OpenStack_Serisi #1-Nedir?</a></p><p>Bu yazıda ise OpenStack bileşenleri ve mimarisi üzerine bazı bilgileri sizinle paylaşmak istiyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NFF3_q1S3b2PjoiMveRPmw.png" /></figure><p>Diğer bulut sağlayıcılarında olduğu gibi OpenStack de bazı servis bileşenlerinden oluşan bir yapı.Bunlar bazıları “temel servisler” diğerleri ise “additional(ek,ilave) servisler” olarak adlandırabileceğimiz ekstra bileşenlerdir.Ayrıca tüm bu servisler Python dilinde yazılmıştır.</p><p>Temel servisler adından da anlaşılabileceği gibi diğer tüm servislerin onlarla konuşarak çalışabilmesi için gerekli olan bileşenlerdir.Yazının devamında bahsedeceğim bu servislerin kurulumları tek tek yapılabilir.Aslında ileriki kurulum yazılarında bahsedeceğim gibi temel servisleri işletim sistemine Packstack veya Devstack ile (yükleme için yönetim araçları olarak düşünebiliriz.Devstack Ubuntu,Packstack CentOS-RHEL gibi OS lar içindir.) toplu olarak kurabiliyoruz.</p><p>İsteğe bağlı bileşenler ise yine OpenStack toplulukları tarafından ihtiyaçlara göre yazılan bileşenlerdir.Bu bileşenleri ihtiyaçlarınıza ve projenize göre OpenStack üzerine kurabiliyoruz.</p><p>Aşağıdaki görselde bu servisler bir çoğu yer almaktadır:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-WZSzpF89S8r3enM0-DQQ.png" /><figcaption>OpenStack Core ve Optional Servisleri</figcaption></figure><p>Şimdi ise temel servisleri tanıyalım…</p><h3>- Temel Servisler</h3><p>OpenStack temel servisleri kendi aralarında aşağıdaki basit mimari resminde görünen gibi bir ilişkiye sahiptirler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Mw8qu5xpoKrXJehXKoLdvw.png" /><figcaption>OpenStack Temel Servisleri-Basit Mimari Gösterimi</figcaption></figure><p>Bu servisler kendi aralarında API’ler sayesinde konuşabilmekte ve çalışabilmektedir.Aşağıda daha detaylı olarak mimaride bunlar görülebilir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56yq7nJyJiawRe2j-ugYQQ.jpeg" /><figcaption>OpenStack Temel Servisler-Detaylı Mimari Gösterimi</figcaption></figure><p>Şimdi de temel servislere tek tek bakalım:</p><blockquote><strong>Identity Service(Keystone)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*hcAUJzrt20ZBJrlJPVh9xw.jpeg" /></figure><p>Kimlik yönetim servisi olan Keystone,projelerinizin kullanıcılarından OpenStack üzerindeki yetkiye sahip diğer kullanıcılara kadar birçok kimlik bilgisini yöneten servistir.OpenStack sistemi üzerinde tüm yetkilendirme ve doğrulama işlemlerini yapan servistir.Bu servis ayrıca var olan kullanıcıları ve projeleri merkezi bir alandan yönetmeyi de sağlar.LDAP vb. servisler ile entegre edilebilir yapısı vardır.</p><p><a href="https://docs.openstack.org/keystone/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Object Storage(Swift)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oCVdXPplN1z_wIFpX5llaA.png" /></figure><p>MPEG4,jpg gibi basit temel objeleri saklayabilen Swift,HTTP tabanlı API sayesinde HTTP metodları ile taşınmasını sağlar ve saklar.Esnek,ölçeklenebilir ve basit bir yapısı vardır.Veri merkezi içinde yatay olarak ölçeklendirebilirsiniz.(horizantally scale)</p><p>Wikipedia vb. siteler bu nesne çözümünü kullanmaktadır.Araştırmalarıma göre de Turkcell bu depolama çözümünü kendi sistemlerinde kullanmaktadır.</p><p><a href="https://docs.openstack.org/swift/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Image Service(Glance)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*P4Sqx9Xss05gpisdRA_S4Q.png" /></figure><p>Bu servis OpenStack üzerinde kurulacak sanal makinelerin imagelarının yönetiminin yapıldığı yerdir.Depolanan imageları şablon olarak bu servis sayesinde kullanarak yeni sanal makineleri kaynaklar doğrultusunda istediğiniz kadar kurabilirsiniz.Ayrıca REST API sayesinde sahip olunan image lar hakkında bilgileri ve bu imageları yeni serverlara aktarabilirsiniz.</p><p><a href="https://docs.openstack.org/glance/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Networking Service(Neutron)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*g7-ot6WXl2MVkPd14_Kkkw.png" /></figure><p>OpenStack için tüm network ve IP adreslerini yöneten servistir.Bu servis sayesinde kullanıcılar static IP,DHCP veya <a href="https://blog.digitalocean.com/floating-ips-start-architecting-your-applications-for-high-availability/">Floating IP</a>(Kayan IP-aynı data center üzerinde bir IP adresini anında başka bir servise geçirmek.),VLAN oluşturma gibi işlemlerini kolayca yapabilirler.Ayrıca kullanıcı kendi projesi için gerekli ağ topolojisini de bu servis sayesinde sağlayabilir.</p><p>Neutron sayesinde saldırı önleme sistemleri,firewall,SDN,load balancer ve VPN hizmetler de sağlanabilir.</p><p><a href="https://docs.openstack.org/neutron/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Block Storage(Cinder)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*tL1aESH-ih6I-BPSz7qVQQ.png" /></figure><p>OpenStack üzerindeki instanceların(var olan makinelerin) bilgilerinin ve ihtiyaçlarının saklanması için kullanılan depolama servisidir.Buna ek olarak sanal makinelerin alınan snapshotları bu servis üzerinde tutulur.Gerektiğinde tekrar bu servis üzerinden sanal makineler restore edilebilir.Bu servis OpenStack Cloud hizmeti için birincil veya ek olarak bir depolama çözümü olarak kullanılması yapılan işin maksimize edilmesi için yararlı bir çözümdür.</p><p><a href="https://docs.openstack.org/cinder/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Compute Service(Nova)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*9coDSjDY6StRkvABTkP-9Q.png" /></figure><p>IaaS(Infrastructure as a Service) olarak kurulan bir mimaride sanallaştırma ve kaynak yönetiminin yapıldığı servistir. Yönetim, sunucu kaynak havuzunun otomatikleştirilmesi hem de bare metal ve HPC(high performance computing)genişletilmiş sanallaştırma teknolojilerine uygun olarak çalışması için tasarlanmıştır. KVM,VMware,Xen,Hyper-V,XenServer,LXC gibi destekleri bulunmaktadır.</p><p>Nova’nın mimarisi standart olarak yatay olarak ölçeklenecek şekilde(horizantally scale)tasarlanmıştır.</p><p><a href="https://docs.openstack.org/nova/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Dashboard(Horizon)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*18f2ZGRck-_h8-QCIqj-Bw.png" /></figure><p>OpenStack üzerindeki işlemleri web arayüzünde grafikler,sürükle-bırak,tıklama ile kolayca yönetebildiğimiz ve kontrolünü sağlayabildiğimiz bir araçtır.Bu araç OpenStack üzerindeki servislerin de arayüzünü sağlar ve bir anlamda komut satırlarından biraz soyutlanmamızı sağlar.</p><p>Horizon,değiştirilebilir yapısı sayesinde birçok sağlayıcı arayüzü yeniden tasarlayarak bunu bir ürün olarak kullandırmasını sağlar.Monitoring,network topoloji,sanal makine yönetimi gibi işlemlerde arayüz ile kolayca halledilebilmektedir.</p><p><a href="https://docs.openstack.org/horizon/latest/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><h3>- İsteğe Bağlı Servisler</h3><p>Bu kısımda OpenStack servisleri içinde temel olarak değil fakat kuracağınız mimari ve iş türüne göre kullanabileceğiniz bazı servislerden bahsetmek istiyorum.Hepsinden bahsetmesem de kullanım oranları en fazla olan ve popüler bileşenleri inceledim:</p><blockquote><strong>Bare Metal Service (Ironic)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*szhKFMvkPdSKLLROUf3xLA.png" /></figure><p>İronic, bare metal yani fiziksel makinelerin sağlanmasını,yönetilmesini ve destek verilmesini sağlayan bir bileşendir.Bunu yapmak için Nova bare metal driver yararlanarak fiziksel makineleri sağlar.Bağımsız olarak veya OpenStack Cloud içerisindeki diğer bileşenler ile(Nova,Neutron,Keystone,Glance,Swift) entegre olarak çalışabilir.Peki tam olarak bare metal yani fiziksel sunucuları sanallaştırma gibi bir teknoloji varken neden direkt olarak kullanırız?Buna örnek birkaç sebebi aşağıdaki gibi sıralayabiliriz:</p><ul><li>Yüksek performanslı işlem kümeleri oluşturabilmek için.</li><li>Sanallaştırma teknolojisinin uygulanamadığı cihazlar üzerindeki bazı işlem görevlerini yapabilmek için.</li><li>Database hosting işlemleri için. (bazı databaseler sanallaştırmaya destek açısından zayıf kalmaktadır.)</li><li>Bazı özel performans donanımları, güvenilebilirlik,diğer düzenleyici gereksinimlere bağlı kalabilmek için.</li><li>Hızlı bir cloud altyapısı hazırlamak amacıyla kullanılan kaynaklar için.</li></ul><p>Doğru yapıldığı takdirde,API ların da yardımı ile,planlanan OpenStack Cloud yapısı içerisinde hem sanal makineler hem de fiziksel makineler verimli bir şekilde kullanılabilir.Yine de bahsedilen fiziksel makinelerin vendorlarına göre değişen sahip olduğu farklı karakteristik özellikler dolayısıyla bazı aksiyonlar limitli kalabilmektedir.Örneğin, live migration bare metal bir instance üzerinde yapılamıyor.</p><p>OpenStack Cloud topluluğu yine de geniş bir donanım yelpazesini kapsayacak şekilde açık kaynaklı teknolojilerden(PXE,IPMI vb.) teknolojilerden yararlanıyor.Ayrıca Ironic,sahip olduğu “pluggable driver” mimarisi sayesinde donanım vendorlarına performansı arttırabilecek,uyum sağlayabilecek,topluluk sürücüleri tarafından sağlanmayan işlevleri kendilerine ekleyebilecek olanaklar sağlar.</p><p><a href="https://docs.openstack.org/ironic/latest/user/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Container Orchestration Engines Provision Service(Magnum)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*IBJbHrS9Epyre6rDXX4FYg.png" /></figure><p>Magnum,OpenStack Containers Team tarafından geliştirilen ve üzerlerinde Docker,Mesos gibi container teknolojileri barındıran gibi COE leri(Container Orchestration Engines: Docker Swarm,Kubernetes,Apache Mesos) OpenStack içerisinde kaynak olarak kullanmayı sağlayan bir servistir.</p><p>Magnum temelde bunu yaparken OpenStack içerisindeki başka bir servis olan <a href="https://docs.openstack.org/heat/latest/">Heat</a>’in özelliklerinden yararlanır.Kısaca Heat’den bahsetmek istersek…<a href="https://wiki.openstack.org/wiki/Heat">Heat</a>, orchestration ve infrastructure sağlayan ve bunu sağlarken farklı yapılardaki cloud uygulamalarını “template” yapısını kullanarak hazırlayan bir servistir diyebiliriz.<a href="https://www.youtube.com/watch?v=RbqKjPJq0VU">Buradaki</a> ve <a href="https://www.youtube.com/watch?v=XGZM42gTdLs">buradaki</a> linkteki videoları kısaca izlersek bu servisin ne işe yaradığını daha iyi anlayabiliriz ve aslında bahsettiğimiz “template” yapısını Docker vb. birçok teknolojide kullandığımız YML uzantılı dosyalara benzetebiliriz.</p><p>Heat’in özelliklerinden olan template yapısını kullanarak hazırlanan imajları kullanan Magnum COE üzerlerinde gerekli mimariyi oluşturabilir ve sanal makine veya bare metal makine ayrımı yapmaksızın bunları çalıştırabilir.Magnum’un sağladığı diğer faydaları ise şöyle sıralayabiliriz:</p><ul><li>API bazlı olarak container clusterları için <a href="https://thenewstack.io/container-lifecycle-management-part-one-not-fathers-vms/">life-cycle management</a></li><li>Container clusterları için multi-tenancy yapı.</li><li>Bare metal veya sanal sunucular farketmeksizin istenilen multi-tenancy yapıyı OpenStack üzerinde kurgulanabiliri.</li><li>Keystone bazlı multi-tenant güvenlik ve yetkilendirme yönetimi</li><li>Neutron bazlı network yönetimi ve izolasyonu</li><li>Cinder bazlı containerlar için volume imkanları</li><li>Cloud kullanıcıları için SSO(Single-Sign-On) sağlar ve güvenli container yapıları için TLS ile erişime imkan sağlar.</li></ul><p><a href="https://docs.openstack.org/magnum/latest/user/index.html"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Shared File System Service (Manila)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*s-M7CaaUNPVff_lH1cyM-w.png" /></figure><p>Manila,OpenStack ortamı içerisinde vendor bağımısız olarak ve farklı şekillerde dosya paylaşımını destekleyen ve yöneten bir servistir.Yazımızın başında bahsettiğimiz Cinder servisinden farklı olarak bu servis,API’ları sayesinde farklı vendorlara bağlı ve <a href="https://docs.openstack.org/newton/config-reference/shared-file-systems/overview.html">farklı türdeki depolama birimleri</a> için standart bir düzlemde yönetim ve kontrol sağlar.Bunlara örnek olarak NAS hostlarını bir araya toplayan <a href="https://docs.gluster.org/en/latest/">GlusterFS</a>,<a href="https://cephturkiye.com/2018/03/04/ceph-depolamanin-gelecegi/">Ceph</a> ürünleri ve <a href="https://www.youtube.com/watch?v=nKLcHYZhhh4">NFS</a>,<a href="https://www.gokhankesici.com/common-internet-file-system-cifs-protocol/">CIFS</a>,<a href="https://www.tutorialspoint.com/hadoop/hadoop_hdfs_overview">HDFS</a> gibi <a href="https://docs.openstack.org/mitaka/config-reference/shared-file-systems.html">depolama çözümleri</a> protokollerini kullanan örnek gösterebiliriz.OpenStack içerisinde çalışan bu dosya sistemleri hangi kaynağa ilişkin verileri tutatsa tutsun Manila sayesinde bunlar tek bir düzlemden görülebilir ve yönetilebilir.</p><p>Dosya tabanlı depolama sistemleri(file-based-storage systems) gelişen bir pazardır.Buna bağlı olarak geliştirilen uygulamalar için kullanılan dağıtık veya ilişkisel veritabanları da sıklıkla değişmektedir.Manila sayesinde OpenStack gibi bir cloud ortamında bu tür uygulamaların sorunsuz olarak ve çok kiracılı bir yapıda paylaşımlı çalışması sağlanabilir.</p><p><a href="https://wiki.openstack.org/wiki/Manila"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><blockquote><strong>Messaging Service — Message Broker Provisioning Service(Zaqar)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*8qAQoF_w40wabZJSCx6STw.png" /></figure><p>Zaqar,web ve mobil geliştiriciler için çok kullanıcılı-kiracılı bir cloud messaging service tir.<a href="https://aws.amazon.com/tr/sqs/">Amazon SQS</a> servisinin temeldeki bazı özelliklerini alarak geliştirilen bu servis geliştiriciler için <a href="https://docs.aws.amazon.com/en_us/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html">Amazon SQS</a> ve <a href="https://aws.amazon.com/tr/sns/">SNS</a>’e bir alternatif olabilir.Bu servis REST API,sayesinde geliştiricilerin kendi uygulamaları için tasarladıkları SaaS iletişim ortamlarında(<a href="https://towardsdatascience.com/10-common-software-architectural-patterns-in-a-nutshell-a0b47a1e9013">communication patterns</a>) bileşenler arası mesaj gönderimlerini sağlar.Bu REST API içerisinde güvenilir,ölçeklenebilir ve verimli bir mesajlaşma motoru bulunur(messaging engine).Ayrıca isteğe göre Websocket API’de kullanılabilir.</p><p>Zaqar için API ve data-oriented yani veri odaklı olduğunu söyleyebiliriz.Bu da şu anlama gelmektedir;direkt olarak bir <a href="https://dzone.com/articles/exploring-message-brokers">message broker</a> olarak çalışmaz ve backend den gelen mesajları direkt olarak client a iletmez.Bunun yerine bir veya daha fazla backend ile client arasında iletişim için cloud seviyesinde bir köprü oluşturur.</p><p>Teknik olarak sağladığı faydalardan biraz bahsetmek istersek şunları söyleyebiliriz:</p><ul><li>Keystone tarafından da desteklenen iki farklı haberleşme iletim türünden biri seçilebilir:<br>- <strong><em>HTTP tabanlı </em></strong><a href="http://devnot.com/2016/rest-mimarisi-ve-restful-servisler/"><strong><em>RESTful API</em></strong></a><strong><em>… </em></strong>Günümüzde birçok geliştirici tarafından tercih edilen bu yöntem hem web hem de firewall dostu olması yönüyle biliniyor.Buna sebep olanda bu protokolün sadeliği ve yapılan işlemlerin sadeliği.Bununla beraber bu protokol için büyük cloud ortamlarında kullanıldığını ve load balancer,firewall,proxy ler yönetimi için kolaylık sağladığını söyleyebiliri.Ayrıca REST API mimarisinin kullanılması büyük cloud provider lar tarafından pratikte tavsiye ve takdir ediliyor.<br>-<strong><em>Websocket tabanı API…</em></strong> Sürekli bağlantılar üzerinden(persistent connections) haberleşmeyi sağlayan bir yöntemdir.HTTP’nin kullandığı her bir istek/cevap çifti için yeni bağlantı açma yöntemi yerine,Websocket tek bir TCP bağlantısı üzerinden birden fazla istek/cevap çifti transfer edebilir.Bu sonuncu olarak da network trafiği kullanımından tasarruf edilmiş ve gecikmeler azaltılmış olur.</li></ul><p>Önemli olarak gördüğüm REST ve Websocket servisleri arasındaki farkları daha detaylı olarak <a href="https://www.educba.com/websocket-vs-rest/"><strong>buradan</strong></a> görebilirsiniz.</p><ul><li>Birçok farklı <a href="https://towardsdatascience.com/10-common-software-architectural-patterns-in-a-nutshell-a0b47a1e9013">iletişim pattern türüne</a> destek verir.(broadcasting,task distribution,point-to-point messaging vs.)</li><li>Özel bileşen tabanlı mimariler için birçok farklı backend seçenekleri ve mesaj filtreleri sunar.</li><li>High-avaliable ve horizantally scalable edilebilirdir.</li><li>Birçok message queue için destek verebilir ve notification type kullanılabilir.(Email notifications,Webhook notifications,Websocket notifications)</li></ul><p><a href="https://docs.openstack.org/zaqar/latest/"><strong>Daha fazla bilgi için bakabilirsiniz…</strong></a></p><h3>- SON</h3><p>Bu yazı için incelemeyi uygun gördüğüm servisler şimdilik bu kadar.Belirtmek isterim ki OpenStack Community leri ve bazı şirketler tarafından destek verilen,geliştirilen daha birçok servis var.Bu servisleri için <a href="https://www.stackalytics.com/"><strong><em>buradaki linkteki</em></strong></a><strong><em> “Reviews by Module”</em></strong> kısmından geliştirme oranlarına,kimlerin katkı verdiğine ve <a href="https://docs.openstack.org/stein/admin/index.html"><strong><em>buradaki linkten</em></strong></a> isimlerine,kullanım yerlerine,ayrıntılı teknik bilgilere bakabilirsiniz.Bu yazı içerisindeki tüm bilgiler için OpenStack offical sitesindeki ilgili servislerin dökümanlarından ve servisleri araştırırken daha açıklayıcı olması için araştırma yaptığım sitelerden yararlandım.</p><p>Son olarak eklemek isterim ki, bu servisler kendi içlerinde her biri detaylı özellikler ve alt bileşenler içermektedir. Birçoğunun içerisinde alt bileşen olarak adlandırdığım “low-level-services” lar sayesinde API iletişimi ve diğer servisler ile uyum içerisinde çalışması sağlanmıştır.Ayrıca birçoğunun da Python ile yazıldığını da söyleyebilirim.Bunların detaylarına,mimarilerine,kurulum aşamalarına ve diğer servisler ile entegrasyonuna her bir servisin altındaki linke tıklarak çok daha detaylı bilgiye sahip olabilirsiniz.</p><p>Bir sonraki yazıda görüşmek üzere…<br>Hoşçakalın…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd5bafe2e5a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopsturkiye/openstack-serisi-2-temel-ve-i%CC%87ste%C4%9Fe-ba%C4%9Fl%C4%B1-servisler-5bd5bafe2e5a">OpenStack_Serisi #2 — Temel ve İsteğe Bağlı Servisler</a> was originally published in <a href="https://medium.com/devopsturkiye">Devops &amp; AI Türkiye☁️ 🐧 🐳 ☸️</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>