<?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 Hamed Soleimani on Medium]]></title>
        <description><![CDATA[Stories by Hamed Soleimani on Medium]]></description>
        <link>https://medium.com/@hamedsol?source=rss-8101cbfc5d01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SjHGyP6HckcPUmRuSl9fdQ@2x.jpeg</url>
            <title>Stories by Hamed Soleimani on Medium</title>
            <link>https://medium.com/@hamedsol?source=rss-8101cbfc5d01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 15:12:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hamedsol/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[Git in Practice: Real-World Version Control]]></title>
            <link>https://medium.com/@hamedsol/git-in-practice-real-world-version-control-69b3628451b4?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/69b3628451b4</guid>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 22:16:23 GMT</pubDate>
            <atom:updated>2024-09-24T23:22:04.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*mrv3I6JNtDSq6iCM7fydcA.jpeg" /><figcaption>Git in Practice: Real-World Version Control</figcaption></figure><p>Are you tired of version control headaches and cumbersome project management?</p><p>Take your team’s productivity to the next level with our comprehensive, hands-on course on collaborative Git workflows.</p><p>Master Key Skills:</p><ul><li>Collaborative development strategies</li><li>Efficient version control techniques</li><li>Conflict resolution and merge management</li><li>Best practices for team workflow optimization</li></ul><p>What You’ll Gain:</p><ul><li>Confidence in managing complex Git projects</li><li>Expertise in resolving merge conflicts</li><li>Improved teamwork and communication skills</li><li>Boosted productivity and efficiency</li></ul><p>Enroll Now and Transform Your Team’s Workflow<br>#Git #Collaboration #Github</p><p>Practical git course :</p><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69b3628451b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Expose a containerised game deployed by kubernetes to the public internet via AWS LoadBalancer]]></title>
            <link>https://medium.com/@hamedsol/expose-a-containerised-game-deployed-by-kubernetes-to-the-public-internet-via-aws-loadbalancer-c2ce705353f1?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2ce705353f1</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 13:05:22 GMT</pubDate>
            <atom:updated>2024-09-24T22:23:25.439Z</atom:updated>
            <content:encoded><![CDATA[<p>In my latest story, I have demonstrated how to containerise a very popular open-source web-based game, 2048. You can find the story here:<br><a href="https://medium.com/@hamedsol/how-to-containerize-containerise-a-game-application-04bebb2a1af6">https://medium.com/@hamedsol/how-to-containerize-containerise-a-game-application-04bebb2a1af6</a></p><p>Now, I am going to deploy the game using Kubernetes, run it behind an AWS LoadBalancer, and then expose it to the public internet to be accessible via your subdomain game.example.com .</p><p><strong>Note:</strong> You need to have a Kubernetes cluster that natively supports cloud-controller Manager for AWS, such as EKS, or a self-managed cluster created by Kops on AWS. I have chosen Kops since I am a fan of self-managed clusters as it offers me more flexibility. In the video below, I have demonstrated how to deploy a sample Kubernetes cluster using Kops on AWS.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F45EZD1SfQac%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D45EZD1SfQac&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F45EZD1SfQac%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/f91df35ad3f60fec6a61c6b5b4ba5e73/href">https://medium.com/media/f91df35ad3f60fec6a61c6b5b4ba5e73/href</a></iframe><p>Just follow the steps below:</p><ol><li>Create a directory on the Linux machine, which is likely your local machine, and create a namespace named ‘game’:</li></ol><pre>hsoleimani@xxxx:~$ mkdir -p game<br>hsoleimani@xxxx:~$ cd game/<br>hsoleimani@xxxx:~$ kubectl create namespace game</pre><p><em>2. </em>Create a deployment object as below:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: game-deployment<br>  namespace: game<br>  labels:<br>    app.kubernetes.io/name: game-app<br>spec:<br>  replicas: 2  # Specify the desired number of replicas here<br>  selector:<br>    matchLabels:<br>      app.kubernetes.io/name: game-app<br>  template:<br>    metadata:<br>      labels:<br>        app.kubernetes.io/name: game-app<br>    spec:<br>      containers:<br>      - name: game<br>        image: hamedsoleimani/devsecops_project<br>        ports:<br>          - containerPort: 80<br>            name: http-game-svc</pre><p>above deployment.yaml file will create 2 replicas / pods of the game on your cluster .</p><p>3. Apply your deployment :</p><pre>hsoleimani@xxxx:~/game$ kubectl apply -f game-deployment.yaml</pre><p>4. Now it is time to create your service by defining the type as a LoadBalancer :</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: game-service<br>  namespace: game<br>spec:<br>  selector:<br>    app.kubernetes.io/name: game-app<br>  ports:<br><br>    - protocol: TCP<br>      port: 80<br>      targetPort: http-game-svc<br>  type: LoadBalancer</pre><p>5. Apply the service :</p><pre>hsoleimani@xxxx:~/game$ kubectl apply -f game-service.yaml</pre><p>After a while, you should see the external IP as your Load Balancer DNS by running the commands below.</p><pre>hsoleimani@xxxx:~$ kubectl -n game get svc -o wide</pre><p><strong>Note:</strong> If you’ve never created an ELB on your AWS account, it might get stuck in a pending state. Simply create one manually and then delete it. Hopefully, this will resolve the issue. Also, ensure that you have sufficient privileged access on your account.</p><p>6. Now, you can access the game via the Load Balancer DNS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4--shzhfQ9jTo67jj1wmg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFeqF2eVdZ0AU5D3JFpqEg.jpeg" /></figure><p>However, if you already have a domain name, you can simply create an alias subdomain on your AWS account to route all internet traffic to it. I have done this as shown below, but please note that it may take some time for the subdomain to be updated.Afterward, you will be able to access your game via <a href="http://game.example.com/">http://game.example.com</a>. Enjoy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ghbi9un7o32WkB-oHGNd0A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdmBg6cPmQP_3fCE_FuNkw.jpeg" /></figure><p>you can watch the video in below link :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F050F7pr-tDo&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D050F7pr-tDo&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca05ae9e251060b46dc99eed43cac3dd/href">https://medium.com/media/ca05ae9e251060b46dc99eed43cac3dd/href</a></iframe><h3>Git in Practice: Real-World Version Control</h3><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2ce705353f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Containerize a game application]]></title>
            <link>https://medium.com/@hamedsol/how-to-containerize-containerise-a-game-application-04bebb2a1af6?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/04bebb2a1af6</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Sat, 24 Feb 2024 10:05:35 GMT</pubDate>
            <atom:updated>2024-09-24T23:18:21.274Z</atom:updated>
            <content:encoded><![CDATA[<p>In this story and subsequent stories, I will demonstrate the deployment of a comprehensive and entertaining project using Kubernetes. This serves as a practical example if you intend to deploy an application on a Kubernetes cluster and subsequently create and expose the service to the public internet. For now, I am going to show you “How to Containerize a game application.”</p><p>The first step is finding a game. I suggest 2048, which you can find at the following address: <a href="https://github.com/gabrielecirulli/2048.git">https://github.com/gabrielecirulli/2048.git</a>.</p><p>Clone this repository into your directory and navigate to the root directory as follows:</p><pre>hsoleimani@xxxx:~$ git clone https://github.com/gabrielecirulli/2048.gitcd <br>hsoleimani@xxxx:~$ cd 2048/<br>hsoleimani@xxxx:~/2048$ </pre><p>Then, create a Dockerfile to build your image as follows:</p><pre>hsoleimani@xxxx:~/2048$ nano Dockerfile</pre><p>Below is the content of the Dockerfile I have created:</p><pre># Use an appropriate base image<br>FROM nginx<br><br># Set the working directory in the container<br>WORKDIR /usr/share/nginx/html<br><br># Copy the static files for NGINX<br>COPY . .<br><br># Expose port 80<br>EXPOSE 80<br><br># Start NGINX<br>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]</pre><p>Now build your image</p><pre># Build your docker image <br>hsoleimani@xxxx:~/2048$ docker build -t 2048-game .</pre><p>You can crosscheck your built image as follows:</p><pre>hsoleimani@xxxx:~/2048$ docker image ls</pre><p>The next step is creating a repository in Docker Hub. I have created one at the following URL:</p><p><a href="https://hub.docker.com/repositories/hamedsoleimani">https://hub.docker.com/repositories/hamedsoleimani</a></p><p>Then, I pushed the image to my Docker Hub account after logging in and tagged the image as shown below:</p><pre>hsoleimani@xxxx:~/2048$ docker login<br>hsoleimani@xxxx:~/2048$ docker tag 2048-game:latest hamedsoleimani/containerised-image-twenty-forty-eight:latest<br>hsoleimani@xxxx:~/2048$ docker push hamedsoleimani/containerised-image-twenty-forty-eight:latest</pre><p>Just to verify if the application is exposing the service on port 8080, run the command below:</p><pre>hsoleimani@xxxx:~/2048$ docker run -d -p 8080:80 2048-game</pre><p>You can view the application on your local machine’s browser by entering the following localhost address: 127.0.0.1:8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GYX0y4aU4cIolQjpOccdnA.jpeg" /></figure><p>In the next story, I will go one step further and show you how to deploy this containerized image on a Kubernetes cluster. Please watch the following YouTube video if you prefer to learn by watching:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FP5M7Vbcm1Nw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DP5M7Vbcm1Nw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FP5M7Vbcm1Nw%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/6e4d5a20fe645666950ec76cc213e250/href">https://medium.com/media/6e4d5a20fe645666950ec76cc213e250/href</a></iframe><p>Practical git course :</p><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04bebb2a1af6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Production-Level Kubernetes Cluster on AWS by kubespray and Terraform — Security Best…]]></title>
            <link>https://medium.com/@hamedsol/deploying-a-production-level-kubernetes-cluster-on-aws-by-kubespray-and-terraform-security-best-3ede6f66fd68?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ede6f66fd68</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Mon, 19 Feb 2024 11:13:23 GMT</pubDate>
            <atom:updated>2024-09-24T23:16:20.757Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@hamedsol/deploying-a-production-level-kubernetes-cluster-on-aws-security-best-practices-0fa99b910b35?source=user_profile---------0----------------------------">Deploying a Kubernetes Cluster on AWS by kubespray and Terraform — Security Best Practices</a></h3><p>Note: This story is a continuation of the story mentioned in the link below. If you haven’t read it before, please refrain from doing so now: Deploying a Production-Level Kubernetes Cluster on AWS: Security Best Practices</p><p><a href="https://medium.com/@hamedsol/deploying-a-production-level-kubernetes-cluster-on-aws-security-best-practices-0fa99b910b35">Deploying a Production-Level Kubernetes Cluster on AWS — Security Best Practices</a></p><p>In the previous story, I created a public subnet and a private subnet inside a private VPC. I’ve already spun up an Ansible controller inside the private subnet. To access the Ansible controller, you can either connect using the SSM agent or open an SSH connection via your local machine to the Ansible controller by adding your public IP address to the relevant security group. I assume that all instances have been stopped or terminated except the Ansible controller.</p><h4><strong>Install terraform and awscli on ansible-controller:</strong></h4><p>Login to ubuntu user to ansible-controller as below</p><pre># make a terraform directory<br>ubuntu@ansible-controller:~$mkdir -p terraform<br># go inside that directory<br>ubuntu@ansible-controller:~$ cd terraform/<br>ubuntu@ansible-controller:~/terraform$</pre><h4><strong>create below files inside terraform directory:</strong></h4><pre>ubuntu@ansible-controller:~/terraform$ nano main.tf</pre><pre># main.tf<br><br>provider &quot;aws&quot; {<br>  region = &quot;ap-southeast-2&quot;<br>}<br><br># Existing Security Group IDs<br>variable &quot;existing_security_group_ids&quot; {<br>  type    = list(string)<br>  default = [&quot;your-existing-security-group-from-previous-story&quot;]  # Replace with your actual security group ID<br>}<br><br><br>resource &quot;aws_instance&quot; &quot;master&quot; {<br>  ami           = &quot;ami-04f5097681773b989&quot;<br>  instance_type = &quot;t3.medium&quot;<br>  key_name      = &quot;your-private-key&quot;<br>  subnet_id     = &quot;your-private-subnet-ID&quot;<br>  vpc_security_group_ids = var.existing_security_group_ids<br>  tags = {<br>    Name = &quot;master&quot;<br>  }<br>}<br><br>resource &quot;aws_instance&quot; &quot;worker1&quot; {<br>  ami           = &quot;ami-04f5097681773b989&quot;<br>  instance_type = &quot;t3.medium&quot;<br>  key_name      = &quot;your-private-key&quot;<br>  subnet_id     = &quot;your-private-subnet-ID&quot;<br>  vpc_security_group_ids = var.existing_security_group_ids<br>  tags = {<br>    Name = &quot;worker1&quot;<br>  }<br>}<br><br>resource &quot;aws_instance&quot; &quot;worker2&quot; {<br>  ami           = &quot;ami-04f5097681773b989&quot;<br>  instance_type = &quot;t3.medium&quot;<br>  key_name      = &quot;your-private-key&quot;<br>  subnet_id     = &quot;your-private-subnet-ID&quot;<br>  vpc_security_group_ids = var.existing_security_group_ids<br>  tags = {<br>    Name = &quot;worker2&quot;<br>  }<br>}</pre><pre>ubuntu@ansible-controller:~/terraform$ nano variables.tf</pre><pre># variables.tf<br><br>variable &quot;aws_region&quot; {<br>  description = &quot;AWS region where resources will be created&quot;<br>  type        = string<br>}<br><br>variable &quot;key_name&quot; {<br>  description = &quot;Name of the SSH key pair&quot;<br>  type        = string<br>}<br><br># Add any other variables you need</pre><pre>ubuntu@ansible-controller:~/terraform$ nano terraform.tfvars</pre><pre># terraform.tfvars<br><br>aws_region = &quot;ap-southeast-2&quot;<br>key_name   = &quot;your-private-key&quot;<br># Add any other variables you need</pre><h4><strong>Run terraform</strong> commands:</h4><pre>ubuntu@ansible-controller:~/terraform$terraform init<br># Review changes <br>ubuntu@ansible-controller:~/terraform$terraform plan<br># Apply the changes<br>ubuntu@ansible-controller:~/terraform$terraform apply</pre><p>After successfully running the previous steps, you can SSH to installed master instance using the “your-private-key” defined in the Terraform files</p><pre>ubuntu@ansible-controller:~$ ssh -i your-private-key.pem ubuntu@10.0.130.246<br><br>ubuntu@node1:~$<br></pre><p>Now return back to the Ansible controller and switch to the root user.</p><pre>ubuntu@ansible-controller:~$ sudo su<br>root@ansible-controller:/home/ubuntu# cd<br>root@ansible-controller:~#VENVDIR=kubespray-venv<br>root@ansible-controller:~#KUBESPRAYDIR=kubespray<br>root@ansible-controller:~#python3 -m venv $VENVDIR<br>root@ansible-controller:~#source $VENVDIR/bin/activate<br>(kubespray-venv) root@ansible-controller:~#apt install python3.10-venv<br>(kubespray-venv) root@ansible-controller:~# cd $KUBESPRAYDIR<br>(kubespray-venv) root@ansible-controller:~/kubespray#pip install -U -r requirements.txt<br>(kubespray-venv) root@ansible-controller:~/kubespray#cp -rfp inventory/sample inventory/mycluster<br><br># here add your nodes private addresses<br><br>(kubespray-venv) root@ansible-controller:~/kubespray#declare -a IPS=(10.0.130.246 10.0.139.103 10.0.129.55) <br>(kubespray-venv) root@ansible-controller:~/kubespray#CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}<br><br># crosscheck the hosts.yaml <br><br>(kubespray-venv) root@ansible-controller:~/kubespray#nano inventory/mycluster/hosts.yaml<br><br># now run the ansible playbook<br><br>(kubespray-venv) root@ansible-controller:~/kubespray#ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml<br></pre><p>After nearly 10 minutes you ckuster is ready connect to the master node as below</p><pre>(kubespray-venv) root@ansible-controller:~/kubespray# cd<br>(kubespray-venv) root@ansible-controller:~# ssh ubuntu@10.0.130.246<br>ubuntu@node1:~$sudo su <br>root@node1:/home/ubuntu# kubectl get node<br>NAME    STATUS   ROLES           AGE   VERSION<br>node1   Ready    control-plane   90m   v1.28.2<br>node2   Ready    control-plane   90m   v1.29.1<br>node3   Ready    &lt;none&gt;          89m   v1.29.1</pre><p>As you can see, your cluster is ready. To destroy the cluster, return to the Ansible controller and go to the Terraform directory.</p><pre>ubuntu@ansible-controller:~/terraform$ terraform destroy<br>.<br>.<br>.<br>Plan: 0 to add, 0 to change, 3 to destroy.<br><br>Do you really want to destroy all resources?<br>  Terraform will destroy all your managed infrastructure, as shown above.<br>  There is no undo. Only &#39;yes&#39; will be accepted to confirm.<br><br>  Enter a value:yes<br>.<br>.<br>.<br><br>aws_instance.worker1: Destruction complete after 2m0s<br><br>Destroy complete! Resources: 3 destroyed.</pre><p>You can stop your Ansible controller using the AWS console to avoid further charges.</p><p>Below is the video of all my story .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_iu-sXw4Yas%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_iu-sXw4Yas&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_iu-sXw4Yas%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/71c92507bd6424fc03d255e387a8e0bf/href">https://medium.com/media/71c92507bd6424fc03d255e387a8e0bf/href</a></iframe><p>Practical git course :</p><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ede6f66fd68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a Secure Kubernetes Cluster by Kops in AWS — Security Best Practices]]></title>
            <link>https://medium.com/@hamedsol/deploy-a-secure-kubernetes-cluster-by-kops-in-aws-6da43b122b05?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/6da43b122b05</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kops]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 07:12:44 GMT</pubDate>
            <atom:updated>2024-09-24T23:19:54.005Z</atom:updated>
            <content:encoded><![CDATA[<p>Deploying a self-managed Kubernetes cluster using Kops on a cloud platform is a well-documented and well-developed solution, specifically designed for developers. Please refer to the link below for more information.</p><p><a href="https://kops.sigs.k8s.io/">Welcome - kOps - Kubernetes Operations</a></p><p>If you follow the quick start guide, it appears quite straightforward to spin up a production-level Kubernetes cluster. For instance, in AWS, all you need to do is create an IAM role for Kops, an S3 bucket to save the cluster state, and a hosted zone. You can also use Gossip DNS instead of externally hosted DNS for propagating the Kubernetes API address. In the video below, I deployed a very simple cluster on AWS using Kops, without considering any security hardening practices.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F45EZD1SfQac%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D45EZD1SfQac&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F45EZD1SfQac%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/f91df35ad3f60fec6a61c6b5b4ba5e73/href">https://medium.com/media/f91df35ad3f60fec6a61c6b5b4ba5e73/href</a></iframe><p>However, installing such a cluster does come with some security risks, which I have already discussed in the video below. These include:</p><ul><li>Accessibility of all nodes from the public internet without any IP address restriction.</li><li>Saving the cluster state in an S3 bucket without version control.</li><li>Tendency of nodes to reside inside public subnets.</li></ul><p>Below, I have provided a video discussing some of the security issues I have observed from my perspective as a security specialist.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2u5gChin_aI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2u5gChin_aI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2u5gChin_aI%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/75926636ced74fea7dd5b94a958fd3b2/href">https://medium.com/media/75926636ced74fea7dd5b94a958fd3b2/href</a></iframe><p>After identifying the above issues, I deployed a cluster as described below. In this deployment, I attempted to apply more infrastructure security practices to a Kops cluster. However, securing a Kubernetes cluster is more complex than this and needs to be secured at the application level as well.</p><p>In order to securely deploy a Kops cluster on AWS, I used three private subnets, each hosting a master node to provide high availability. I also added two worker nodes in two separate AWS availability zones. A bastion host was added to provide developers with indirect access to the cluster nodes. Additionally, I restricted API and SSH access by modifying the security groups. Versioning was also activated for the S3 bucket.</p><p>1. Install Kops, AWS CLI, kubectl an jq on a Linux machine (I used a Raspberry Pi as it was the only machine I had that wasn’t behind a firewall). Then, run the following command:</p><pre>aws configure</pre><p>This will prompt you to add your access key, secret key, AWS region, and output format.</p><blockquote>hsoleimani@raspberrypi:~ $ aws configure<br>AWS Access Key ID [****************Q5]:<br>AWS Secret Access Key [****************FP]:<br>Default region name [ap-southeast-2]:<br>Default output format [json]:</blockquote><p>Then, create a bucket either by using AWS CLI or through the AWS console.</p><pre>aws s3api create-bucket --bucket &lt;your_bucket_name&gt; --region ap-southeast-2 --create-bucket-configuration LocationConstraint=ap-southeast-2</pre><p>I enabled version control to prevent loss of the cluster state as a backup using the command below:</p><pre>aws s3api put-bucket-versioning --bucket &lt;your_bucket_name&gt; --versioning-configuration Status=Enabled</pre><p>Next, I used the command below to retrieve my hosted-zone ID. I’m assuming you’ve already purchased example.com from AWS or defined a hosted subdomain hosted zone on AWS. For me, example.com worked since I bought the domain from AWS. Please refer to the Kops documentation where this is clearly explained.</p><pre>HZC=$(aws route53 list-hosted-zones | jq -r &#39;.HostedZones[] | select(.Name==&quot;example.com.&quot;) | .Id&#39; | tee /dev/stderr)</pre><p>The output will be something like this. Please keep a record of it:</p><p>/hostedzone/Zxxxxxxxxxxxxxxxxxxx4</p><p>then run below command</p><pre># This command creates a new Kubernetes cluster using kops on AWS.<br>kops create cluster example.com \<br>    --cloud=aws \<br>    --zones=ap-southeast-2a,ap-southeast-2b,ap-southeast-2c \<br>    --kubernetes-version=1.28.6 \<br>    --control-plane-zones=ap-southeast-2a,ap-southeast-2b,ap-southeast-2c \<br>    --node-count=2 \<br>    --topology private \<br>    --node-size=t3.medium \<br>    --control-plane-size=t3.large \<br>    --dns-zone=Zxxxxxxxxxxxxxxxxxxx4 \<br># in order to access the Kubernetes cluster via the bastion (jump-host), run the command below:To SSH into the bastion, use below from local machine:<br>    --bastion=true \<br>    --ssh-public-key=$HOME/.ssh/id_rsa.pub</pre><p>After running the above command, follow up with Kops edit and update commands, which will be prompted at the end. By using kops edit, you can restrict access to your cluster via your local IP address either for SSH or API access. kops update will complete the cluster installation. Below is the command to access the bastion host. You might need to replace bastion.example.com with the accurate DNS record of the relevant load balancer (refer to the video for more details, please).</p><pre>ssh -A -i ~/.ssh/id_rsa ubuntu@bastion.example.com</pre><p>You can access other cluster nodes using your local machine’s private key. Copy and paste id_rsa from your local machine to the same path on the bastion host , this a secure way to access your cluster .then run the following command to get access to cluster nodes :</p><p>ssh ubuntu@node1</p><p>I can list the nodes status by my local machine as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*shwEHAQaWj8_w2kQHlBK0g.jpeg" /></figure><p>At the end, to destroy the cluster, you can run the following command:</p><pre>kops delete cluster --name example.com --yes --state=s3://xxxxxxxxx</pre><p>Above command will delete the Kubernetes cluster named ‘example.com’ and the state will be stored in the specified S3 bucket . Please ensure that you have the necessary permissions and the cluster name and S3 bucket are correct. Please refer to the video below to watch the entire procedure.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrPP0zQSschg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrPP0zQSschg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrPP0zQSschg%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/1dc27254ef897881a915c68d16437f45/href">https://medium.com/media/1dc27254ef897881a915c68d16437f45/href</a></iframe><p>Practical git course :</p><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6da43b122b05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Production-Level Kubernetes Cluster on AWS — Security Best Practices]]></title>
            <link>https://medium.com/@hamedsol/deploying-a-production-level-kubernetes-cluster-on-aws-security-best-practices-0fa99b910b35?source=rss-8101cbfc5d01------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fa99b910b35</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubespray]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Hamed Soleimani]]></dc:creator>
            <pubDate>Sun, 04 Feb 2024 03:02:30 GMT</pubDate>
            <atom:updated>2024-09-24T23:20:32.644Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying a Production-Level Kubernetes Cluster on AWS by kubespray — Security Best Practices</h3><p>There are several ways to set up a self-managed Kubernetes cluster. If your goal is to learn Kubernetes, this article is not for you. You can use Minikube or even Kubeadm with 2 or 3 nodes.</p><p>Kubespray runs on bare metal and most clouds, using Ansible as its main tool for provisioning and orchestration. I believe basic familiarity with Ansible, such as knowing how to use playbooks and change variables, is essential to use Kubespray. Based on my personal experience, Kubespray is one of the main deployment tools for telecom-grade clusters that run on bare metal or private clouds.</p><p>The main platform for this demo is AWS. You might ask why AWS, and the answer is just for lab purposes, since AWS already has EKS as its managed Kubernetes service. KOps is another useful tool to deploy self-managed K8s clusters on public and private clouds. It will also provision the necessary cloud infrastructure. I will try to provide another demo about it later on. Basic knowledge of AWS is essential for readers. Since security is very important to me, I aim to deploy security best practices.</p><p>You can watch what I have done in below YouTube link as well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQZ42zNcHMUQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQZ42zNcHMUQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQZ42zNcHMUQ%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/511af8015f940d4db9eadfd7bbdfd416/href">https://medium.com/media/511af8015f940d4db9eadfd7bbdfd416/href</a></iframe><p><strong>Step 1: Prepare Ansible Controller Node:</strong></p><p>1–1. Create an admin account with Multi-Factor Authentication (MFA) as well as keys to be used by AWS CLI. Refer to AWS documents for more information.</p><p>C:\Users\user1&gt;aws configure</p><p>AWS Access Key ID [None]: xxxxx</p><p>AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxx</p><p>Default region name [None]:</p><p>Default output format [None]:</p><p>1–2. Configure AWS CLI with MFA:</p><p>C:\Users\user1&gt;aws sts get-session-token — serial-number arn:aws:iam::ACCOUNT-ID-WITHOUT-HYPHENS:mfa/USERNAME — token-code CODE-FROM-MFA</p><p>You will receive the following temporary keys, which will be valid for 12 hours by default:</p><p>{</p><p>“Credentials”: {</p><p>“AccessKeyId”: “xxxxxxx”,</p><p>“SecretAccessKey”: “xxxxxxxxxxxxxxxxxxxxx”,</p><p>“SessionToken”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,</p><p>“Expiration”: “2024–02–03T11:53:21+00:00”</p><p>}</p><p>}</p><p>1–3. Set/export them as environmental variables. If you are using Windows CMD:</p><p>C:\Users\user1&gt;set AWS_ACCESS_KEY_ID=xxxxxxxx</p><p>C:\Users\user1&gt;set AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxx</p><p>C:\Users\user1&gt;set AWS_SESSION_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p><p>1-4. Create a VPC or use the default VPC. Also, create one availability zone (though not the best practice for high availability, it’s acceptable for lab purposes). Personally, I created two subnets within a private VPC: one private subnet and one public subnet. I used one NAT gateway inside the public subnet and associated relevant route tables from the private subnet to the public subnet.</p><p>1–5. Below is a preview; if you select “VPC and More,” the route tables will be created by default as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7EnETQpM_DRS0PGT0O7_A.jpeg" /></figure><p>1–6. One of the main components of Ansible is the Ansible Controller. I will add an EC2 instance inside the public subnet and assign a public IP to it for the time being. This will allow me to use it as a bastion host as well as for SSH connections from my public IP address. (I plan to use AWS Systems Manager for enhanced security after deactivating direct SSH.)</p><p>I will use an Ubuntu image with 2 vCPUs and 4GB RAM, along with sufficient volume, as my Ansible Controller. I need to assign a security group to allow SSH access from my public IP and SSH access from within the private VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*NkBoaJ-GrdEIlQwGgMdClg.jpeg" /></figure><p>1–7. Add the following command to the user data window to install the SSM agent on my Ubuntu machine and assign “ssm-role-EC2” in the IAM instance profile. This will enable terminal access via AWS SSM, which is considered more secure than SSH .</p><p>sudo snap install amazon-ssm-agent — classic</p><p>sudo snap start amazon-ssm-agent</p><p>1–8. After launching the EC2 instance in AWS we can get terminal access to the instance via below command on your local machine .</p><p>aws ssm start-session — target i-xxxxxxx — region your-preferred-region</p><p>Alternatively, you can use SSH as shown below:</p><p>ssh -i “my_private_key.pem” ubuntu@xxxx.compute.amazonaws.com</p><p>I will return to the Ansible controller after preparing the Kubernetes cluster nodes inside the private subnet.</p><p><strong>Step 2: Prepare Kubernetes Cluster Nodes:</strong></p><p>2.1. Launch 6 Ubuntu instances inside the private subnet. Here, I create a security group to allow only internal private subnet traffic. Although we can restrict it to just the exposed ports inside the Kubernetes cluster, we can modify it later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UV861mQWGSzF47cvg3_rSQ.jpeg" /></figure><p>2.2. Assign the “ssm-role-EC2” to the IAM instance profile, and use the same private key that was used in Step 1 for now.</p><p>2.3. In order to cross-check the connection from the Ansible controller to the Kubernetes cluster nodes, first, use SCP to transfer the private key from the local AWS CLI to the Ansible controller. After that, attempt an SSH connection from the Ansible controller to the Kubernetes nodes as follows:</p><p>C:\Users\user1&gt;scp -i xxx.pem xxx.pem ubuntu@xxxxxxx.ap-southeast-2.compute.amazonaws.com:/tmp/</p><p>root@ansible-controller:~/.ssh# cp /tmp/xxx.pem id_rsa</p><p>root@ansible-controller:~/.ssh# chmod 400 id_rsa</p><p>root@ansible-controller:~# ssh ubuntu@10.0.132.196</p><p>ubuntu@ip-10–0–132–196:~$</p><p><strong>Step 3: Deploy Kubespray:</strong></p><p>Now, proceed with deploying Kubespray.</p><p>3.1. Clone the Kubespray repository on the Ansible controller instance using the following command:</p><p>root@ip-10–0–6–164:~# git clone <a href="https://github.com/kubernetes-sigs/kubespray.git">https://github.com/kubernetes-sigs/kubespray.git</a></p><p>3.2. It is recommended to deploy the Ansible version used by Kubespray into a Python virtual environment.</p><p>apt-get update</p><p>VENVDIR=kubespray-venv</p><p>KUBESPRAYDIR=kubespray</p><p>python3 -m venv $VENVDIR</p><p>source $VENVDIR/bin/activate</p><p>cd $KUBESPRAYDIR</p><p>pip install -U -r requirements.txt</p><p>(kubespray-venv) root@ip-10–0–6–164:~/kubespray# cp -rfp inventory/sample inventory/mycluster</p><p># Update Ansible inventory file with inventory builder (can get the ips from private subnet’s instances )</p><p>(kubespray-venv) root@ip-10–0–6–164:~/kubespray# cp -rfp inventory/sample inventory/mycluster</p><p>(kubespray-venv) root@ip-10–0–6–164:~/kubespray# declare -a IPS=(10.0.132.196 10.0.139.71 10.0.129.9 10.0.133.26 10.0.130.58 10.0.130.235)</p><p>(kubespray-venv) root@ip-10–0–6–164:~/kubespray# CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}</p><p>3.3. Before running the final playbook, make changes to the inventory (inventory/mycluster/hosts.yaml) by adding the ansible_user: ubuntu argument as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*Re31iODCsR8Yooyt2b4J2g.jpeg" /></figure><p>3.4 At the end, run the final playbook</p><pre>(kubespray-venv) root@ansible-controller:~/kubespray#ansible-playbook -i inventory/mycluster/hosts.yaml --become  --become-user=root cluster.yml</pre><p>After a couple of minutes, you will see the Ansible output like below. Since there are no failed results, the playbook seems to have been deployed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcNAggzZgb1gcwkK46u7cg.jpeg" /></figure><p>Since I defined node1 as one of the master nodes, we can SSH to it as shown below:</p><p>root@ansible-controller:~# ssh ubuntu@10.0.132.196</p><p>switch to the root user and run kubectl commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*wCXbPiib8y23P6aKThzSBQ.jpeg" /></figure><p>I deployed the default sample cluster, but you can customize the playbooks according to your cluster requirements and different cloud platforms. Don’t forget to refer to <a href="https://kubespray.io/#/">https://kubespray.io/#/</a> for additional information . In the next story, I enhanced the approach by adding more automation via Terraform in below link.</p><p><a href="https://medium.com/@hamedsol/deploying-a-production-level-kubernetes-cluster-on-aws-by-kubespray-and-terraform-security-best-3ede6f66fd68">Deploying a Production-Level Kubernetes Cluster on AWS by kubespray and Terraform — Security Best…</a></p><p>Practical git course :</p><p><a href="https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3">https://www.udemy.com/course/git-in-practice-real-world-version-control/?referralCode=344583629B331AD227A3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0fa99b910b35" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>