<?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 Stephen kanyi on Medium]]></title>
        <description><![CDATA[Stories by Stephen kanyi on Medium]]></description>
        <link>https://medium.com/@StephenKanyiW?source=rss-83322ea202d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6qzHZn-KWiwXlBUQ.jpeg</url>
            <title>Stories by Stephen kanyi on Medium</title>
            <link>https://medium.com/@StephenKanyiW?source=rss-83322ea202d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:25:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@StephenKanyiW/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[Deploy AWS Managed Prometheus (AMP) and AWS Managed Grafana (AMG) With Terraform for scalable…]]></title>
            <link>https://towardsdev.com/deploy-aws-managed-prometheus-amp-and-aws-managed-grafana-amg-with-terraform-for-scalable-4286a9089eb0?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4286a9089eb0</guid>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Wed, 23 Aug 2023 16:49:14 GMT</pubDate>
            <atom:updated>2023-08-24T16:49:13.839Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploy AWS Managed Prometheus (AMP) and AWS Managed Grafana (AMG) With Terraform for scalable observability on the EKS Cluster.</h3><p><a href="https://github.com/Skanyi/terraform-projects/tree/main/monitoring">GitHub Repository</a></p><p><a href="https://www.stephenkanyi.com/devops/eks/aws/terraform/helm/prometheus/grafana/amp/amg/2023/08/14/Deploy-AWS-Managed-Prometheus-(AMP)-and-AWS-Managed-Grafana-(AMG)-With-Terraform-for-scalable-observibility-on-EKS-Cluster.html">Personal Blog</a></p><h3>Prerequisite</h3><p>Before we proceed to deploy AMP and AMG using Terraform, there are a few commands or tools you need to have in the server where you will be executing the Terraform scripts.</p><pre>1. awscli<br>2. go<br>3. Terraform<br>4. kubectl<br>5. helm</pre><h4>Assumptions</h4><p>The following details make the following assumptions.</p><pre>You have aws cli configured.<br><br>You have created s3 bucket that will act as the backend of the project.</pre><h4>Quick Setup</h4><p>Clone the repository if you have not cloned it already:</p><pre>git clone https://github.com/Skanyi/terraform-projects.git</pre><p>Change directory;</p><pre>cd terraform-projects/monitoring</pre><p>Update the backend.tf and update the s3 bucket and the region of your s3 bucket. Update the profile if you are not using the default profile.</p><p>Update the variables.tf profile variable if you are not using the default profile.</p><p>Update the secret.tfvars file with the output values of the <a href="https://github.com/Skanyi/terraform-projects/tree/main/eks">Setting up EKS Cluster with Terraform, Helm and a Load balancer module</a>.</p><p>Format the project</p><pre>terraform fmt</pre><p>Initialize the project to pull all the modules used</p><pre>terraform init</pre><p>Validate that the project is correctly set up.</p><pre>terraform validate</pre><p>Run the plan command to see all the resources that will be created</p><pre>terraform plan — var-file=”secret.tfvars”</pre><p>When you are ready, run the apply command to create the resources.</p><pre>terraform apply — var-file=”secret.tfvars”</pre><h4>Detailed Setup Steps.</h4><p>When the above setup is done, we are now ready to deploy AMP and AMG in our previously created cluster. If you have not created the cluster, follow the steps outlined here <a href="https://www.stephenkanyi.com/devops/eks/aws/terraform/helm/2023/07/04/provision-fully-private-eks-cluster-with-terraform.html">Setting up EKS with Terraform, Helm, and a Load balancer In this step.</a></p><h4>Deploy AWS Managed Service for Grafana (AMG)</h4><p>Before creating the AMG, we need to ensure that the AWS-SSO is enabled to be able to access the Grafana workspace.</p><p>The following documentation details how to use <a href="https://docs.aws.amazon.com/grafana/latest/userguide/getting-started-with-AMG.html">AWS IAM Identity Center (successor to AWS Single Sign-On)</a> with your Amazon Managed Grafana workspace.</p><p>When you have AWS Single Sign-On setup, continue with the next steps.</p><p>1. Create the AMG using the <a href="https://registry.terraform.io/modules/terraform-aws-modules/managed-service-grafana/aws/latest">AWS Managed Service for Grafana (AMG) Terraform module</a></p><p>Note the variable var.sso_admin_group_id. Make sure you have updated the secret.tfvars with a valid value from AWS SSO Group.</p><pre>module &quot;managed_grafana&quot; {<br>source = &quot;terraform-aws-modules/managed-service-grafana/aws&quot;<br><br>providers = {<br>    aws = aws.us-east-2<br>}<br><br># Workspace<br>name                      = &quot;eks-grafana&quot;<br>description               = &quot;AWS Managed Grafana service&quot;<br>account_access_type       = &quot;CURRENT_ACCOUNT&quot;<br>authentication_providers  = [&quot;AWS_SSO&quot;]<br>permission_type           = &quot;SERVICE_MANAGED&quot;<br>data_sources              = [&quot;CLOUDWATCH&quot;, &quot;PROMETHEUS&quot;, &quot;XRAY&quot;]<br>notification_destinations = [&quot;SNS&quot;]<br><br>create_workspace      = true<br>create_iam_role       = true<br>create_security_group = true<br>associate_license     = false<br>license_type          = &quot;ENTERPRISE_FREE_TRIAL&quot;<br>vpc_configuration = {<br>    subnet_ids = var.private_subnets<br>}<br><br>security_group_rules = {<br>    egress = {<br>    from_port        = 0<br>    to_port          = 0<br>    protocol         = &quot;-1&quot;<br>    cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>    }<br>}<br># Workspace API keys<br>workspace_api_keys = {<br>    viewer = {<br>    key_name        = &quot;viewer&quot;<br>    key_role        = &quot;VIEWER&quot;<br>    seconds_to_live = 3600<br>    }<br>    editor = {<br>    key_name        = &quot;editor&quot;<br>    key_role        = &quot;EDITOR&quot;<br>    seconds_to_live = 3600<br>    }<br>    admin = {<br>    key_name        = &quot;admin&quot;<br>    key_role        = &quot;ADMIN&quot;<br>    seconds_to_live = 3600<br>    }<br>}<br><br><br># Role associations<br>role_associations = {<br>    &quot;ADMIN&quot; = {<br>    &quot;group_ids&quot; = [var.sso_admin_group_id]<br>    }<br>}<br><br>tags = {<br>    Terraform   = &quot;true&quot;<br>    Environment = var.env_name<br>}<br>}</pre><h4>Deploy AWS Managed Service for Prometheus (AMP)</h4><p>Prometheus requires an Amazon EBC CSI driver to be installed in your cluster. This driver allows your cluster to manage the lifecycle of Amazon EBS volumes for persistent volumes. Update the <a href="https://github.com/Skanyi/terraform-projects/tree/main/eks">Setting up EKS Cluster with Terraform, Helm, and a Load balancer</a> and add the Amazon EBS volume addon. Also, add AmazonEBSCSIDriverPolicy to the NodeGroups.</p><pre>cluster_addons = {<br>aws-ebs-csi-driver = {<br>    most_recent = true<br>    }<br>}<br><br>eks_managed_node_group_defaults = {<br>    iam_role_additional_policies = {<br>    AmazonEBSCSIDriverPolicy = &quot;arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy&quot;<br>    }<br>}</pre><p>1. Create the AWS Managed Service for Prometheus (AMP) <a href="https://registry.terraform.io/modules/terraform-aws-modules/managed-service-prometheus/aws/latest">Terraform module</a></p><pre>module &quot;prometheus&quot; {<br>source = &quot;terraform-aws-modules/managed-service-prometheus/aws&quot;<br><br>workspace_alias  = &quot;eks-workspace&quot;<br>create_workspace = true<br><br>providers = {<br>    aws = aws.us-east-2<br>}<br><br>alert_manager_definition = &lt;&lt;-EOT<br>alertmanager_config: |<br>    route:<br>    receiver: &#39;default&#39;<br>    receivers:<br>    - name: &#39;default&#39;<br>EOT<br><br>rule_group_namespaces = {<br>    first = {<br>    name = &quot;rule-01&quot;<br>    data = &lt;&lt;-EOT<br>    groups:<br>        - name: test<br>        rules:<br>        - record: metric:recording_rule<br>            expr: avg(rate(container_cpu_usage_seconds_total[5m]))<br>    EOT<br>    }<br>    second = {<br>    name = &quot;rule-02&quot;<br>    data = &lt;&lt;-EOT<br>    groups:<br>        - name: test<br>        rules:<br>        - record: metric:recording_rule<br>            expr: avg(rate(container_cpu_usage_seconds_total[5m]))<br>    EOT<br>    }<br>}<br>}</pre><p>2. Namespace — Create a namespace where we are going to deploy the Prometheus server in the EKS Cluster.</p><pre>resource &quot;kubernetes_namespace&quot; &quot;prometheus-namespace&quot; {<br> metadata {<br>     annotations = {<br>     name = &quot;monitoring&quot;<br>     }<br><br>     labels = {<br>     application = &quot;monitoring&quot;<br>     }<br><br>     name = &quot;monitoring&quot;<br> }<br> }</pre><p>3. Role — Create a role that we are going to annotate the Service Account used by the Prometheus server.</p><pre>module &quot;prometheus_role&quot; {<br> source = &quot;terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks&quot;<br><br> role_name                                        = &quot;${var.env_name}_prometheus&quot;<br> attach_amazon_managed_service_prometheus_policy  = true<br> amazon_managed_service_prometheus_workspace_arns = [module.prometheus.workspace_arn]<br><br> oidc_providers = {<br>     main = {<br>     provider_arn               = var.oidc_provider_arn<br>     namespace_service_accounts = [&quot;${kubernetes_namespace.prometheus-namespace.metadata[0].name}:amp-iamproxy-ingest-role&quot;]<br>     }<br> }<br><br> }</pre><p>4. Service Account — Create a service account that the Prometheus server is going to use to access the AMP service.</p><pre>resource &quot;kubernetes_service_account&quot; &quot;service-account&quot; {<br> metadata {<br>     name      = &quot;amp-iamproxy-ingest-role&quot;<br>     namespace = kubernetes_namespace.prometheus-namespace.metadata[0].name<br>     labels = {<br>     &quot;app.kubernetes.io/name&quot; = &quot;prometheus&quot;<br>     }<br>     annotations = {<br>     &quot;eks.amazonaws.com/role-arn&quot;               = module.prometheus_role.iam_role_arn<br>     &quot;eks.amazonaws.com/sts-regional-endpoints&quot; = &quot;true&quot;<br>     }<br> }<br> }</pre><p>5. Deployment — Install the Prometheus server with Helm.</p><p>templates/amp_ingest_override_values.yaml can be customized to meet your configuration desire for the AMP server deployment.</p><pre>resource &quot;helm_release&quot; &quot;prometheus&quot; {<br> name       = &quot;prometheus-community&quot;<br> repository = &quot;https://prometheus-community.github.io/helm-charts&quot;<br> chart      = &quot;prometheus&quot;<br> version    = &quot;23.1.0&quot;<br> namespace  = kubernetes_namespace.prometheus-namespace.metadata[0].name<br> depends_on = [<br>     kubernetes_service_account.service-account<br> ]<br><br> values = [<br>     &quot;${file(&quot;${path.module}/templates/amp_ingest_override_values.yaml&quot;)}&quot;<br> ]<br><br> set {<br>     name  = &quot;server.remoteWrite[0].url&quot;<br>     value = &quot;${module.prometheus.workspace_prometheus_endpoint}api/v1/remote_write&quot;<br> }<br><br> set {<br>     name  = &quot;server.remoteWrite[0].sigv4.region&quot;<br>     value = var.main-region<br> }<br><br> }</pre><p>When the above is done, use the following commands to confirm if the Prometheus server was deployed successfully.</p><pre>kubectl get all -n monitoring</pre><h4>Deploy VPC endpoints</h4><p>1. Security Group — Create a security group that will be attached to the VPC Endpoints. Allow traffic from the Grafana Security group.</p><pre>resource &quot;aws_security_group&quot; &quot;allow_tls_grafana&quot; {<br> name        = &quot;allow_tls_from_grafana&quot;<br> description = &quot;Allow TLS inbound traffic from Grafana&quot;<br> vpc_id      = var.vpc_id<br> provider    = aws.us-east-2<br> ingress {<br>     description     = &quot;TLS from Grafana Security group&quot;<br>     from_port       = 443<br>     to_port         = 443<br>     protocol        = &quot;tcp&quot;<br>     security_groups = [var.grafana_security_group_id]<br> }<br><br> egress {<br>     from_port        = 0<br>     to_port          = 0<br>     protocol         = &quot;-1&quot;<br>     cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>     ipv6_cidr_blocks = [&quot;::/0&quot;]<br> }<br><br> tags = {<br>     Name        = &quot;allow_tls_grafana&quot;<br>     Terraform   = &quot;true&quot;<br>     Environment = var.env_name<br> }<br> }</pre><p>2. Prometheus VPC Endpoint — Create the Prometheus VPC Endpoint</p><pre>resource &quot;aws_vpc_endpoint&quot; &quot;prometheus&quot; {<br> vpc_id            = var.vpc_id<br> provider          = aws.us-east-2<br> service_name      = &quot;com.amazonaws.us-east-2.aps-workspaces&quot;<br> vpc_endpoint_type = &quot;Interface&quot;<br><br> security_group_ids = [<br>     aws_security_group.allow_tls_grafana.id,<br> ]<br><br> subnet_ids = var.private_subnets<br> }</pre><h4>Access the Grafana workspace and create Dashboards</h4><p>Add Prometheus as the data source in Grafana Workspace without the /api/v1/query on the URL. Select AWS SDK as the authentication provider and update the region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*VdXyzzO_eU1zx1dGLts5aw.png" /></figure><p>When the above is done, click on save and test and you should see the Data source is working message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*EApgEgAMoxQ2BJ0iVMBs3A.png" /></figure><p>Create a sample dashboard by importing a sample dashboard from Grafana. Search a dashboard 3119 and import it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fkg_Rf3_67O3GNHDTgdi3w.png" /></figure><p>When the dashboard is imported, give it a moment and it should populate and look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6an0PKmrxa62oX07Wp_Cg.png" /></figure><p>At this moment you have both AMP and AMG configured with a sample dashboard. Grafana dashboards can be created to monitor the metrics important to you in your EKS cluster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4286a9089eb0" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/deploy-aws-managed-prometheus-amp-and-aws-managed-grafana-amg-with-terraform-for-scalable-4286a9089eb0">Deploy AWS Managed Prometheus (AMP) and AWS Managed Grafana (AMG) With Terraform for scalable…</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Provision EKS with Terraform, Helm, and a Load Balancer Controller,]]></title>
            <link>https://medium.com/@StephenKanyiW/provision-eks-with-terraform-helm-and-a-load-balancer-controller-821dacb35066?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/821dacb35066</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 16:48:24 GMT</pubDate>
            <atom:updated>2023-07-20T16:48:24.091Z</atom:updated>
            <content:encoded><![CDATA[<h3>Provision EKS with Terraform, Helm, and a Load Balancer Controller.</h3><h3>Setting up EKS with Terraform, Helm, and a Load balancer</h3><p><a href="https://github.com/Skanyi/terraform-projects/tree/main/eks">GitHub Repository</a></p><p><a href="https://www.stephenkanyi.com/devops/eks/aws/terraform/helm/2023/07/04/provision-fully-private-eks-cluster-with-terraform.html">Personal Blog</a></p><h3>Prerequisite</h3><p>Before we proceed and provision EKS Cluster using Terraform, there are a few commands or tools you need to have in the server where you will be creating the cluster from.</p><pre>1. awscli - aws-cli/2.12.1 Python/3.11.3</pre><pre>2. go version go1.18.9 linux/amd64</pre><pre>3. Terraform v1.5.0</pre><pre>4. kubectl - Client Version: v1.23.17-eks</pre><pre>5. helm - v3.8.0</pre><h3>Assumptions</h3><p>The following details make the following assumptions.</p><pre>You have aws cli configured<br><br>You have created s3 bucket that will act as the backend of the project.</pre><h3>Quick Setup</h3><p>Clone the repository:</p><pre>git clone https://github.com/Skanyi/terraform-projects.git</pre><p>Change directory;</p><pre>cd terraform-projects/eks</pre><p>Update the backend.tf and update the s3 bucket and the region of your s3 bucket. Update the profile if you are not using the default profile.</p><p>Update the variables.tf profile variable if you are not using the default profile.</p><p>If the is a role you want to add to be able to access the EKS cluster created, create the following environment variable.</p><pre>TF_VAR_rolearn</pre><p>If there is no role to add, disable adding a role to the config map by commenting out the following field in modules/eks-cluster/main.tf</p><pre>manage_aws_auth_configmap = true</pre><p>Initialize the project to pull all the modules used</p><pre>terraform init</pre><p>Validate that the project is correctly set up.</p><pre>terraform validate</pre><p>Run the plan command to see all the resources that will be created</p><pre>terraform plan</pre><p>When you are ready, run the apply command to create the resources.</p><pre>terraform apply</pre><h3>Detailed Setup Steps.</h3><p>Creating an EKS cluster falls under the DevOps Engineer role and sometimes it can be very common to create a cluster several times. In this article, I will share how I create an EKS cluster using Terraform and Install an ALB controller in the cluster. We will also create a sample application that will be exposed using an Application load balancer created with Ingress.</p><h3>Architecture</h3><p>The following diagram shows the core resources that we will be creating in AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/0*0S5QB9eo_4abBxrq.png" /></figure><p>A VPC will be created with three Public Subnets and three Private Subnets in three different Availability Zones. Traffic from Private Subnets will route through the NAT Gateway and traffic from Public Subnets will route through the Internet Gateway.</p><p>Kubernetes Cluster Nodes will be created as part of Auto-Scaling groups and will reside in Private Subnets. The Application Load balancer will be created in the Public Subnets.</p><h3>Setting up EKS</h3><ol><li>Create a VPC where to deploy the cluster. For this, I used the <a href="https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest">VPC module</a>.</li></ol><pre>module &quot;vpc&quot; {<br> source  = &quot;terraform-aws-modules/vpc/aws&quot;<br> version = &quot;5.0.0&quot;<br><br> name = &quot;eks-vpc&quot;<br> cidr = &quot;10.0.0.0/16&quot;<br><br> providers = {<br>     aws = aws.us-east-2<br> }<br><br> azs = [&quot;us-east-2a&quot;, &quot;us-east-2b&quot;, &quot;us-east-2c&quot;]<br> #private_subnets     = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]<br> #public_subnets      = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 4)]<br> private_subnets = [&quot;10.0.1.0/24&quot;, &quot;10.0.2.0/24&quot;, &quot;10.0.3.0/24&quot;]<br> public_subnets  = [&quot;10.0.101.0/24&quot;, &quot;10.0.102.0/24&quot;, &quot;10.0.103.0/24&quot;]<br><br> enable_nat_gateway = true<br><br> public_subnet_tags = {<br>     &quot;kubernetes.io/role/elb&quot; = 1<br> }<br><br> private_subnet_tags = {<br>     &quot;kubernetes.io/role/internal-elb&quot; = 1<br> }<br><br> tags = {<br>     Terraform   = &quot;true&quot;<br>     Environment = &quot;dev&quot;<br> }<br> }</pre><p>2. Create the EKS cluster using the <a href="https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest">EKS terraform module</a></p><pre>module &quot;eks&quot; {<br> source  = &quot;terraform-aws-modules/eks/aws&quot;<br> version = &quot;~&gt; 19.0&quot;<br><br> cluster_name    = &quot;tf-cluster&quot;<br> cluster_version = &quot;1.27&quot;<br><br> providers = {<br>     aws = aws.us-east-2<br> }<br><br> cluster_endpoint_public_access = true<br><br> create_kms_key              = false<br> create_cloudwatch_log_group = false<br> cluster_encryption_config   = {}<br><br> cluster_addons = {<br>     coredns = {<br>     most_recent = true<br>     }<br>     kube-proxy = {<br>     most_recent = true<br>     }<br>     vpc-cni = {<br>     most_recent = true<br>     }<br> }<br><br> vpc_id                   = var.vpc_id<br> subnet_ids               = var.private_subnets<br> control_plane_subnet_ids = var.private_subnets<br><br> # EKS Managed Node Group(s)<br> eks_managed_node_group_defaults = {<br>     instance_types = [&quot;m5.xlarge&quot;, &quot;m5.large&quot;, &quot;t3.medium&quot;]<br> }<br><br> eks_managed_node_groups = {<br>     blue = {}<br>     green = {<br>     min_size     = 1<br>     max_size     = 10<br>     desired_size = 1<br><br>     instance_types = [&quot;t3.large&quot;]<br>     capacity_type  = &quot;SPOT&quot;<br>     }<br> }<br><br> tags = {<br>     env       = &quot;dev&quot;<br>     terraform = &quot;true&quot;<br> }<br> }</pre><h3>Adding the Load Balancer Controller</h3><p>Before we can install the Application load balancer controller, we need to create a role, policy, and service account that the controller will use.</p><ol><li>We create a role using the module <a href="https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-for-service-accounts-eks">iam-role-for-service-accounts-eks</a> which will create the required policy when attach_load_balancer_controller_policy is set to true.</li></ol><pre>module &quot;lb_role&quot; {<br> source = &quot;terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks&quot;<br><br> role_name                              = &quot;${var.env_name}_eks_lb&quot;<br> attach_load_balancer_controller_policy = true<br><br> oidc_providers = {<br>     main = {<br>     provider_arn               = var.oidc_provider_arn<br>     namespace_service_accounts = [&quot;kube-system:aws-load-balancer-controller&quot;]<br>     }<br> }<br> }</pre><p>2. We create a service account that is annotated with the role created in the above step.</p><pre>resource &quot;kubernetes_service_account&quot; &quot;service-account&quot; {<br> metadata {<br>     name      = &quot;aws-load-balancer-controller&quot;<br>     namespace = &quot;kube-system&quot;<br>     labels = {<br>     &quot;app.kubernetes.io/name&quot;      = &quot;aws-load-balancer-controller&quot;<br>     &quot;app.kubernetes.io/component&quot; = &quot;controller&quot;<br>     }<br>     annotations = {<br>     &quot;eks.amazonaws.com/role-arn&quot;               = module.lb_role.iam_role_arn<br>     &quot;eks.amazonaws.com/sts-regional-endpoints&quot; = &quot;true&quot;<br>     }<br> }<br> }</pre><p>3. Finally, we install the AWS load balancer controller.</p><pre>resource &quot;helm_release&quot; &quot;alb-controller&quot; {<br> name       = &quot;aws-load-balancer-controller&quot;<br> repository = &quot;https://aws.github.io/eks-charts&quot;<br> chart      = &quot;aws-load-balancer-controller&quot;<br> namespace  = &quot;kube-system&quot;<br> depends_on = [<br>     kubernetes_service_account.service-account<br> ]<br><br> set {<br>     name  = &quot;region&quot;<br>     value = var.main-region<br> }<br><br> set {<br>     name  = &quot;vpcId&quot;<br>     value = var.vpc_id<br> }<br><br> set {<br>     name  = &quot;image.repository&quot;<br>     value = &quot;602401143452.dkr.ecr.${var.main-region}.amazonaws.com/amazon/aws-load-balancer-controller&quot;<br> }<br><br> set {<br>     name  = &quot;serviceAccount.create&quot;<br>     value = &quot;false&quot;<br> }<br><br> set {<br>     name  = &quot;serviceAccount.name&quot;<br>     value = &quot;aws-load-balancer-controller&quot;<br> }<br><br> set {<br>     name  = &quot;clusterName&quot;<br>     value = var.cluster_name<br> }<br> }</pre><h3>Cleanup the Resources we Created</h3><p>When we are done testing the setup and don’t require the resources created anymore, we can use the steps below to remove them.</p><pre>terraform init<br><br>terraform destroy</pre><p>If you get errors deleting the resources, remove the .terraform folder and destroy it again.</p><pre>rm -rf .terraform<br>terraform destroy</pre><h3>Conclusion of Terraform Kubernetes Deployment</h3><p>Elastic Kubernetes Service (EKS) is a managed Kubernetes service provided by AWS, which takes the complexity and overhead out of provisioning and optimizing a Kubernetes Cluster for development teams.</p><p>An EKS Cluster can be created using a variety of methods; nevertheless, using the best possible way is critical in improving the infrastructure management lifecycle.</p><p>The above method is just one of the methods that can be used to create the EKS clusters.</p><h3>Next Steps</h3><p>The following project deploys a sample nginx application and creates a load balancer that can be used to access the application.</p><p><a href="https://www.stephenkanyi.com/devops/eks/aws/terraform/helm/loadbalancer/2023/07/11/Deploy-sample-application-and-Create-a-Load-Balancer-Using-Terraform-to-EKS-Cluster.html">Deploy sample application and create a Load Balancer Using Terraform to EKS Cluster</a></p><p>Throughout the setup, I referenced heavily from the following sources.</p><p>[1] AWS VPC Terraform module — <a href="https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest">https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest</a></p><p>[2] AWS EKS Terraform module — <a href="https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest">https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest</a></p><p>[3] IAM Role for Service Accounts in EKS — <a href="https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-for-service-accounts-eks">https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-role-for-service-accounts-eks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=821dacb35066" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup OSSEC + ELK +Application Servers Architecture Using Ansible]]></title>
            <link>https://medium.com/@StephenKanyiW/setup-ossec-elk-application-servers-architecture-using-ansible-791765fbe5e0?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/791765fbe5e0</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ossec]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Tue, 24 Sep 2019 13:28:34 GMT</pubDate>
            <atom:updated>2019-09-24T13:28:34.932Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, I have been playing with a setup to monitor the host intrusions. To do that, I use <strong>OSSEC Software</strong> which is an open-source project. I then ship the OSSEC logs to ELK for monitoring. To simulate a simple organization setup, I added an application server which will also be monitored by OSSEC agent and also send Nginx logs to ELK server.</p><p><strong>Technologies:</strong></p><p>OSSEC(OSSEC Server and OSSEC agents), Elastic Stack, Filebeat, Python3, Gunicorn, Nginx, Ansible, Vagrant.</p><p>The Illustration below gives an overview of the Setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6Dnceox1-N1YpZELrE94w.jpeg" /><figcaption>OSSEC + ELK + App Setup</figcaption></figure><p>Here is the full project in Github: <a href="https://github.com/Skanyi/OSSEC-ELK-Application-Servers-Setup">Full Project</a>. For a quick setup of this project, check the README.md on the GitHub repo.</p><p><strong>Prerequisites:</strong></p><p>Before you can run the ansible configuration playbook, you need to have/do a few things.</p><p>3 Ubuntu Servers — In this case, I used Vagrant and virtualbox to start 3 servers.</p><p>Using the snippet Vagrantfile, I can start the 3 servers. the bootstrap.sh is just to ensure we have python installed. You can customize it as you wish. Also, we assign elk-server CPU to 2 and increase its memory size to 4gb to be able to run Elastic Stack. Additionally, we copy the ssh key to the servers to be able to ssh to the machines. Generate one if you don’t have any. ssh-keygen</p><pre>servers = {<br>     &quot;ossec-server&quot; =&gt; { :ip =&gt; &quot;192.168.33.10&quot;, :cpus =&gt; 1, :mem =&gt; 1024 },<br>     &quot;elk-server&quot; =&gt; { :ip =&gt; &quot;192.168.33.11&quot;, :cpus =&gt; 2, :mem =&gt; 4096 },<br>     &quot;app-server&quot; =&gt; { :ip =&gt; &quot;192.168.33.12&quot;, :cpus =&gt; 1, :mem =&gt; 1024 }<br> }<br>Vagrant.configure(2) do |config|<br>     servers.each_with_index do | (hostname, info), index|<br>        config.vm.define hostname do |config|<br>            config.vm.provider :virtualbox do |vb, override|<br>                config.vm.box = &quot;ubuntu/bionic64&quot;<br>      config.vm.provision :shell, path: &quot;bootstrap.sh&quot;<br>                override.vm.network :private_network, ip: &quot;#{info[:ip]}&quot;<br>                override.vm.hostname = hostname<br>                vb.name = hostname<br>                vb.customize [&quot;modifyvm&quot;, :id, &quot;--memory&quot;, info[:mem], &quot;--cpus&quot;, info[:cpus], &quot;--hwvirtex&quot;, &quot;on&quot;]<br>            <br>            config.ssh.insert_key = false<br>            config.ssh.private_key_path = [&#39;~/.vagrant.d/insecure_private_key&#39;,<br>            &#39;~/.ssh/ossec&#39;]<br>            config.vm.provision &quot;file&quot;, source: &quot;~/.ssh/ossec.pub&quot;, destination:<br>            &quot;~/.ssh/authorized_keys&quot;<br>            end<br>         end<br>     end<br> end</pre><p>bootstrap.sh</p><pre>#!/usr/bin/env bash</pre><pre>sudo apt-get update<br>sudo apt-get install -y python3<br>sudo apt-get install -y aptitude<br>sudo apt-get install -y ifupdown</pre><p>We are going to use ansible to configure all the servers, but before we can do that. We need to setup ansible on a local machine that we will use to run ansible-playbook.</p><p><strong>Setup Ansible</strong></p><p>Install Ansible on the local machine that we will use to configure the clients&#39; machines we created above. Ansible uses ssh to connect to the machines removing the need to install an agent on the clients.</p><p><strong>Install Ansible:</strong></p><pre>sudo apt update<br>sudo apt install software-properties-common<br>sudo apt-add-repository ppa:ansible/ansible<br>sudo apt update<br>sudo apt install ansible</pre><p><strong>Setup Ansible Hosts:</strong></p><p>Edit /etc/ansible/hosts and add another group at the end named servers which will define the host servers we want to control with Ansible.</p><pre>[servers]<br>ossec ansible_host=192.168.33.10<br>elk ansible_host=192.168.33.11<br>app ansible_host=192.168.33.12</pre><p>If you try to ping the hosts with ansible right now, ansible -m ping allyou will most likely get Failed to connect error to host via ssh . To resolve this, create a directory named group_vars and a file under the group name servers.</p><pre>sudo mkdir /etc/ansible/group_vars<br>sudo touch /etc/ansible/group_vars/servers</pre><p>Add the following block to the server&#39;s file created above, and now ansible will connect to the host using the root user.</p><pre>---<br>ansible_user: root</pre><p>At this moment, if you configured everything correctly, you should be able to ping the hosts. ansible -m ping all or you can ping using the alias name. I.e ansible -m ping ossec.</p><pre>app | SUCCESS =&gt; {<br>    &quot;ansible_facts&quot;: {<br>        &quot;discovered_interpreter_python&quot;: &quot;/usr/bin/python3&quot;<br>    }, <br>    &quot;changed&quot;: false, <br>    &quot;ping&quot;: &quot;pong&quot;<br>}</pre><blockquote>At this we point we can start Configuring the host servers</blockquote><h3><strong>Configure OSSEC Server(manager)</strong></h3><p>Start by the initial setup that includes creating directories and files. On your working directory; Copy /etc/ansible/ansible.cfg , create a site.ymlfile that will use to run the playbook. Create inventory and roles directories. Copy the /etc/ansible/hosts to /inventory/hosts. Finally, create directories of each role under the roles directory. Or you can use theansible-galaxy command to created roles, just remember to change directory to roles directory before running the create command.</p><pre>cd roles<br>ansible-galaxy init ossec<br>ansible-galaxy init elk<br>ansible-galaxy init app<br>ansible-galaxy init filebeat<br>ansible-galaxy init ossecagent</pre><p>Paste the following to ossec.yml and import the playbook to site.yml:</p><pre>---<br>- name: ansible site playbook<br>  hosts: &quot;{{ target | default(&#39;ossecservers&#39;) }}&quot;<br>  gather_facts: &quot;{{ gather_facts | default(&#39;true&#39;) }}&quot;<br>  roles:<br>    - ossec</pre><p>Directory Structure should look something like this.</p><pre>.<br>├── ansible.cfg<br>├── bootstrap.sh<br>├── inventory<br>│   └── hosts<br>├── roles<br>│   └── ossec<br>├── site.yml<br>└── Vagrantfile</pre><pre>3 directories, 5 files</pre><p>What we need to install:</p><pre>- build-essential<br>- pexpect<br>- apt-transport-https<br>- filebeat (to send logs to ELK server)</pre><p>Download, extract and run the install.sh script of ossec-hids . We are going to create a role named ossec that will handle all these. Also, create a playbook specifically that only configure the ossec-server and import it to the main playbook. Check the complete role on the Github Repo. Run the playbook with, ansible-playbook -i inventory ossec.yml.</p><p>Add elk and app agents on the server and extract the key. Save the keys as you will need it to configure the OSSEC agents on ELK and Application servers.</p><h3>Configure ELK Server</h3><p>Create an elk.yml similar to ossec.yml only changing the host default to elk and the role to elk. This ensures that the elk role will only configure the elk server.</p><p>What we need to install:</p><pre>java<br>apt-transport-https<br>Nginx<br>Elasticsearch<br>Logstash<br>Kibana</pre><p>Install Elastic stack and ensure that all the components are running.</p><p>Configure Kibana using Nginx to serves the requests.</p><h3>Configure Application Server</h3><p>What we need to Install:</p><pre>Nginx<br>virtualenv<br>python3-pip</pre><p>Start by copying sample helloworld application directory to the server. Use pip to create a virtual environment and install the application dependencies.</p><p>Configure Gunicorn to start the application and use Nginx to proxy the requests.</p><p>Filebeat Role — This role is used to install Filebeat on both application and OSSEC servers.</p><p>Ossecagent Role — This role is used to install OSSEC agents on bothe Elastic stack and application servers. It also Imports the agents&#39; keys generated by the OSSEC role.</p><p><strong>Conclusion:</strong></p><p>This Project is far from perfect but it is a good base for someone who would love to understand ansible, Elastic Stack and all the technologies used in the project.</p><p>Any feedback, improvement or questions are welcome.</p><p>Here is the full project in Github: <a href="https://github.com/Skanyi/OSSEC-ELK-Application-Servers-Setup">Full Project</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=791765fbe5e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MySQL Load Balancing with HAProxy]]></title>
            <link>https://medium.com/@StephenKanyiW/mysql-load-balancing-with-haproxy-46b25b0295dd?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/46b25b0295dd</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[load-balancing]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Thu, 08 Feb 2018 19:09:48 GMT</pubDate>
            <atom:updated>2018-02-19T11:16:07.619Z</atom:updated>
            <content:encoded><![CDATA[<p>Taking it from where we left on the last post where we created master-slave replication. In this post, we going to try and load balance that. We have four servers this time, one HAProxy server, one master server and two slave servers. <strong>NB: I will be sharing the full configurations.</strong></p><p><strong>Lab Servers:</strong></p><pre>HAProxy — 192.168.56.101<br>Master server - 192.168.56.102<br>Slave1 server - 192.168.56.103<br>Slave2 server - 192.168.56.104</pre><p><strong>Create users on mysql servers:</strong></p><p>We start by creating a haproxy_user. The user will be used to check if the instances are are up or not. More like a health check. Since we have replication which is ignoring the mysql database where we are adding the user. We will have to create the user in all mysql servers. If we did not ignore the mysql database, we would only run the command on master and the user should be created in all slaves.</p><pre>mysql -u root -p</pre><pre>USE mysql;</pre><pre>INSERT INTO user (HOST, USER) VALUES(&#39;192.168.56.101&#39;, &#39;haproxy_user&#39;);</pre><pre>flush privileges;</pre><p>Repeat the above commands on the two slaves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqORmJz7XaOQFWdZvfWkdw.png" /><figcaption>creating haproxy_user</figcaption></figure><p>Next we create haproxy_rootthat will have the same access level as root user and will be used to access the databases from the HAProxy server. You can use root(Fail-over need root access to the database), but it is good practice to create another user. Run the following commands in all the mysql servers.(I assume you still in the same session from previous step)</p><pre>GRANT ALL PRIVILEGES ON *.* TO &#39;haproxy_root&#39;@&#39;192.168.56.101&#39; IDENTIFIED BY &#39;haproxy_root_pass&#39; WITH GRANT OPTION;</pre><pre>flush privileges;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHPL9Px_czyVy8hfzCGXQw.png" /><figcaption>create haproxy_root user</figcaption></figure><p><strong>Install mysql-client on HAProxy server:</strong></p><p>In haproxy server we run the following command to install mysql-client. sudo apt-get install mysql-client. Once done, you can confirm it is installed by running mysql command.</p><p><strong>Install and Configure HAProxy:</strong></p><p>We start off by install haproxy in HAProxy server. sudo apt-get install haproxy. It is not enable by default, therefore we have to enable it so that it can start any time the server is rebooted. Edit the file /etc/default/haproxy and set ENABLED=1. That is all you need to do there.</p><p>Next we backup the existing configuration file and edit like below.</p><pre>sudo cp /etc/haproxy/haproxy.cfg{,.original}</pre><p>My final configuration file was</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*LJoBHWLQ_b6dMswyQsq-vw.png" /><figcaption>/etc/haproxy/haproxy.cfg</figcaption></figure><p>The listen stats was added to allow view the setup on the browser. On mysql-cluster, we check the haproxy_user, use roundrobin algorithm. And finally pass the servers.</p><p>When you happy with your configuration, you can check if it is valid before restarting the haproxy service. haproxy -c -V -f /etc/haproxy/haproxy.cfg. If it has errors, fix them until the file is valid. Now you can go ahead and restart the haproxy. sudo service haproxy restart.</p><p><strong>Viewing the Stats:</strong></p><p>If the above setup was successful, you should have something similar to this when you view on the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHCwgiDleScPgpeeurOsFw.png" /></figure><p><strong>Testing Load Balancing and Fail-over:</strong></p><p>Doing a quick test on HAProxy server by querying the for server-id, you can see the result is from all the mysql servers in roundrobin manner.</p><pre>mysql -h 127.0.0.1 -u haproxy_root -p -e &quot;show variables like &#39;server_id&#39;&quot;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWSQ1OUHUYMIqtbEjBIPyA.png" /></figure><p><strong>Conclusion:</strong></p><p>We have successfully set a load-balanced mysql-cluster. See you on the next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46b25b0295dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Master-Slave Replication Using Mysql]]></title>
            <link>https://medium.com/@StephenKanyiW/create-a-master-slave-replication-using-mysql-8b4545a20235?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b4545a20235</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Tue, 06 Feb 2018 20:22:16 GMT</pubDate>
            <atom:updated>2018-02-21T07:51:47.152Z</atom:updated>
            <content:encoded><![CDATA[<p>Prerequisites:</p><p>We need to have two servers, one will act as the master and the other as slave. I will be using Ubuntu.</p><p>Master IP — 192.168.56.102</p><p>Slave IP — 192.168.56.103</p><p>I used vagrant to spin up the servers. Here is the sample of the vagrant file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSM9ePeUmpz7Z36tF8VB0A.png" /><figcaption>Vagrant file</figcaption></figure><p>When you have the two servers up and running. Install mysql-server in both of them.</p><pre>sudo apt-get install mysql-server</pre><p>Ensure to set a password for the root user during installation.</p><p>From here now we can start to configure the master and slave.</p><p><strong>Configure Master Server.</strong></p><p>Open /etc/mysql/my.cnf and comment out bind_address line. From the add the following at the end of [mysqld].</p><pre>server-id = 1<br>log_bin = /var/log/mysql/mysql-bin.log<br>binlog-ignore-db = &quot;mysql&quot;</pre><p>Server-id helps the master/slaves servers to identify each other uniquely. log_bin set the paths where the the master will be dumping its logs. binlog-ignore-db is set to specify on which logs of the db the server should not log into the file. Here you can either set it that way or decide to set binlog-do-db which kind of the same but in this case you specify the database that you want the server to log its logs.</p><p>Restart the mysql service sudo service mysql restart</p><p>Connect to mysql and create a user that will be used for replication. Please note the IP used on the command below is that of slave.</p><pre>mysql -u root -p<br>create user &#39;replica&#39;@&#39;192.168.56.103&#39; identified by &#39;replica&#39;;</pre><pre>grant replication slave on *.* to &#39;replica&#39;@&#39;192.168.56.103&#39; identified by &#39;replica;</pre><pre>flush privileges;</pre><p>From here if there is a specific database that you want to keep track of that already exist, then we need copy the database from master to slave. Connect to the database. Stop read connection to the database and check the master status.</p><pre>flush table with read lock;</pre><pre>show master status;</pre><p>Below is a sample output of the above commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9kylRgz_XAwuDIx8BKzoXQ.png" /><figcaption>master status</figcaption></figure><p>Open another ssh session to export the master server DB. Use mysqldump command.</p><p>mysqldump -u root -p --opt dbname &gt; dbname.sql</p><p>Transfer the exported DB to the slave server. scp dbname.sql vagrant@192.168.56.103:/vagrant The default password for vagrant user is vagrant</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QzmxI73lxuVfiOSMNYeig.png" /><figcaption>scp to slave server</figcaption></figure><p>Finally unlock the table. unlock tables;</p><p><strong>Configure Slave Server.</strong></p><p>If you shipped the DB file to the slave, start by importing it. Ensure you have the DB created before importing.</p><p>mysql -u root -p dbname &lt; dbname.sql</p><p>From here we edit the /etc/mysql/my.cnf like we did in master server.</p><p>Start by commenting out the bind_address line. Then add the following lines at the bottom of [mysqld]</p><pre>server-id = 2</pre><pre>relay-log = /var/log/mysql/mysql-relay-bin.log</pre><pre>bin_log = /var/log/mysql/mysql-bin.log</pre><pre>binlog-ignored-db = &quot;mysql&quot;</pre><p>The relay-log is used by the slave server to synchronize with the master. If you don’t set it, mysql uses the hostname. Finally save the file and exit. Restart mysql service. sudo service mysql restart</p><p>Login to mysql server, mysql -u root -p</p><p>Finally we ready to connect the master server with the file name and position on slave server so that we can have a complete and automatic replication. We start by stopping the slave with stop slave;</p><pre>change master to master_host=&#39;192.168.56.102&#39;, master_user=&#39;replica&#39;, master_password=&#39;replica&#39;, master_log_file=&#39;mysql-bin.000001&#39;, master_log_pos=624;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uk2FLNQ1qVcXH15QMo9XJg.png" /></figure><p>Start the slave start slaveand can go ahead to check the status of the slave to ensure there is no error. show slave status \G Below is an output of my slave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-tMyeuQEHvEzhEqk8-7tw.png" /><figcaption>slave status</figcaption></figure><p><strong>Testing the Replication.</strong></p><p>I will use three scenario to ensure that everything is working perfectly.</p><ol><li>Create a new db on master and check if it is created on slave. create database testdb2; On slave, listing the database, I can see the db created.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*VFzIWviLYoR7SvmP7ZeNlw.png" /></figure><p>2. Create a table in already existing db and see if the replication happens for previously created database. Confirm the table is created on the same database on slave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*T0CgH1rqdSyULaero5VDdA.png" /><figcaption>create test table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*w1uhqrEQ-DmpOFSvwl9oqQ.png" /><figcaption>table list on slave</figcaption></figure><p>3. Insert into a table created in scenario 2. Confirm that the data is added to the table on slave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*__1BKcHSGtSkdv2lgfRzow.png" /><figcaption>Insert in master</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*CUHxZ7h7FOw5rS-w5tIYkg.png" /><figcaption>insert in slave</figcaption></figure><p><strong>Conclusion</strong></p><p>Please not that In my case, the vagrant file has another server that will be used in the next post when load balancing the replicated db. And I also added another slave configured the same way as the slave above.</p><p>Next, I use HAProxy to load balance the above created replication. I added another slave and a HAProxy server. Check the post, <a href="https://medium.com/@StephenKanyiW/mysql-load-balancing-with-haproxy-46b25b0295dd">MySQL Load Balancing with HAProxy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b4545a20235" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Python Application to Google Cloud with Docker and Kubernetes.]]></title>
            <link>https://medium.com/google-cloud/deploy-python-application-to-google-cloud-with-docker-and-kubernetes-db33ee9fbed3?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/db33ee9fbed3</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Sun, 23 Jul 2017 08:15:05 GMT</pubDate>
            <atom:updated>2017-07-23T08:29:49.158Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Deploy Python Application to Google Cloud with Docker and Kubernetes.</strong></p><p>In this post, I will be trying to deploy one of my python application to Google Cloud. I decided to use an existing application to avoid wasting much time showing how to create the application. So let’s get to it.</p><p>Prerequisites:</p><p>Create a project on google cloud.</p><p>Log in to your google cloud account and create a new project if you don’t have one already. I created a project called bucketlist.</p><p>Follow the links to see how to install each of them</p><ul><li><a href="https://www.docker.com/">docker</a></li><li><a href="https://cloud.google.com/sdk/downloads#mac">gcloud</a></li><li>kubernetes — install with gcloud components install kubectl</li></ul><p><strong>Packaging the app in Container and then pushing the google cloud registry.</strong></p><p>Since we already have the application, <a href="https://github.com/andela-skanyi/bucketlist_api">https://github.com/andela-skanyi/bucketlist_api</a></p><p>Now we create the Dockerfile in the root directory.</p><blockquote>FROM python:3.5.2-slim</blockquote><blockquote>RUN mkdir -p /usr/src/app</blockquote><blockquote>WORKDIR /usr/src/app</blockquote><blockquote>COPY requirements.txt /usr/src/app</blockquote><blockquote>RUN apt-get update &amp;&amp; \</blockquote><blockquote>apt-get install -y postgresql python-psycopg2 libpq-dev cython &amp;&amp; \</blockquote><blockquote>pip install — upgrade pip &amp;&amp; pip install -r requirements.txt</blockquote><blockquote>COPY . /usr/src/app</blockquote><blockquote>EXPOSE 50050</blockquote><blockquote>ENTRYPOINT [“python3”]</blockquote><blockquote>CMD [“manage.py” ]</blockquote><p>Then build the image that we will push to google cloud. We will use docker for this. Docker has a build command and since we will push the image to google cloud, we will create the image according to google cloud guidelines.</p><p>They have a naming conventions, gcr.io/[YOUR_PROJECT_ID]/[YOUR_APPLICATION_NAME]</p><pre>docker build -t [DOCKER_IMAGE_NAME]  -f [DOCKERFILE_LOCATION] [APPLICATION_FILE_PATH] </pre><p>In our case this translate to something like ```docker build -t gcr.io/[YOUR_PROJECT_ID]/[YOUR_APPLICATION_NAME]:v1 .```</p><p>Now that we have built the image, we are now going to push it to google registry. To list all the images that you have.</p><pre>docker images</pre><p>To push the image,</p><pre>gcloud docker -- push gcr.io/your-project-id/image-name</pre><p>If you get this error,</p><pre>denied: Please enable Google Container Registry API in Cloud Console at <a href="https://console.cloud.google.com/apis/api/containerregistry.googleapis.com/overview?project=bucketlist-174407">https://console.cloud.google.com/apis/api/containerregistry.googleapis.com/overview?project=y</a>our-project-id before performing this operation.</pre><p>Go to the link and click on enable and retry to push again.</p><p>Create a cluster for the full guide on how to create the cluster, have a look at <a href="https://cloud.google.com/container-engine/docs/clusters/operations">https://cloud.google.com/container-engine/docs/clusters/operations</a></p><pre>gcloud container clusters create staging --zone ZONE</pre><p>The above command will create a cluster called staging in the zone you have specified.</p><p>If you have more than one project, you might want to set the project that you want to create the cluster in with,</p><pre>gcloud config set project &lt;project-id&gt;</pre><h3>Configuring kubectl</h3><p>We are going to configure kubectl so that it can know which cluster to target.</p><pre>gcloud config set project &lt;project-id&gt;<br>gcloud  config set container/cluster staging<br>gcloud config set compute/zone us-east1-c<br>gcloud container clusters get-credentials staging</pre><p>You can combine all these commands to one,</p><pre>gcloud container clusters get-credentials staging --zone us-east1-c --project &lt;project-name&gt;</pre><p>Deploying the app to the cluster.</p><p>We have two options on how we can achieve this.</p><ul><li>On the command line</li><li>Deploy with configuration file</li></ul><p>Option A:</p><pre>kubectl run {deployment_name} --image=gcr.io/$PROJECT_ID/{image-name}:{tag} --port={port}</pre><p>Which translate to in our case,</p><pre>kubectl run bucketlist-api --image=gcr.io/bucketlist-174407/bucketlistapi:latest --port=50050</pre><p>A successful deployment should return deployment “bucketlist-api” created. You can add different variables to the deployment like — env and so on.</p><p>To get the deployment, kubectl get deployment bucketlist-api.</p><p>To observe if the application deployment is up and running, Check the status should be running.</p><pre>kubectl get po <br>or <br>watch kubectl get po</pre><p>Option B:</p><p>We are going to create a deployment file called deployment.yml. Here we can manipulate several things like the environment variables and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*ezBqbedSILTtHvhxj_Ctjw.png" /></figure><p>Notice that I get the Secret key from secretKeyRef, I created a secret deployment file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*9ZgMIt_hQrFO9AJLqHv71g.png" /></figure><p>Now the app is up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*O3KI2aprzkE9q9hKvwODzQ.png" /></figure><p><strong>Expose the app to the Internet</strong></p><p>We can also do this in the terminal, or create a service file,</p><pre>kubectl expose deployment bucketlist-api --type<strong>=</strong>&quot;LoadBalancer&quot;</pre><p>With a service file,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*JYXwsP99mq8dMpv4WzHRbw.png" /></figure><p>To create the service, run</p><pre>kubectl create -f service.yml</pre><p>To list available services, use</p><pre>kubectl get services</pre><p>Use the external IPaddress together with the port to access the app.</p><p><strong>Update or Delete a deployment</strong></p><pre>kubectl edit deployment &lt;name-of-your-deployment&gt;</pre><pre>kubectl delete deployment &lt;name-of-your-deployment&gt;</pre><p><strong>Conclusion,</strong></p><p>We have now deployed our application and exposed it to the outside world.</p><p>Steps:</p><ul><li>Create a dockerfile</li><li>Build an image</li><li>Push it to google registry</li><li>Create a deployment file</li><li>Create secrets deployment file to store the environment variables</li><li>Deploy the application with kubernetes</li><li>Create a service deployment file to expose the app</li><li>Can edit the deployment</li><li>Can also delete the deployment</li></ul><p>There are many things that you can do including scaling the app or even set auto scaling. Feel free to explore beyond.</p><p><strong>What Next?</strong></p><p>I will be automating the deployment pipeline, when the developer pushes the code from their local machine up to the deployed application without breaking the app due to the changes introduced.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db33ee9fbed3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/deploy-python-application-to-google-cloud-with-docker-and-kubernetes-db33ee9fbed3">Deploy Python Application to Google Cloud with Docker and Kubernetes.</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Have Adapted To Andela Community During The Boot-camp]]></title>
            <link>https://medium.com/@StephenKanyiW/how-i-have-adapted-to-andela-community-during-the-boot-camp-e52ec572c443?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e52ec572c443</guid>
            <category><![CDATA[andela]]></category>
            <category><![CDATA[andela-bootcamp]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Mon, 07 Nov 2016 12:34:29 GMT</pubDate>
            <atom:updated>2016-11-07T12:34:29.936Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been a week now, and I have had to adapt to a new schedule that will allow me to handle the Andela work. Before Andela, my usual day always started at around 8:00 am and ends at around 2;00 am. Being in the boot-camp, I have changed my time plans to 5:00 am to 12:00 am.</p><p>Adapting to this has not been a smooth ride as am always faced with fear that I might oversleep and don’t make to the boot-camp on time. I have four alarms that ensure that I will indeed hear one of them within 15 minutes duration. <br>Every day in Andela, I have been learning new skills and improving on the one I have to help me ease interaction with my fellow boot-campers.</p><p>The few days that I have been here, I have realized that being at Andela I must step up of my comfort zone and be outgoing and open-minded that everyone has something to teach me. I have been keen on accepting what I don’t know by always seeking help to those who knows it to help me keep up. Learning quickly. <br>Am not afraid to learn a new skill using the shortest way possible. <br>Week two of the boot-camp started on well, and we were assigned different projects. This being ever my first development project, I have had to learn the few basic of how to set up an environment. Lewis, one of the facilitator, was very helpful in guiding me to the right path and am now confident that when doing another project, setting up an environment will be a piece of cake.</p><p>Finally, I believe that change is inevitable and I have to adapt to the changes by leveraging the resources around me that including the community around me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e52ec572c443" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Andela Boot-Camp: 3rd Day]]></title>
            <link>https://medium.com/@StephenKanyiW/andela-boot-camp-3rd-day-5b4410b01fd9?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b4410b01fd9</guid>
            <category><![CDATA[andela-bootcamp]]></category>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Wed, 02 Nov 2016 16:58:40 GMT</pubDate>
            <atom:updated>2016-11-02T16:58:40.266Z</atom:updated>
            <content:encoded><![CDATA[<p>Wednesday: The day assignment was something not so new but it has been long before i used HTML and CSS. The day started of well on doing the andela labs.</p><p>Binary Search andela proved to be a tough one and hard to crack. After a long interaction with other boot-campers and facilitators. I was able to write a code that was doing something that i wanted it to do.</p><p>Creating a user interface was fun and reminded of how to code with html to create web pages.</p><p>The day could have not been complete if i didn’t learn how to create folders on github repository.</p><p>Andela boot-camp has been engaging and a major learning opportunity for me. I have met people who challenge me and how i think and offer guidance when I don’t understand anything</p><p>I would like to thank Chris, my facilitator for always being available to assist whenever i need his help.</p><p>Thanks Andela for the opportunity at the boot-camp.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b4410b01fd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Andela Boot-camp Experience So Far: Day 1]]></title>
            <link>https://medium.com/@StephenKanyiW/andela-boot-camp-experience-so-far-day-1-30f42aad8f26?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/30f42aad8f26</guid>
            <category><![CDATA[andela]]></category>
            <category><![CDATA[andela-bootcamp]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Tue, 01 Nov 2016 06:03:52 GMT</pubDate>
            <atom:updated>2016-11-01T06:03:52.060Z</atom:updated>
            <content:encoded><![CDATA[<p>Monday: The day started on well with doing the labs, writing a blog post and reading about class.</p><p>The day took a turn when the car class lab could not be submitted and after asking people around including the facilitators, boot-campers and even andela fellows, I couldn’t not solve the problem still.</p><p>During the day we exchanged ideas and challenged each other flow of thinking. It was a progress for me as i learned to create methods in a class.</p><p>Being able to help and be helped by fellow boot-campers shows how much we all can learn from each other. Sharing what we know feels good.</p><p>Finally the lab submitted without me doing any changes to the initial code which only left me wondering if my code was good all along.</p><p>Day two is here and am looking for a great interaction with the guys as we learn about API, a concept that is new to me but eager to learn about it.</p><p>Looking forward to an awesome day. I couldn’t be more happier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30f42aad8f26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Andela Boot-camp Experience So Far]]></title>
            <link>https://medium.com/@StephenKanyiW/andela-boot-camp-experience-so-far-3463c382cca2?source=rss-83322ea202d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3463c382cca2</guid>
            <category><![CDATA[andela-bootcamp]]></category>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Stephen kanyi]]></dc:creator>
            <pubDate>Mon, 31 Oct 2016 04:35:50 GMT</pubDate>
            <atom:updated>2016-10-31T04:35:50.240Z</atom:updated>
            <content:encoded><![CDATA[<p>Andela Boot-camp Experience So Far</p><p>Friday: It is a beautiful day. The day kicked off very well on a high gear. It was full of events and always having something to at all time.</p><p>Interacting with the fellow boot-campers was also something I enjoyed together with our facilitators. The facilitators are friendly and ready to help whenever they can. I can say they are making my boot-camp experience to be an awesome journey. I love their work ethics and code of conduct and by that am sure it will be a lovely experience to work with them.</p><p>During lunch time had a chance to interact with Andelans Fellow and get to know how life is when you in Andela. I can only describe the day with only three words, Fun, Engaging and awesome day.</p><p>I have been busy over the weekends trying to do the labs and everything else that we are suppose to be doing over the week. The weekend has not been that good because I could not check or submit the labs.</p><p>The problem has not only been experienced by me but with other boot-campers. We hope it will be resolved as early as possible.</p><p>Monday morning seems to be a beautiful day. Am looking for a long exciting day.</p><p>Thanks Andela for giving me this Chance. It means a lot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3463c382cca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>