<?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 Agnieszka Pasieka on Medium]]></title>
        <description><![CDATA[Stories by Agnieszka Pasieka on Medium]]></description>
        <link>https://medium.com/@agnieszkapasieka?source=rss-7da4ac8f6c2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dPN0omVCW1mOK14fVWJjhw.png</url>
            <title>Stories by Agnieszka Pasieka on Medium</title>
            <link>https://medium.com/@agnieszkapasieka?source=rss-7da4ac8f6c2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:08:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@agnieszkapasieka/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[The security guardrails I put on every public GitHub repo]]></title>
            <link>https://agnieszkapasieka.medium.com/the-security-guardrails-i-put-on-every-public-github-repo-5ae60074857e?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ae60074857e</guid>
            <category><![CDATA[guardrail]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-repositories]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 21:59:49 GMT</pubDate>
            <atom:updated>2026-11-14T21:59:49.934Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why bother securing a tiny public repo</h3><p>A public repo exposes more than your code: anyone can read your CI config, your workflow permissions, and your full commit history. That raises the security bar rather than lowering it.</p><blockquote><a href="https://nohungrypets.co.uk/">NoHungryPets</a> is my very first vibe-coded project — a free community platform for sharing surplus pet food in the neighbourhood. <br>A single-maintainer project — a static GitHub Pages frontend backed by Firebase, with no server-side code and no security team. It still runs a layered, automated security setup that’s free at this scale, apart from the AI review, which runs on a Claude subscription.</blockquote><p>Here is exactly what is on it, and why, so you can lift the same guardrails onto your own repos.</p><h3>Catch secrets twice</h3><p>The fastest way to compromise a public repo is a committed credential, so catch them in two layers.</p><p>First line: GitHub’s native secret scanning with push protection, free on public repos. It blocks known partner key formats before the push even lands.</p><p>Second line: <a href="https://github.com/agapasieka/nohungrypets/blob/master/.github/workflows/gitleaks.yml">gitleaks</a> in CI as a backup. It catches keys GitHub’s scanner misses, like Google AI Studio or Resend tokens, and reports them in the repo’s Security tab. <br>Tip: run the free gitleaks binary directly rather than the action wrapper, which needs a paid licence for org-owned repos.</p><h3>Keep dependencies current on autopilot</h3><p>An unmaintained dependency is how a quiet repo rots into a vulnerable one, so updates run without me.</p><p><a href="https://github.com/agapasieka/nohungrypets/blob/master/renovate.json">Renovate</a> owns dependency version updates here, driven by a single shared preset so one central policy governs every repo instead of per-repo configs drifting apart. I go deeper on this self-hosted, centralised Renovate setup in <a href="https://medium.com/@agnieszkapasieka/self-hosted-renovate-how-we-centralised-dependency-updates-and-why-not-dependabot-1fdd6688c33a">a separate write-up</a>.</p><p>Dependabot still runs, but for one job only: its security alerts flag known vulnerabilities as a free safety net. It no longer opens version-update PRs — one update bot is plenty, and two just means duplicate noise.</p><h3>Harden the supply chain</h3><p>The riskiest code in your CI is often code you didn’t write: the actions you call.</p><p>Every GitHub Action here is pinned to a full commit SHA rather than a moving tag like @v4. A tag can be quietly re-pointed at malicious code; a SHA can&#39;t. Workflows get read-only access by default, and write access only where a job needs it. Checkouts also set persist-credentials: false so the git token isn&#39;t left lying around for later steps.</p><p>To keep this honest over time, <a href="https://github.com/agapasieka/nohungrypets/blob/master/.github/workflows/scorecard.yml">OpenSSF Scorecard</a> scores the repo’s security every week and flags anything that slips.</p><h3><strong>Scan your own code, too</strong></h3><p>Pinned actions protect you from other people’s code. <a href="https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql">CodeQL</a> checks yours. It’s GitHub’s static analysis, and it’s free on public repos.</p><p>I use the default setup: one switch in Settings, no workflow file to maintain. It scans the JavaScript and the GitHub Actions workflows on every PR and every push to master, plus a weekly run. Findings land in the Security tab next to the gitleaks and Scorecard results.</p><p>The workflow scanning is the part people miss. It catches CI mistakes like feeding untrusted PR titles into a shell command, which can let a stranger run code inside your pipeline.</p><h3>Put a reviewer on every PR</h3><p>Every change gets a second reviewer, using the Claude subscription I already pay for. A <a href="https://github.com/agapasieka/nohungrypets/blob/master/.github/workflows/claude-review.yml">Claude Code review</a> (on the cheap Haiku model) runs via the official action on every PR, posting inline comments on anything it spots, plus one status comment so you know it ran.</p><p>One public-repo catch worth knowing: GitHub withholds secrets from pull requests opened off forks, so secret-dependent jobs like this run only on branches within your own repo. That’s a safe default, not a bug — it stops a stranger’s PR from exfiltrating your tokens.</p><h3>Lock the front door with branch protection</h3><p>All the scanning above only matters if nothing can bypass it. Branch protection on the default branch is what makes the rest enforceable: require a pull request, require the security and review checks to pass before merge, and block direct pushes and force-pushes.</p><p>Working solo? Set required approvals to 0. You can merge your own PRs, but every change still has to pass the checks first.</p><p>It turns every check above from a suggestion into a gate, and it’s one of the things OpenSSF Scorecard rewards.</p><h3>Guard the data, not just the code</h3><p>With no server, the database rules are the backend. Get them wrong and anyone can read or edit your users’ data.</p><p>The <a href="https://github.com/agapasieka/nohungrypets/blob/master/firestore.rules">Firestore rules</a> default to owner-only: people can change only their own records. Admin rights live in a record that can’t be created from the app, so nobody can make themselves an admin.</p><p>The rules file lives in the repo, and a <a href="https://github.com/agapasieka/nohungrypets/blob/master/.github/workflows/firestore-rules-deploy.yml">workflow</a> deploys it on every merge. Rule changes get reviewed like code, and the live rules can’t quietly drift from what’s committed.</p><h3>Make it easy to report a bug</h3><p>Give people a private, obvious way to report a vulnerability and they’ll use it instead of dropping it in a public issue. A short <a href="https://github.com/agapasieka/nohungrypets/blob/master/SECURITY.md">SECURITY.md</a> does the job: it points to GitHub’s private vulnerability reporting with an email fallback, lists what’s in and out of scope, and sets honest response expectations for a solo project.</p><p>It also heads off noise with one clarifying note: the Firebase web API key visible in the client JavaScript is expected and not a secret by itself. Saying so up front saves everyone a round of false reports.</p><h3>The starter checklist</h3><p>Here’s the whole setup as a checklist you can run on any public repo in an afternoon. None of it needs a team, and everything except the AI review is free.</p><p><strong>Flip on in Settings → Code security &amp; analysis:</strong></p><ul><li>Secret scanning + push protection</li><li>Dependabot security alerts</li><li>CodeQL code scanning (default setup)</li><li>Private vulnerability reporting</li><li>Branch protection on the default branch (require a PR and passing checks)</li></ul><p><strong>Commit to the repo:</strong></p><ul><li>renovate.json — a shared, centralised preset for version updates</li><li>A gitleaks workflow — secret scanning in CI</li><li>An OpenSSF Scorecard workflow</li><li>An AI code-review workflow (e.g. Claude Code review)</li><li>SECURITY.md</li><li>Every GitHub Action pinned to a commit SHA</li><li>Database security rules in the repo, deployed by CI (if you use Firebase)</li></ul><p>Grab the working configs from the <a href="https://github.com/agapasieka/nohungrypets">NoHungryPets repo</a> and adapt them. Apart from the AI review, all of it is free at this scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ae60074857e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Hosted Renovate: How We Centralised Dependency Updates (and Why Not Dependabot)]]></title>
            <link>https://agnieszkapasieka.medium.com/self-hosted-renovate-how-we-centralised-dependency-updates-and-why-not-dependabot-1fdd6688c33a?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fdd6688c33a</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[renovate]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 21:40:02 GMT</pubDate>
            <atom:updated>2026-11-09T21:40:02.794Z</atom:updated>
            <content:encoded><![CDATA[<h3>The chore nobody wants</h3><p>Keeping dependencies current across a handful of repos quietly rots: projects drift, security patches sit unmerged, and nobody wants to spend a Friday bumping versions by hand. We wanted updates as small, scheduled pull requests — the boring ones merging themselves — with the policy set once, not per repo.</p><p>So we set up self-hosted Renovate, driven from one repo. “The bot” is Renovate itself: a scheduled job that runs the Renovate CLI, authenticated as a GitHub App, which opens the update PRs. That repo holds the bot, its schedule, the list of repos to watch, and the shared policy every other repo inherits.</p><h3>Why not Dependabot?</h3><p>Dependabot is the obvious default — it’s built into GitHub, free, and takes about five minutes to enable. For a single repo, it’s genuinely fine, and we’re not here to dunk on it. Our problem was fleet-scale consistency, and that’s where it started to chafe.</p><p>The big one is <strong>configuration living in every repo</strong>. Dependabot’s config is a dependabot.yml committed to each repository. Change your grouping rules or schedule and you&#39;re editing (and reviewing) the same YAML in N places, hoping they stay in sync. Renovate lets us publish one shared preset that every repo extends by reference — a single line of config per repo, and all the real policy centralised.</p><p>The rest piled on from there:</p><ul><li><strong>Grouping and scheduling are blunter.</strong> Renovate groups related updates, batches monorepo packages, and takes rich schedules (“after 9pm on weekdays”) far more flexibly.</li><li><strong>Auto-merge control is finer.</strong> We wanted “auto-merge minor and patch once CI is green, hold every major for review.” That’s a couple of lines of packageRules in Renovate; it&#39;s awkward to express cleanly in Dependabot.</li><li><strong>No freshness reporting.</strong> Renovate can emit a machine-readable report with libyear data (how many “years behind” latest each dependency is). Dependabot gives you PRs, not a scorecard.</li><li><strong>Self-hosting means control.</strong> Running the bot ourselves means our rules, our schedule, our logs — and it works identically across public and private repos.</li></ul><p>None of these is fatal on its own. Together, for more than two or three repos, they tipped us to Renovate.</p><h3>One repo to rule them all</h3><p>The whole setup lives in renovate-config, four small files:</p><pre>renovate-config/<br>├── targets.json                 # which repos Renovate manages<br>├── config.js                    # the bot&#39;s global config<br>├── default.json                 # the shared update policy<br>└── .github/workflows/renovate.yml   # the scheduled runner</pre><p>targets.json is just a list of repositories — the single source of truth for what the bot touches. Onboarding a new repo is a one-line pull request here.</p><p>default.json is the preset every managed repo inherits. Instead of copying policy around, each repo carries a trivial renovate.json:</p><pre>{<br>  &quot;$schema&quot;: &quot;https://docs.renovatebot.com/renovate-schema.json&quot;,<br>  &quot;extends&quot;: [&quot;local&gt;your-org/renovate-config&quot;]<br>}</pre><p>That extends line pulls in grouping, scheduling, labels, and auto-merge rules from the centre. Want to change how updates behave everywhere? Edit default.json once; every repo picks it up on the next run. That&#39;s the entire point of the design.</p><h3>Making it run</h3><p><strong>Auth: a GitHub App, not a token.</strong> <br>You can run Renovate with a personal access token, but a dedicated GitHub App is cleaner — no human account in the loop, fine-grained permissions (contents, pull requests, issues, workflows), and its PRs play nicely with branch protection. The workflow mints a short-lived token from the App’s ID and private key at runtime.</p><p><strong>The runner is a scheduled GitHub Action.</strong> A cron-triggered workflow (plus a manual “Run workflow” button) spins up the self-hosted Renovate CLI daily. One wrinkle worth knowing: the Renovate action mounts only its config file into the container, so config.js can&#39;t just require(&#39;./targets.json&#39;). Instead a small step reads targets.json with jq and passes the list as the RENOVATE_REPOSITORIES env var — RENOVATE_* variables get forwarded into the container automatically:</p><pre>- name: Build repository list from targets.json<br>  id: targets<br>  run: echo &quot;repositories=$(jq -r &#39;.repositories | join(&quot;,&quot;)&#39; targets.json)&quot; &gt;&gt; &quot;$GITHUB_OUTPUT&quot;</pre><p>A nice side effect of self-hosting: renovate-config can be <strong>private</strong>, and it still happily manages a mix of public and private target repos. Presets are resolved by the bot at runtime using its own token, so the target repo&#39;s visibility never matters.</p><h3>The update policy</h3><p>The policy that makes this sustainable is simple: <strong>auto-merge minor and patch updates once CI passes, and hold every major for a human.</strong> In default.json that&#39;s two packageRules:</p><pre>&quot;packageRules&quot;: [<br>  {<br>    &quot;description&quot;: &quot;Auto-merge all minor and patch updates once CI passes&quot;,<br>    &quot;matchUpdateTypes&quot;: [&quot;minor&quot;, &quot;patch&quot;],<br>    &quot;automerge&quot;: true<br>  },<br>  {<br>    &quot;description&quot;: &quot;Major updates: open a PR, never auto-merge, review manually&quot;,<br>    &quot;matchUpdateTypes&quot;: [&quot;major&quot;],<br>    &quot;automerge&quot;: false,<br>    &quot;addLabels&quot;: [&quot;major-update&quot;]<br>  }<br>]</pre><p>The routine churn — patch bumps, minor releases — flows through on its own as long as the tests stay green. The risky stuff, the major version bumps that might break you, shows up as a labelled PR waiting for review. One caveat we flag loudly: auto-merge only gates on <em>required status checks</em>, so a repo with no CI will merge immediately. If that feels loose, add a check, or a minimumReleaseAge so a release has to age a few days before Renovate touches it.</p><p>Each managed repo also gets a <strong>Dependency Dashboard</strong> — a tracking issue that lists everything pending, with checkboxes to trigger a specific update on demand. It’s the control panel when you want to reach in by hand. Onboarding a repo is two steps, worth remembering: add it to targets.json, <em>then</em> merge the &quot;Configure Renovate&quot; PR that lands in the repo. The first tells the bot to look; the second switches it on.</p><h3>Bonus: tracking how stale we are</h3><p>Update PRs tell you what to fix; they don’t tell you how far behind you are overall. So we added a second, separate workflow that produces a <strong>freshness report</strong>. It runs Renovate in --dry-run mode (so it opens no PRs), has it emit its JSON report, and commits a rendered libyear summary straight into the repo under reports/.</p><p>Libyears measure staleness in time: the sum, across your dependencies, of how long ago your version shipped versus the latest. Renovate already computes this — the report carries a libYears value per update — so a small script rolls it up into a per-repo table.</p><p>It’s a single number you can watch trend down as auto-merge does its work, and a quick way to spot the one repo that’s quietly two years behind. The report overwrites weekly; git history keeps the trail.</p><h3>Was it worth it?</h3><p>For one repo? Probably not — turn on Dependabot and move on. The payoff arrives with fleet size. Once you’re maintaining several repos and you care about <em>consistent</em> policy across them, the central-preset model pays for itself: change the rules in one file, and every repo follows.</p><p>Be honest about the cost, though. Self-hosted Renovate is more moving parts — a GitHub App to create, a scheduled workflow to babysit, a preset to maintain, and the occasional config quirk to debug. You’re trading Dependabot’s zero-setup simplicity for control and centralisation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fdd6688c33a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Free AI Code Reviews on GitHub: Setting Up CodeRabbit in 10 Minutes]]></title>
            <link>https://agnieszkapasieka.medium.com/free-ai-code-reviews-on-github-setting-up-coderabbit-in-10-minutes-a691d9642998?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a691d9642998</guid>
            <category><![CDATA[ai-code-review]]></category>
            <category><![CDATA[code-rabbit]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[pull-request-reviews]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Sun, 09 Aug 2026 19:06:04 GMT</pubDate>
            <atom:updated>2026-08-09T19:06:04.133Z</atom:updated>
            <content:encoded><![CDATA[<p><em>*A 10-minute setup that gives every pull request an automatic first-pass review — no credit card, no billing account, no catch (if your repo is public).*</em></p><p>If you maintain a public repository solo, you’ve probably wished for a second pair of eyes on every pull request, something that flags the obvious stuff (unused variables, missed edge cases, style drift, overly complex diffs). That’s exactly what [CodeRabbit](https://coderabbit.ai) does, and for open-source projects it’s completely free — the full Pro feature set, no credit card required.</p><p>I recently added it to a public repo and wanted to write up exactly what that looked like, including the alternative I tried first and ruled out.</p><p><strong>Why not Gemini Code Assist?</strong></p><p>My first instinct was to use Gemini Code Assist for PR reviews, since Gemini was already powering another part of the project. Its GitHub integration (via Google Cloud’s Developer Connect) looked promising — until I got to the fine print: it requires a <strong>**GCP billing account attached to the project**</strong>, even though Google says actual charges are unlikely within the free tier.</p><p>For a vibe-coded project with a zero-billing policy, “you probably won’t be charged” isn’t the same as “you can’t be charged.” Attaching a billing account is a real commitment, not a formality — so I looked for an alternative.</p><p><strong>Enter CodeRabbit</strong></p><p>CodeRabbit’s pricing page states plainly: <strong>**free forever for public repositories**</strong>, full Pro features included, no credit card and no stated PR-count limit for the open-source tier. That’s a clean fit for any public repo where the zero-billing constraint actually matters.</p><p>(If your repo is private, CodeRabbit still has a free tier, but it comes with a fair-use limit — documented as roughly 5 PR reviews per developer per hour on their standard Pro plan. It’s not entirely clear from their docs whether that same limit applies to public repos too, but at normal project PR volume it’s unlikely to matter. Worth revisiting only if reviews mysteriously stop firing on a busy day.)</p><p><strong>Setup, step by step</strong></p><p><strong>1. Add a <em>.coderabbit.yaml</em> to your repo root.</strong></p><p>This is optional (CodeRabbit works with sane defaults out of the box), but it’s worth tuning the review profile. Here’s a minimal, balanced config:</p><p>```yaml</p><p>profile: chill</p><p>high_level_summary: true</p><p>auto_review:</p><p>enabled: true</p><p>```</p><p><strong><em>profile: chill</em></strong> keeps the noise down — you get medium-and-above severity feedback rather than a flood of low-priority nits on every PR. <strong><em>high_level_summary: true</em></strong> adds a short plain-English summary comment at the top of each PR, which is genuinely useful for reviewers skimming a big diff.</p><p><strong>2. Install the CodeRabbit GitHub App.</strong></p><p>This part can’t be scripted — it needs to be done by the repo owner through the GitHub UI:</p><p>- Go to <strong><em>app.coderabbit.ai/login</em></strong> and sign in with GitHub.</p><p>- Choose <strong>”Only select repositories”</strong> and pick the repo(s) you want reviewed.</p><p>- Review the permissions CodeRabbit asks for — typically read-only access to Actions, checks, and metadata, and read-write access to code, commit statuses, issues, and PRs.</p><p>- Click <strong>Install &amp; Authorize</strong>.</p><p><strong>3. Verify it’s actually live.</strong></p><p>Here’s a gotcha worth knowing in advance: CodeRabbit only reacts to PRs that are <strong>opened or updated after installation</strong>. If you already have open PRs sitting around (say, a few Dependabot dependency bumps), it won’t touch them automatically.</p><p>To confirm the install worked without waiting for a fresh PR, comment on an existing open PR:</p><blockquote>@coderabbitai review</blockquote><p>That manually triggers a review and is the fastest way to know the app is actually connected and working, rather than just “installed” in name.</p><p><strong>Where it fits alongside other automation</strong></p><p>CodeRabbit is additive, not a replacement for other checks you might already have running — it doesn’t overlap with:</p><p>- <strong>CodeQL</strong>— static analysis for security vulnerability patterns.</p><p>- <strong>gitleaks</strong>— secret scanning.</p><p>Each tool covers a different concern: CodeRabbit is about code quality, logic, and style; CodeQL is about vulnerability patterns; gitleaks is about accidentally committed secrets. Running all three costs nothing on a public repo and covers three genuinely different failure modes.</p><p><strong>The takeaway</strong></p><p>If you’re maintaining a public repository and want AI-assisted PR reviews, there’s no reason to reach for a paid tool or one that requires attaching a billing account “just in case.” CodeRabbit’s free-for-open-source tier gets you a real reviewer bot — summaries, inline comments, and configurable severity — in about ten minutes, with the only manual step being the GitHub App install itself.</p><p><strong>— -</strong></p><p><em>*Have you set up automated PR reviews on your own projects? I’d be curious what tradeoffs you ran into, especially on private repos where the free-tier limits actually start to bite.*</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a691d9642998" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 4: Deploy…]]></title>
            <link>https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-4-deploy-b55dc8e2fa92?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b55dc8e2fa92</guid>
            <category><![CDATA[app-security]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 13:08:54 GMT</pubDate>
            <atom:updated>2024-10-07T02:21:53.573Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 4: Deploy Application with SSL</h3><p>This is a Part 4 of the tutorial: Building reliable and scalable infrastructure in Google Cloud Platform (GCP).</p><p>In <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-3-deploy-d497a6745141">Part 3</a>, we deployed the blog app to MIG and host it behind a HTTP Load Balancer, introducing scalability and reliability.</p><p>In this series, we will create a SSL certificate used for HTTPS load balancing to serve secure connections from the user. <br>For simplicity, we will create self-signed certificate without the need to rely on an external certificate authority (CA).</p><blockquote><a href="https://github.com/agapasieka/Deploy-Reliable-Infrastructure">Github repo</a> containing all files</blockquote><h4>Step 1. Create self-signed certificate</h4><p>Create a new folder called <strong>self-signed-ssl</strong> to store certificate files</p><ol><li>Create private key</li></ol><pre>openssl genrsa -out self-signed-ssl/blog.key 2048</pre><p>2. Create certificate signing request</p><pre>openssl req -new -key self-signed-ssl/blog.key -out self-signed-ssl/blog.csr -subj &quot;/CN=blog.example.com&quot;</pre><p>3. Create public certificate</p><pre>openssl x509 -req -days 7300 -in self-signed-ssl/blog.csr -signkey self-signed-ssl/blog.key -out self-signed-ssl/blog.crt</pre><p>4. Create certificate with terraform</p><pre>resource &quot;google_compute_ssl_certificate&quot; &quot;blog_ssl&quot; {<br>  name_prefix = &quot;blog-ssl-&quot;<br>  description = &quot;SSL Certificate for blog&quot;<br>  private_key = file(&quot;self-signed-ssl/blog.key&quot;)<br>  certificate = file(&quot;self-signed-ssl/blog.crt&quot;)<br><br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}</pre><h4>Step 2. Modify Load Balancer</h4><p>We will now modify the existing load balancer to support <strong>SSL/TLS</strong> traffic, enabling secure communication via HTTPS. To achieve this, we’ll add the necessary components:</p><ul><li><strong>HTTPS Target Proxy</strong>: This will handle HTTPS requests and forward them to the backend.</li><li><strong>HTTPS Forwarding Rule</strong>: Route incoming HTTPS traffic to the load balancer using the SSL certificate.</li></ul><ol><li>Add HTTPS Target Proxy in <strong>load-balander.tf</strong></li></ol><pre># HTTPS Target Proxy<br>resource &quot;google_compute_target_https_proxy&quot; &quot;mylb&quot; {<br>  name   = &quot;${local.name}-mylb-https-proxy&quot;<br>  url_map = google_compute_url_map.mylb.self_link<br>  ssl_certificates = [google_compute_ssl_certificate.blog_ssl.id]<br>}</pre><p>2. Create Forwarding rule for HTTPS</p><pre>  # HTTPS Forwarding Rule<br>  resource &quot;google_compute_forwarding_rule&quot; &quot;mylb_https&quot; {<br>      name        = &quot;${local.name}-mylb-https-forwarding-rule&quot;<br>      target      = google_compute_target_https_proxy.mylb.self_link<br>      port_range  = &quot;443&quot;<br>      ip_protocol = &quot;TCP&quot;<br>      ip_address  = google_compute_global_address.mylb.address<br>      load_balancing_scheme = &quot;EXTERNAL_MANAGED&quot; <br>      network = google_compute_network.myvpc.id<br>      <br>      depends_on = [ google_compute_subnetwork.regional_proxy_subnet ]<br>    }</pre><p>3. Add new URL Map to set up http-to-https redirection</p><pre>  # URL Map for HTTP to HTTPS redirection<br>  resource &quot;google_compute_url_map&quot; &quot;http&quot; {<br>    name = &quot;${local.name}-blog-http-to-https-url-map&quot;<br>    default_url_redirect {<br>      redirect_response_code = &quot;MOVED_PERMANENTLY_DEFAULT&quot;<br>      strip_query            = false<br>      https_redirect         = true<br>    }<br>  }</pre><p>4. Modify the HTTP Proxy to use the new URL Map for HTTP to HTTPS redirection</p><pre>  # HTTP Proxy<br>  resource &quot;google_compute_target_http_proxy&quot; &quot;mylb&quot; {<br>    name    = &quot;${local.name}-mylb-http-proxy&quot;<br>    url_map = google_compute_url_map.http.self_link<br>  }</pre><h4>Step 3. Execute deployment</h4><pre>terraform init<br>terraform apply -auro-approve</pre><p>When deployment completes, terraform outputs the external IP of load balancer. You can test the blog in browser by using the following URL</p><pre>https://&lt;LOAD-BALANCER-IP&gt;</pre><p>A self-signed certificate does not provide the <strong>trusted “green padlock”</strong> in browsers because it isn’t signed by a recognized Certificate Authority (CA). Instead, the browsers will display a warning, indicating the certificate is not trusted. <br>However, these steps are sufficient for testing or internal use cases where full SSL validation is not critical. While the browser might show a warning, it still enables encrypted communication, which is useful for securing traffic during development or in controlled environments.</p><p>Don’t forget to clean-up your lab resources</p><pre>terraform destroy -auro-approve</pre><p>And that&#39;s all it is to it. By adding these components, we ensure secure traffic handling on the load balancer.</p><p>Happy Learning and Thanks for Reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b55dc8e2fa92" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-4-deploy-b55dc8e2fa92">Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 4: Deploy…</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[Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 3: Deploy…]]></title>
            <link>https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-3-deploy-d497a6745141?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d497a6745141</guid>
            <category><![CDATA[managed-instance-group]]></category>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 15:02:04 GMT</pubDate>
            <atom:updated>2024-10-07T02:21:57.508Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 3: Deploy Application to Managed Instance Group(MIG)</h3><p>This is a Part 3 of the tutorial: Building reliable and scalable infrastructure in Google Cloud Platform (GCP).</p><p>In <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-2-deploy-3b7974dbc111">Part 2</a>, we developed our sample blog to GCE. In this part we will deploy the app to MIG and host it behind an HTTP(S) Load Balancer, which will enhance scalability, improve reliability, and provide better load distribution for our application.</p><h4>Prerequisites</h4><ul><li>Google Cloud Platform (GCP) Account</li><li>IAM Permissions on GCP project</li><li>Google Cloud SDK (gcloud)</li><li>Terraform version 1.8.5</li></ul><p>We will reuse almost all resources created in <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-2-deploy-3b7974dbc111">Part 2</a>. Feel free to clone the <a href="https://github.com/agapasieka/Deploy-Reliable-Infrastructure">Github repo</a> if you want to follow along. Make sure to uncomment or delete the gce.tf file as we will replace it with instance template and mig.</p><h4>Step 1. Create instance template</h4><p>An <strong>instance template</strong> is a predefined configuration for virtual machine instances, allowing you to create multiple instances with the same configuration easily. It’s commonly used with managed instance groups for scaling.</p><ol><li>Create new file called <strong>instance-template.tf</strong></li></ol><pre>cat &gt; instance-template.tf</pre><p>2. Paste the following code:</p><pre>data &quot;google_compute_image&quot; &quot;my_image&quot; {<br>  #Debian<br>  project = &quot;debian-cloud&quot;<br>  family  = &quot;debian-12&quot;<br>}<br><br># Instance Template<br>resource &quot;google_compute_instance_template&quot; &quot;blog_green&quot; {<br>  name         = &quot;${local.name}-blog-template&quot;<br>  description  = &quot;This template is used to create Blog instances.&quot;<br>  tags         = [tolist(google_compute_firewall.allow_http.target_tags)[0], tolist(google_compute_firewall.allow_health_checks.target_tags)[0]]<br>  machine_type = var.machine_type<br>  scheduling {<br>    automatic_restart   = true<br>    on_host_maintenance = &quot;MIGRATE&quot;<br>  }<br><br>   disk {<br>    source_image      = data.google_compute_image.my_image.self_link<br>    boot              = true<br>    auto_delete = true<br>  }<br><br>  network_interface {<br>    subnetwork = google_compute_subnetwork.gce_subnet.id<br>  }<br>  # Install Webserver<br>  metadata_startup_script = file(&quot;${path.module}/scripts/setup-blog-nginx.sh&quot;)<br><br>  metadata = {<br>    environment = local.environment<br>  }<br>  service_account {<br>    email  = google_service_account.blog_vm_sa.email<br>    scopes = [&quot;cloud-platform&quot;]<br>  }<br>}</pre><p>Type CTRL+C to exit</p><p>The code will be almost identical to gce.tf, with one key difference in the network_interface block, where we’ve removed the creation of the public IP:</p><pre>access_config {<br>      // Ephemeral public IP<br>    }</pre><h4>Step 2. Create Managed Instance Group</h4><p>A <strong>Managed Instance Group (MIG)</strong> automatically manages a group of identical virtual machines.</p><ol><li>Create new file called <strong>mig.tf</strong></li></ol><pre>cat &gt; mig.tf</pre><pre># Managed Instance Group<br>resource &quot;google_compute_instance_group_manager&quot; &quot;blog_mig&quot; {<br>  name                      = &quot;${local.name}-blog-mig&quot;<br>  base_instance_name        = &quot;${local.name}-blog&quot;<br>  target_size  = 2<br>  zone = var.zones[0]<br><br>  version {<br>    instance_template = google_compute_instance_template.blog_green.id<br>  }<br>  # Named Port<br>  named_port {<br>    name = &quot;webserver&quot;<br>    port = 80<br>  }<br>  # Autohealing<br>  auto_healing_policies {<br>    health_check      = google_compute_health_check.blog_hc.id<br>    initial_delay_sec = 300<br>  }<br>  # Update Policy<br>  update_policy {<br>    type                           = &quot;PROACTIVE&quot;<br>    minimal_action                 = &quot;REPLACE&quot;<br>    most_disruptive_allowed_action = &quot;REPLACE&quot;<br>    max_surge_fixed                = length(var.zones)<br>    max_unavailable_fixed          = length(var.zones)<br>    replacement_method             = &quot;SUBSTITUTE&quot;<br>  }<br> depends_on = [google_storage_bucket.public_bucket, google_storage_bucket_object.file1, google_storage_bucket_object.file2]<br>}<br><br># Health Check<br>resource &quot;google_compute_health_check&quot; &quot;blog_hc&quot; {<br>  name                = &quot;${local.name}-blog-hc&quot;<br>  check_interval_sec  = 5<br>  timeout_sec         = 5<br>  healthy_threshold   = 2<br>  unhealthy_threshold = 3<br>  http_health_check {<br>    request_path = &quot;/index.html&quot;<br>    port         = 80<br>  }<br>}<br><br># MIG Autoscaling<br>resource &quot;google_compute_region_autoscaler&quot; &quot;blog_autoscaler&quot; {<br>  name   = &quot;${local.name}-blog-autoscaler&quot;<br>  target = google_compute_instance_group_manager.blog_mig.id<br>  autoscaling_policy {<br>    max_replicas    = 6<br>    min_replicas    = 2<br>    cooldown_period = 60<br>    cpu_utilization {<br>      target = 0.9<br>    }<br>  }<br>}</pre><p>Type CTRL+C to exit</p><h4>Step 3. Set up a NAT gateway to enable outbound connections.</h4><p>Create a NAT gateway to allow outgoing connections from your private instances to the internet while keeping them secure from inbound traffic.<br>Without NAT gateway, the startup script will fail to install nginx and download files from bucket as we removed the Public IP creation from instance template.</p><p>Create new file called <strong>cloud-nat-router.tf</strong></p><pre>cat &gt; cloud-nat-router.tf</pre><pre># Cloud Router<br>resource &quot;google_compute_router&quot; &quot;cloud_router&quot; {<br>  name    = &quot;${local.name}-${var.region}-cloud-router&quot;<br>  network = google_compute_network.myvpc.id<br>  region  = var.region<br>}<br><br># Cloud NAT<br>resource &quot;google_compute_router_nat&quot; &quot;cloud_nat&quot; {<br>  name                               = &quot;${local.name}-${var.region}-cloud-nat&quot;<br>  router                             = google_compute_router.cloud_router.name<br>  region                             = google_compute_router.cloud_router.region<br>  nat_ip_allocate_option             = &quot;AUTO_ONLY&quot;<br>  source_subnetwork_ip_ranges_to_nat = &quot;ALL_SUBNETWORKS_ALL_IP_RANGES&quot;<br>  log_config {<br>    enable = true<br>    filter = &quot;ALL&quot;<br>  }<br>}</pre><p>Type CTRL+C to exit</p><blockquote><strong>Cloud Router</strong> helps manage dynamic routes in a VPC and is needed to set up Cloud NAT.</blockquote><h4>Step 4. Set up a HTTP Load Balancer for traffic distribution</h4><p>Set up load balancer to distribute incoming traffic across multiple backend instances, improving availability and reliability.</p><p>Create new file called <strong>load-balancer.tf</strong></p><pre>cat &gt; load-balancer.tf</pre><pre># Reserve Static IP Address<br>resource &quot;google_compute_global_address&quot; &quot;mylb&quot; {<br>  name   = &quot;${local.name}-mylb-static-ip&quot;<br>  region = var.region<br>}<br><br># Health Check<br>resource &quot;google_compute_health_check&quot; &quot;mylb&quot; {<br>  name                = &quot;${local.name}-mylb-blog-health-check&quot;<br>  check_interval_sec  = 5<br>  timeout_sec         = 5<br>  healthy_threshold   = 2<br>  unhealthy_threshold = 3<br>  http_health_check {<br>    request_path = &quot;/index.html&quot;<br>    port         = 80<br>  }<br>}<br><br># Backend Service<br>resource &quot;google_compute_backend_service&quot; &quot;mylb&quot; {<br>  name                  = &quot;${local.name}-blog-backend-service&quot;<br>  protocol              = &quot;HTTP&quot;<br>  load_balancing_scheme = &quot;EXTERNAL_MANAGED&quot;<br>  health_checks         = [google_compute_health_check.mylb.self_link]<br>  port_name             = &quot;webserver&quot;<br>  backend {<br>    group           = google_compute_instance_group_manager.blog_mig.instance_group<br>    capacity_scaler = 1.0<br>    balancing_mode  = &quot;UTILIZATION&quot;<br>  }<br>}<br><br># URL Map<br>resource &quot;google_compute_url_map&quot; &quot;mylb&quot; {<br>  name            = &quot;${local.name}-mylb-url-map&quot;<br>  default_service = google_compute_backend_service.mylb.self_link<br>}<br><br><br># HTTP Proxy<br>resource &quot;google_compute_target_http_proxy&quot; &quot;mylb&quot; {<br>  name    = &quot;${local.name}-mylb-http-proxy&quot;<br>  url_map = google_compute_url_map.mylb.self_link<br>}<br><br><br># Forwarding Rule<br>resource &quot;google_compute_global_forwarding_rule&quot; &quot;mylb&quot; {<br>  name                  = &quot;${local.name}-mylb-forwarding-rule&quot;<br>  target                = google_compute_target_http_proxy.mylb.self_link<br>  port_range            = &quot;80&quot;<br>  ip_protocol           = &quot;TCP&quot;<br>  ip_address            = google_compute_global_address.mylb.address<br>  load_balancing_scheme = &quot;EXTERNAL_MANAGED&quot;<br><br>  depends_on = [google_compute_subnetwork.regional_proxy_subnet]<br>}<br><br>output &quot;Load_Balancer_IP&quot; {<br>  value       = google_compute_global_address.mylb.address<br>  description = &quot;The external IP address of the Load Balancer&quot;<br>}</pre><p>Type CTRL+C to exit</p><blockquote><strong>Global static IP address</strong> will be associated with the load balancer, ensuring a consistent IP for external clients to connect to</blockquote><blockquote><strong>Health check</strong> monitors the status of backend instances to ensure they are healthy and able to serve traffic. If an instance fails this check, it will be marked as unhealthy and traffic will not be routed to it</blockquote><blockquote><strong>Backend service</strong> is the core component that connects the load balancer to the backend instances (managed by an instance group). It determines how traffic is distributed among backends</blockquote><blockquote><strong>URL Map</strong> defines how incoming HTTP requests should be routed to backend services. In this case, all incoming traffic is directed to the default backend service (google_compute_backend_service.mylb)</blockquote><blockquote><strong>HTTP Proxy</strong> is a component of the load balancer that receives incoming HTTP requests and forwards them to the correct backend based on the URL map. It ensures requests are properly routed</blockquote><blockquote><strong>Forwarding rule</strong> is the entry point for the load balancer. It listens for incoming traffic on a specified port (here, port 80 for HTTP) and forwards the requests to the HTTP proxy, which will route them to the appropriate backend</blockquote><h4>Step 5. Amend firewall rules</h4><p>We can now improve security by modifying firewall rules created in <a href="https://github.com/agapasieka/Deploy-Reliable-Infrastructure/blob/master/Part2-Deploy-App-to-VM/firewall.tf">Task 2 </a>where our instance was exposed to the internet on ports: 22 and 80.</p><p>Modify file called <strong>firewall.tf</strong></p><pre># Allow HTTP from Proxy-only subnet to backends<br>resource &quot;google_compute_firewall&quot; &quot;allow_http&quot; {<br>  name = &quot;${local.name}-fwrule-allow-http80&quot;<br>  allow {<br>    ports    = [&quot;80&quot;]<br>    protocol = &quot;tcp&quot;<br>  }<br>  direction     = &quot;INGRESS&quot;<br>  network       = google_compute_network.myvpc.id<br>  priority      = 1000<br>  source_ranges = [&quot;10.0.0.0/24&quot;]<br>  target_tags   = [&quot;webserver-tag&quot;]<br>}<br><br># Allow Health checks<br>resource &quot;google_compute_firewall&quot; &quot;allow_health_checks&quot; {<br>  name    = &quot;${local.name}-allow-health-checks&quot;<br>  network = google_compute_network.myvpc.id<br>  allow {<br>    protocol = &quot;tcp&quot;<br>    ports    = [&quot;80&quot;]<br>  }<br>  source_ranges = [<br>    &quot;35.191.0.0/16&quot;,<br>    &quot;130.211.0.0/22&quot;<br>  ]<br>  target_tags = [&quot;allow-health-checks&quot;]<br>}<br></pre><p>Type CTRL+C to exit</p><blockquote><strong>allow_http</strong> allows HTTP traffic (port 80) from the <strong>proxy-only subnet</strong> to the backend instances in the VPC network</blockquote><blockquote><strong>allow_health_checks</strong> allows health check traffic from Google Cloud’s health check services to the backend instances. Health checks are used by the load balancer to ensure that backend instances are healthy and can serve traffic</blockquote><h4>Step 6. Apply the config to deploy all resources</h4><ol><li>Check for any config errors</li></ol><pre>terraform validate</pre><p>2. Execute the configuration</p><pre>terraform apply</pre><p>When deployment completes, terraform outputs the external IP of Load Balancer. You can test the blog in browser by using the following URL</p><pre>http://&lt;Load_Balancer_IP&gt;</pre><p>Don’t forget to clean-up your lab resources</p><pre>terraform destroy</pre><p>Well done for completing another part!</p><p>I hope you learned valuable insights and gained confidence in deploying more reliable and scalable infrastructure on Google Cloud.</p><p>The next <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-4-deploy-b55dc8e2fa92">Part 4</a> will introduce SSL to ensure secure traffic handling on the load balancer.</p><p>Keep up the great work, and let’s continue building on this progress!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d497a6745141" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-3-deploy-d497a6745141">Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 3: Deploy…</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[Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 2: Deploy…]]></title>
            <link>https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-2-deploy-3b7974dbc111?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b7974dbc111</guid>
            <category><![CDATA[startup-script]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[managed-instance-group]]></category>
            <category><![CDATA[gcp-load-balancer]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 21:43:06 GMT</pubDate>
            <atom:updated>2024-10-07T02:22:09.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 2: Deploy Application to GCE</h3><p>This is a Part 2 of the tutorial: Building reliable and scalable infrastructure in Google Cloud Platform (GCP).</p><p>In <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-1-building-083c9ae4b56c">Part 1</a>, we developed and tested our sample blog using Docker. In this part we will deploy the same app to Google Compute Engine.</p><h4>Prerequisites</h4><ul><li>Google Cloud Platform (GCP) Account</li><li>IAM Permissions on GCP project</li><li>Google Cloud SDK (gcloud)</li><li>Terraform version 1.8.5</li></ul><h4>Step 1. Create startup script</h4><p>We will use startup script to install all requirements for blog on GCE.</p><ol><li>Use the same directory you created in Part 1 and create new file called <strong>setup-blog-nginx.sh</strong></li></ol><pre>cat &gt; setup-blog-nginx.sh</pre><p>2. Paste the following config</p><pre>#!/bin/bash<br><br># Fetch the project ID <br>PROJECT_ID=$(gcloud config get-value project)<br># Fetch the bucket name<br>BUCKET=$PROJECT_ID-bucket<br><br># Update package list and install Nginx and Google Cloud SDK<br>echo &quot;Updating package list and installing Nginx and Google Cloud SDK...&quot;<br>if [ -f /etc/debian_version ]; then<br>    sudo apt update -y &amp;&amp; sudo apt install -y nginx google-cloud-sdk<br>elif [ -f /etc/redhat-release ]; then<br>    sudo yum update -y &amp;&amp; sudo yum install -y nginx google-cloud-sdk<br>fi<br><br># Create the web directory if it doesn&#39;t exist<br>echo &quot;Setting up the Nginx HTML directory...&quot;<br>sudo mkdir -p /usr/share/nginx/html<br><br># Set permissions for the Nginx web directory<br>echo &quot;Setting permissions...&quot;<br>sudo chown -R www-data:www-data /usr/share/nginx/html<br>sudo chmod -R 755 /usr/share/nginx/html<br><br># Change directory to the Nginx web directory<br>cd /usr/share/nginx/html<br><br># Copy the blog.html and image from GCS bucket to the Nginx web directory<br>echo &quot;Copying blog.html and image from GCS bucket to Nginx directory...&quot;<br>sudo gsutil cp -r gs://$BUCKET/blog.html ./blog.html <br>sudo gsutil cp -r gs://$BUCKET/my-dog.jpg ./my-dog.jpg <br><br><br># Ensure that the copied files have the correct permissions<br>sudo chmod 644 /usr/share/nginx/html/blog.html<br>sudo chmod 644 /usr/share/nginx/html/my-dog.jpg<br><br># Remove the default Nginx configuration if it exists<br>sudo rm -f /etc/nginx/sites-enabled/default<br><br># Configure Nginx to serve the blog page<br>echo &quot;Configuring Nginx to serve the blog page...&quot;<br>sudo tee /etc/nginx/sites-available/blog &gt; /dev/null &lt;&lt;EOF<br>server {<br>    listen 80;<br>    server_name _;<br>    root /usr/share/nginx/html;<br>    index blog.html;<br>    location / {<br>        try_files \$uri \$uri/ =404;<br>    }<br>}<br>EOF<br><br># Enable the blog configuration<br>sudo ln -sf /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/blog<br><br># Test and restart Nginx<br>echo &quot;Testing Nginx configuration...&quot;<br>sudo nginx -t &amp;&amp; sudo systemctl restart nginx || sudo service nginx restart<br><br>echo &quot;Blog setup complete! Access it at http://&lt;your_server_ip&gt;&quot;</pre><p>Type CTRL+C to exit</p><h4>Step 2. Create Terraform provider</h4><p>To start with Terraform, we will define the following files</p><ol><li>Create<strong> provider.tf</strong></li></ol><pre>cat &gt; provider.tf</pre><pre>provider &quot;google&quot; {<br>  project = var.project_id<br>  region  = var.region<br>}<br><br>provider &quot;google-beta&quot; {<br>  project = var.project_id<br>  region  = var.region<br>}<br><br>terraform {<br>  required_version = &quot;&gt;= 1.8.5&quot;<br>  required_providers {<br>    google = {<br>      source  = &quot;hashicorp/google&quot;<br>      version = &quot;&gt;= 5.34&quot;<br>    }<br>    google-beta = {<br>      source  = &quot;hashicorp/google-beta&quot;<br>      version = &quot;&gt;= 5.34&quot;<br>    }<br>  }<br>}</pre><p>Type CTRL+C to exit</p><p>2. Create <strong>variables.tf</strong></p><pre>cat &gt; variables.tf</pre><pre># GCP Project<br>variable &quot;project_id&quot; {<br>  description = &quot;Project ID&quot;<br>  type        = string<br>}<br><br># GCP Region<br>variable &quot;region&quot; {<br>  description = &quot;Main Region&quot;<br>  type        = string<br>}<br><br># GCP Zones<br>variable &quot;zones&quot; {<br>  description = &quot;Zones&quot;<br>  type        = list(string)<br>}<br><br># GCP Compute Engine Machine Type<br>variable &quot;machine_type&quot; {<br>  description = &quot;Compute Engine Machine Type&quot;<br>  type        = string<br>}<br><br># Environment Variable<br>variable &quot;environment&quot; {<br>  description = &quot;Environment Variable used as a prefix&quot;<br>  type        = string<br>}<br><br># Business Division<br>variable &quot;business_divsion&quot; {<br>  description = &quot;Business Division in the large organization this Infrastructure belongs&quot;<br>  type        = string<br>}</pre><p>Type CTRL+C to exit</p><p>3. Create <strong>terraform.tfvars</strong></p><pre>cat &gt; terraform.tfvars</pre><pre>#project_id <br>region           = &quot;europe-west1&quot;<br>zones            = [&quot;europe-west1-b&quot;, &quot;europe-west1-c&quot;, &quot;europe-west1-d&quot;]<br>machine_type     = &quot;e2-medium&quot;<br>environment      = &quot;dev&quot;<br>business_divsion = &quot;web&quot;</pre><p>Type CTRL+C to exit</p><p>Optionally, you can uncomment the project_id and paste your project here, otherwise you will be prompted to enter it when you run terrform apply in later stage.</p><p>4. In addition, I created <strong>locals.tf</strong> to help us avoid code repetition</p><pre>cat &gt; locals.tf</pre><pre>locals {<br>  owners      = var.business_divsion<br>  environment = var.environment<br>  name        = &quot;${var.business_divsion}-${var.environment}&quot;<br>  common_tags = {<br>    owners      = local.owners<br>    environment = local.environment<br>  }<br>} </pre><p>Type CTRL+C to exit</p><h4>Step 3. Deploy Bucket</h4><p>The first resource we need is <a href="https://cloud.google.com/storage/docs/buckets">Storage Bucket</a> to store the blog.html and my-dog.jpg files which are downloaded to GCE via startup script .</p><ol><li>Create <strong>bucket.tf</strong></li></ol><pre>cat &gt; bucket.tf</pre><pre># Create a GCS bucket<br>resource &quot;google_storage_bucket&quot; &quot;public_bucket&quot; {<br>  name         = &quot;${var.project_id}-bucket&quot;<br>  location      = &quot;EU&quot;<br>  force_destroy = true<br><br>  labels = {<br>    environment = &quot;dev&quot;<br>    purpose     = &quot;web-files&quot;<br>  }<br>}<br><br># Upload two files to the bucket with public access<br>resource &quot;google_storage_bucket_object&quot; &quot;file1&quot; {<br>  name   = &quot;blog.html&quot;   <br>  bucket = google_storage_bucket.public_bucket.name<br>  source = &quot;blog.html&quot;   <br>  content_type = &quot;text/html&quot;<br>}<br><br>resource &quot;google_storage_bucket_object&quot; &quot;file2&quot; {<br>  name   = &quot;my-dog.jpg&quot;  <br>  bucket = google_storage_bucket.public_bucket.name<br>  source = &quot;my-dog.jpg&quot;  <br>  content_type = &quot;image/jpeg&quot;<br>}<br><br># Add bucket-level access control to allow public access<br>resource &quot;google_storage_bucket_iam_binding&quot; &quot;bucket_public_access&quot; {<br>  bucket = google_storage_bucket.public_bucket.name<br>  role   = &quot;roles/storage.objectViewer&quot;<br><br>  members = [<br>    &quot;allUsers&quot;,<br>  ]<br>}</pre><p>Type CTRL+C to exit</p><p>2. Deploy bucket with Terraform</p><pre>terraform init<br>terraform apply</pre><h4>Step 4. Deploy GCE</h4><p>For GCE, we need to create VPC network and dedicated service account. <br>With dedicated service accounts, you can grant the minimum set of permissions needed for that specific application or workload, following the principle of least privilege.</p><ol><li>Create <strong>vpc.tf</strong></li></ol><pre>cat &gt; vpc.tf</pre><pre># VPC<br>resource &quot;google_compute_network&quot; &quot;myvpc&quot; {<br>  name                    = &quot;${local.name}-vpc&quot;<br>  auto_create_subnetworks = false<br>}<br><br># Regional Subnet<br>resource &quot;google_compute_subnetwork&quot; &quot;gce_subnet&quot; {<br>  name          = &quot;${var.region}-gce-subnet&quot;<br>  region        = var.region<br>  ip_cidr_range = &quot;10.128.0.0/20&quot;<br>  network       = google_compute_network.myvpc.id<br>}</pre><p>Type CTRL+C to exit</p><p>2. Create <strong>service-account.tf</strong></p><pre>cat &gt; service-account.tf</pre><pre>resource &quot;google_service_account&quot; &quot;blog_vm_sa&quot; {<br>  account_id   = &quot;blog-vm-sa&quot;<br>  display_name = &quot;Custom SA for VM Instance&quot;<br>}</pre><p>Type CTRL+C to exit</p><p>3. Create <strong>gce.tf</strong></p><pre>cat &gt; gce.tf</pre><pre>data &quot;google_compute_image&quot; &quot;my_image&quot; {<br>  #Debian<br>  project = &quot;debian-cloud&quot;<br>  family  = &quot;debian-12&quot;<br>}<br><br># Boot Disk<br>resource &quot;google_compute_disk&quot; &quot;blog_vm_boot&quot; {<br>  name  = &quot;blog-vm-boot&quot;<br>  type  = &quot;pd-ssd&quot;<br>  zone  = var.zones[0]<br>  image = data.google_compute_image.my_image.self_link<br>  labels = {<br>    environment = local.environment<br>  }<br>  size = 20<br>}<br># Instance blog-vm<br>resource &quot;google_compute_instance&quot; &quot;blog_vm&quot; {<br>  name         = &quot;${local.name}-blog-vm&quot;<br>  description  = &quot;Blog instance&quot;<br>  tags         = [tolist(google_compute_firewall.allow_ssh.target_tags)[0], tolist(google_compute_firewall.allow_http.target_tags)[0]]<br>  machine_type = var.machine_type<br>  zone         = var.zones[0]<br>  scheduling {<br>    automatic_restart   = true<br>    on_host_maintenance = &quot;MIGRATE&quot;<br>  }<br><br>  labels = {<br>    environment = local.environment<br>  }<br><br>  boot_disk {<br>    source      = google_compute_disk.blog_vm_boot.self_link<br>    auto_delete = true<br>  }<br><br>  network_interface {<br>    subnetwork = google_compute_subnetwork.gce_subnet.id<br>    access_config {<br>      // Ephemeral public IP<br>    }<br>  }<br>  # Install Webserver<br>  metadata_startup_script = file(&quot;${path.module}/setup-blog-nginx.sh&quot;) <br><br>  metadata = {<br>    environment             = local.environment<br>  }<br>  service_account {<br>    email  = google_service_account.blog_vm_sa.email<br>    scopes = [&quot;cloud-platform&quot;]<br>  }<br>}<br><br>output &quot;External_IP&quot; {<br>  value = google_compute_instance.blog_vm.network_interface[0].access_config[0].nat_ip<br>}</pre><p>Type CTRL+C to exit</p><blockquote>Take a look at the <strong>metadata_startup_script</strong> argument that will setup our blog on vm startup.</blockquote><p>The last resources we need are firewall rules to allow http traffic to blog on port 80 and ssh access on port 22.</p><p>4. Create <strong>firewall.tf</strong></p><pre>cat &gt; firewall.tf</pre><pre># Allow SSH<br>resource &quot;google_compute_firewall&quot; &quot;allow_ssh&quot; {<br>  name = &quot;${local.name}-fwrule-allow-ssh22&quot;<br>  allow {<br>    ports    = [&quot;22&quot;]<br>    protocol = &quot;tcp&quot;<br>  }<br>  direction     = &quot;INGRESS&quot;<br>  network       = google_compute_network.myvpc.id<br>  priority      = 1000<br>  source_ranges = [&quot;0.0.0.0/0&quot;]<br>  target_tags   = [&quot;ssh-tag&quot;]<br>}<br><br># Allow HTTP Port 80<br>resource &quot;google_compute_firewall&quot; &quot;allow_http&quot; {<br>  name = &quot;${local.name}-fwrule-allow-http80&quot;<br>  allow {<br>    ports    = [&quot;80&quot;]<br>    protocol = &quot;tcp&quot;<br>  }<br>  direction     = &quot;INGRESS&quot;<br>  network       = google_compute_network.myvpc.id<br>  priority      = 1000<br>  source_ranges = [&quot;0.0.0.0/0&quot;]<br>  target_tags   = [&quot;webserver-tag&quot;]<br>}</pre><p>Type CTRL+C to exit</p><blockquote>In production, allowing access from 0.0.0.0/0 is considered as poor security practice. To allow SSH access, I recommend using <a href="https://cloud.google.com/iap/docs/using-tcp-forwarding#tunneling_ssh_connections">IAP for TCP forwarding</a> which allows you to establish an encrypted tunnel over which you can forward SSH, RDP, and other traffic to VM instances. IAP TCP forwarding also provides you fine-grained control over which users are allowed to establish tunnels and which VM instances users are allowed to connect to.<br>In the next Part, we will also improve accessing our blog by implementing Load Balancer instead of exposing it directly to the internet.</blockquote><p>5. Run terraform validate and if configuration has no errors follow with terraform apply</p><pre>terraform validate<br>terraform apply</pre><p>When deployment completes, terraform outputs the external IP of GCE instance. You can test the blog in browser by using the following URL</p><pre>http://&lt;External_IP&gt;</pre><p>Don&#39;t forget to clean-up your lab resources</p><pre>terraform destroy</pre><p>Well done for deploying the blog on Google Cloud.</p><p>In <a href="https://medium.com/p/d497a6745141">Part 3</a>, we will deploy the blog to a Managed Instance Group and host it behind an HTTP(S) Load Balancer.</p><p>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b7974dbc111" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-2-deploy-3b7974dbc111">Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 2: Deploy…</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[Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 1: Building…]]></title>
            <link>https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-1-building-083c9ae4b56c?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/083c9ae4b56c</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 19:59:05 GMT</pubDate>
            <atom:updated>2024-10-07T02:22:20.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 1: Building Application</h3><p>This is a Part 1 of the tutorial: Building reliable and scalable infrastructure in Google Cloud Platform (GCP).</p><p>We will start with creating the config files for our sample blog followed by a local test to preview the website.</p><blockquote>You can also use <a href="https://marketplace.visualstudio.com/items?itemName=codespaces-Contrib.codeswing">CodeSwing</a> VS Code extension that enables a live preview of your HTML, CSS, and JavaScript code as you type.</blockquote><p>Once we are satisfied with our blog, we will gradually deploy it to Google Cloud Platform (GCP), with each stage focusing on enhancing reliability and scalability.</p><h4>Prerequisites</h4><ul><li>Docker</li></ul><h4>Step 1: Create the Blog HTML File</h4><ol><li>Create a directory for your project</li></ol><pre>mkdir nginx-blog<br>cd nginx-blog</pre><p>2. Create the blog.html file</p><pre>nano blog.html</pre><p>3. Add the following HTML content</p><pre><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;My Blog Page&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: Arial, sans-serif;<br>            margin: 40px;<br>            background-color: #f4f4f9;<br>            color: #333;<br>        }<br>        header {<br>            text-align: center;<br>            margin-bottom: 40px;<br>        }<br>        article {<br>            max-width: 800px;<br>            margin: 0 auto;<br>            padding: 20px;<br>            background-color: #fff;<br>            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);<br>        }<br>        h1 {<br>            color: #3b5998;<br>        }<br>        footer {<br>            text-align: center;<br>            margin-top: 40px;<br>            font-size: 0.8em;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;header&gt;<br>        &lt;h1&gt;Welcome to My Blog&lt;/h1&gt;<br>    &lt;/header&gt;<br>    &lt;article&gt;<br>        &lt;h2&gt;First Blog Post&lt;/h2&gt;<br>        &lt;p&gt;This is a sample blog post content. Here, you can write about anything you like. This is a simple HTML template to help you get started with your Nginx web server.&lt;/p&gt;<br>        &lt;h2&gt;Second Blog Post&lt;/h2&gt;<br>        &lt;p&gt;This is a second blog post content, where I have added my dog&#39;s photo.&lt;/p&gt;<br>        &lt;img src=&quot;my-dog.jpg&quot; alt=&quot;Blog Image&quot; style=&quot;max-width:80%; height:auto; display:block; margin: 20px auto;&quot;&gt;<br>    &lt;/article&gt;<br>    &lt;footer&gt;<br>        &amp;copy; 2024 My Blog<br>    &lt;/footer&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Save and close the file (CTRL + X, then Y, and ENTER). Feel free to modify the html the way you like.</p><h4>Step 2. Create a Dockerfile</h4><ol><li>Create a Dockerfile in the same directory</li></ol><pre>nano Dockerfile</pre><p>2. Add the following content to the Dockerfile</p><pre># Use the official Nginx image from Docker Hub<br>FROM nginx:latest<br><br># Copy the blog.html to the default Nginx web directory<br>COPY blog.html /usr/share/nginx/html/index.html<br><br># Copy the image to the default Nginx web directory<br>COPY my-dog.jpg /usr/share/nginx/html/my-dog.jpg</pre><p>This Dockerfile uses the official Nginx image and copies blog.html and my-dog.jpg file into the container’s default web directory, renaming it to index.html so that it is served as the home page.</p><h4>Step 3: Build and Run the Docker Container</h4><ol><li>Build the Docker image</li></ol><pre>docker build -t nginx-blog .</pre><p>2. Run the Docker container</p><pre>docker run -d -p 8080:80 --name nginx-blog-container nginx-blog</pre><blockquote>Detailed Explanation</blockquote><blockquote><strong>docker run</strong> — this is the Docker command to create and start a new container from a specified image.</blockquote><blockquote><strong>-d (detached mode) </strong>— runs the container in the background, allowing it to run independently without tying up the terminal. This means the container will run even after you close the terminal.</blockquote><blockquote><strong>-p 8080:80 (port mapping)</strong> — maps port 8080 on the host machine (your computer) to port 80 inside the container. This means that when you access http://localhost:8080 on your browser, the traffic will be directed to the container&#39;s web server running on port 80.</blockquote><blockquote><strong>--name nginx-blog-container</strong> — assigns a custom name (nginx-blog-container) to the running container.</blockquote><blockquote><strong>nginx-blog </strong>— the name of the Docker image that will be used to create the container.</blockquote><h4>Step 4: Test the Blog</h4><p>Open your web browser and use this url</p><pre>http://localhost:8080</pre><p>You can find the files for this part in my <a href="https://github.com/agapasieka/Deploy-Reliable-Infrastructure/tree/master/Part1-Develop-App">Github repo</a>.</p><h4>Step 5: Clean-up: delete container</h4><pre>docker rm -f nginx-blog-container</pre><p>And that’s all for this part.</p><p>Our blog is ready to be used it in <a href="https://agnieszkapasieka.medium.com/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-2-deploy-3b7974dbc111">Part 2</a> where we will deploy it to Google Compute Engine (GCE).</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=083c9ae4b56c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-reliable-and-scalable-infrastructure-in-google-cloud-platform-gcp-part-1-building-083c9ae4b56c">Building reliable and scalable infrastructure in Google Cloud Platform (GCP) Part 1: Building…</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[Understanding Proxy-only Subnets in Google Cloud Platform (GCP)]]></title>
            <link>https://medium.com/google-cloud/understanding-proxy-only-subnets-in-google-cloud-platform-gcp-7d886c41def3?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d886c41def3</guid>
            <category><![CDATA[envoy-proxy]]></category>
            <category><![CDATA[gcp-load-balancer]]></category>
            <category><![CDATA[network-security]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 11:47:20 GMT</pubDate>
            <atom:updated>2024-09-27T04:00:48.281Z</atom:updated>
            <content:encoded><![CDATA[<p>While working on building a new infrastructure project, I came across network feature called <a href="https://cloud.google.com/load-balancing/docs/proxy-only-subnets"><strong>Proxy-only Subnet</strong></a><strong>. </strong>Let’s break down the purpose of proxy-only subnets in GCP and how they work with Envoy-based load balancers.</p><h3>What Are Proxy-Only Subnets in GCP?</h3><p>A <strong>proxy-only subnet</strong> in GCP is a special kind of subnet designed to host only Google Cloud’s <strong>Envoy-based</strong> load balancing proxies, like the Google Cloud HTTP(S) Load Balancer. The main purpose of this subnet is to provide a centralized location where the Envoy proxies live and handle traffic for your backend services.</p><h3>How Proxy-Only Subnets Work</h3><p>In GCP, the HTTP(S) Load Balancer uses <a href="https://www.envoyproxy.io/#:~:text=Envoy%20is%20a%20self%20contained,1.1%20to%20HTTP%2F2%20proxy.">Envoy</a> as its proxy. When you set up such a load balancer, GCP will use a proxy-only subnet as the network location for these Envoy proxies.</p><p>Here’s a step-by-step explanation:</p><p><strong>1.Traffic enters the VPC</strong>: When a request is sent to load balancer, it first reaches the proxy-only subnet where the Envoy-based load balancer resides.</p><p><strong>2. The Envoy proxies handle traffic</strong>: The traffic is processed by the Envoy proxies in this subnet, applying load-balancing logic, routing rules, and security policies.</p><p><strong>3. Traffic is then forwarded</strong>: After processing, the traffic is forwarded from the proxy-only subnet to the target backend services or VMs in your other subnets.</p><p>This setup helps GCP separate the traffic management (handled by the Envoy proxies) from your backend services, improving scalability, security, and manageability.</p><h3>Supported load balancers</h3><ol><li>Proxy-only subnet with purpose <strong>GLOBAL_MANAGED_PROXY</strong>:</li></ol><ul><li><a href="https://cloud.google.com/load-balancing/docs/l7-internal">Cross-region internal Application Load Balancer</a></li><li><a href="https://cloud.google.com/load-balancing/docs/tcp/internal-proxy">Cross-region internal proxy Network Load Balancer</a></li></ul><p>2. Proxy-only subnet with purpose <strong>REGIONAL_MANAGED_PROXY</strong>:</p><ul><li><a href="https://cloud.google.com/load-balancing/docs/https">Regional external Application Load Balancer</a></li><li><a href="https://cloud.google.com/load-balancing/docs/l7-internal">Regional internal Application Load Balancer</a></li><li><a href="https://cloud.google.com/load-balancing/docs/tcp">Regional external proxy Network Load Balancer</a></li><li><a href="https://cloud.google.com/load-balancing/docs/tcp/internal-proxy">Regional internal proxy Network Load Balancer</a></li></ul><h3>Key Purposes and Benefits of Proxy-Only Subnets</h3><ul><li><strong>Separation of Proxy Layer from Backends:</strong> By having a proxy-only subnet, Envoy proxies are kept separate from your actual backend services. This separation helps isolate the traffic management layer from the application logic layer.</li><li><strong>Advanced Traffic Management</strong>: You can implement advanced routing features such as traffic splitting, canary deployments, or routing based on header information, all managed centrally through the Envoy proxies.</li><li><strong>Enhanced Security:</strong> Proxy-only subnets limit exposure since only the Envoy proxies reside there. Backend VMs or services aren’t directly exposed to the internet or other untrusted networks.</li><li><strong>Controlled Access</strong>: You can use firewall rules to control access to and from the proxy-only subnet, ensuring that only allowed traffic reaches your backend services.</li></ul><h3>Real-World Example in GCP</h3><p>Imagine you have an internal web application with multiple microservices running in different subnets across a GCP Virtual Private Cloud (VPC). You want to balance traffic between these services using the Internal HTTP(S) Load Balancer.</p><ul><li>You create a <strong>proxy-only subnet</strong> in your VPC to host the Envoy proxies.</li><li>Incoming requests hit the Envoy-based load balancer, which resides in the proxy-only subnet.</li><li>The load balancer applies the necessary routing logic and distributes traffic to your backend services.</li></ul><p>This separation ensures that traffic management happens in the proxy-only subnet, while your backend services remain isolated, scalable, and secure in their respective subnets.</p><h3>Summary</h3><p><strong>Proxy-only subnets</strong> in GCP serve the following primary purposes:</p><ul><li><strong>Isolate and manage Envoy-based proxies</strong> separately from backend services.</li><li><strong>Centralize traffic routing and management</strong> through a dedicated subnet for Envoy proxies.</li><li><strong>Improve security and scalability</strong> by separating traffic handling logic from application logic.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d886c41def3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/understanding-proxy-only-subnets-in-google-cloud-platform-gcp-7d886c41def3">Understanding Proxy-only Subnets in Google Cloud Platform (GCP)</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[Deploying Apps to GCP using Terraform]]></title>
            <link>https://agnieszkapasieka.medium.com/deploying-apps-to-gcp-using-terraform-f5e70b240356?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5e70b240356</guid>
            <category><![CDATA[google-kubernetes-engine]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[app-engine]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Wed, 25 Sep 2024 12:24:18 GMT</pubDate>
            <atom:updated>2024-09-25T12:32:01.593Z</atom:updated>
            <content:encoded><![CDATA[<p>In this lab, you will gain hands-on experience deploying a cloud-based application using Google Cloud Platform (GCP) services.</p><p>You will learn to build and push container images to <strong>Google Artifact Registry</strong> using Docker, preparing their application for deployment.</p><p>The lab will also introduce <strong>Google App Engine</strong> and <strong>Cloud Run</strong>, showcasing how to deploy containerized applications effortlessly while benefiting from automatic scaling and serverless capabilities.</p><p>Finally, the lab will demonstrate how to create a <strong>Kubernetes cluster</strong>, configure a Deployment resource to manage application instances, and expose the application using a Load Balancer Service.</p><h3>Prerequisites</h3><ul><li>Google Cloud Platform (GCP) Account</li><li>IAM Permissions on GCP project: Viewer, Editor, Kubernetes Engine Admin, Cloud Run Admin, Cloud Build Editor, Artifact Registrty Reader</li><li>Google Cloud SDK (gcloud)</li><li>Docker</li><li>Terraform</li></ul><h4>Clone the code for this lab and change directory to deploy_apps_to_gcp</h4><pre>git clone https://github.com/agapasieka/Terraform-GoogleCloudPlatform.git<br>cd Terraform-GoogleCloudPlatform/deploy_apps_to_gcp</pre><h4>Build test docker image and run application locally</h4><p>To build our test image and deploy to docker container for testing, head out to apps folder. We need the following config files:</p><ul><li>Dockerfile</li><li>main.py</li><li>requirements.txt</li><li>templates folder includes index.html and layout.html files</li></ul><ol><li>Build the test-python-app image</li></ol><pre>cd apps/<br>docker build -t test-python-app .</pre><p>2. Run the Docker container to test the app</p><pre>docker run --name hello-from-docker --rm -d -p 8080:8080 test-python-app</pre><p>3. Test the app in terminal</p><pre>curl -s http://localhost:8080 | awk -F&#39;&lt;h1&gt;|&lt;/h1&gt;&#39; &#39;/&lt;h1&gt;/ {print $2}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*YRBhGE3ny3I-NT1y5dvfuw.png" /></figure><p>4. Test the app in browser</p><pre>localhost:8080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rpWNfjM_AdpzyO74L23ZDA.png" /></figure><p>5. Delete the container and local image</p><pre>docker rm hello-from-docker -f<br>docker rmi test-python-app</pre><h3>Deploy to App Engine</h3><p>I will be using a similar app code for App Engine located in <strong>apps/app-engine/ </strong>folder. I changed the body message to say: <em>Hello from App Engine</em> so we can be sure each deployment succeeded.</p><p>Before we create any resources with terraform, verify the region defined in <strong>terraform.tfvars</strong> file. I used <em>europe-west1</em> but you can use any region of your choice.</p><p>Add your project ID in <strong>terraform.tfvars</strong>, uncomment the first line to look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*3NsztHgtYeMWy7LvicuYHQ.png" /></figure><p>To deploy to App Engine, we need to zip our code first and place it in the storage bucket</p><ol><li>In <strong>deploy-app-to-gcp/</strong> locate the <strong>bucket.tf</strong> file, uncomment the code and save the file. Make sure you are in <strong>deploy_apps_to_gcp/ </strong>directory</li></ol><p>2. Deploy with terraform</p><pre>cd ..<br>terraform init<br>terraform apply</pre><p>3. Now let’s deploy the App Engine. Uncomment code in <strong>app-engine.tf</strong> and save the file</p><pre>terraform apply  </pre><p>Wait for the deployment to finish. At the end terraform outputs the URL to an App Engine application. Click on the link to test the app</p><h3>Deploy to Cloud Run</h3><p>To use Cloud Run, you need to build a Docker image again and store it in Artifact Registry.</p><ol><li>Let’s first create an Artifact Registry repository named <strong>devops-repo</strong>. Uncomment code in <strong>artifact-registry.tf</strong> and save the file</li></ol><p>2. Deploy with terraform</p><pre>terraform apply</pre><p>3. Configure Docker to authenticate to the Artifact Registry Docker repository. I used <em>europe-west1</em> as my region for all resources but if you changed it in <strong>provider.tf</strong> in previous step, update it here too</p><pre> export REGION=europe-west1<br> gcloud auth configure-docker $REGION-docker.pkg.dev</pre><p>4. Build the image for Cloud Run. This time we will use Google Cloud Build to submit a build and create a container image. Change directory to <strong>apps/cloud-run</strong>/</p><pre>cd apps/cloud-run/<br>gcloud builds submit --tag $REGION-docker.pkg.dev/$DEVSHELL_PROJECT_ID/devops-repo/cloud-run-image:v0.1 .</pre><p>5. Deploy Cloud Run, uncomment the code in <strong>cloud-run.tf</strong>, save it and run below command</p><pre>cd ../../<br>terraform apply </pre><p>Wait for the deployment to finish. At the end terraform outputs the URL to a Cloud Run application. Click on the link to test the app</p><h3>Deploy to Kubernetes Engine</h3><p>To deploy an application to Kubernetes, you must first create the cluster. Next, you’ll need to provide a configuration file to enable the deployment of your application to the cluster. We will also build another Docker image using Cloud Build and store it in devops-repo Artifact Registry. <br>The Python app config files are located in <strong>apps/gke-config</strong> folder.</p><ol><li>Deploy GKE cluster and VPC, uncomment the code in <strong>vpc.tf</strong>, <strong>service-accounts.tf </strong>and <strong>gke.tf.</strong> These components depend on each other.</li></ol><p>2. We are using public terraform modules for vpc and gke so we must reinitialize terraform. Make sure you are still in <strong>deploy_apps_to_gcp</strong> directory</p><pre>terraform init<br>terraform apply</pre><blockquote>If you get a provider error, run <em>terraform init -upgrade</em></blockquote><p>3. Change directory to <strong>apps/gke-config/</strong> and build the image</p><pre>cd apps/gke-config/<br>gcloud builds submit --tag $REGION-docker.pkg.dev/$DEVSHELL_PROJECT_ID/devops-repo/gke-image:v0.1 .</pre><p>In <strong>apps/gke-config/</strong> directory locate file named <strong>kubernetes-config.yaml</strong>. This YAML file defines two key resources: a <em>Deployment</em> and a <em>Service</em>. <br>In <em>Deployment</em> section we are deploying 3 instances of our Python web app and specifying the image we just build. <br>A <em>Service</em> part provides an endpoint for accessing a set of pods, allowing for load balancing and discovery</p><p>4. Add image to <strong>kubernetes-config.yaml</strong>. Use nano or vim to edit the file</p><pre>nano kubernetes-config.yaml</pre><p>Look for line: <strong>&lt;YOUR IMAGE PATH HERE&gt;</strong> and replace with the image url we just created. Save the file by using <strong>Ctrl + X, Y, Enter</strong>.</p><p>5. Authenticate to cluster</p><pre>CLUSTER_NAME=$(gcloud container clusters list --project $DEVSHELL_PROJECT_ID --region $REGION --format &quot;value(name)&quot; | head -n 1)<br>gcloud container clusters get-credentials $CLUSTER_NAME --region $REGION --project $DEVSHELL_PROJECT_ID</pre><p>6. To deploy our application run the following command</p><pre>  kubectl apply -f kubernetes-config.yaml</pre><p>7. Verify whether three instances of application have been created</p><pre>  kubectl get pods</pre><p>8. Verify the load balancer IP address to test the application</p><pre>  kubectl get services</pre><p>If the load balancer’s external IP address says pending, wait a few seconds and try again.</p><p>9. To test the app, open the browser and use: <a href="http://external-ip:8080/">http://EXTERNAL-IP:8080</a></p><p>10. Alternatively, test with curl</p><pre>curl -s http://EXTERNAL-IP:8080 | awk -F&#39;&lt;h1&gt;|&lt;/h1&gt;&#39; &#39;/&lt;h1&gt;/ {print $2}&#39;</pre><h3>Lab clean-up</h3><pre>kubectl delete -f apps/gke-config/kubernetes-config.yaml<br>terraform destroy</pre><p>I hope you enjoyed this lab. Happy Learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5e70b240356" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run Python scripts directly from GitHub repository using Codespaces]]></title>
            <link>https://agnieszkapasieka.medium.com/run-python-scripts-directly-from-github-repository-using-codespaces-902468f50b0a?source=rss-7da4ac8f6c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/902468f50b0a</guid>
            <category><![CDATA[olympics]]></category>
            <category><![CDATA[code-first-girls]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-codespaces]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Agnieszka Pasieka]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 18:38:54 GMT</pubDate>
            <atom:updated>2024-09-17T18:38:54.702Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><a href="https://docs.github.com/en/codespaces/overview">GitHub Codespaces </a>is a cloud-based development environment that allows you to write, run, and debug code directly from your browser. It provides a full-featured, customizable Visual Studio Code experience without the need to set up a local development environment. <br>With Codespaces, you can instantly spin up environments tailored to your project’s needs, including all dependencies, making it easy to collaborate on code, run scripts, and test applications directly from a GitHub repository.</blockquote><p><strong>Open the Repository</strong>:</p><ul><li>Go to the GitHub repository you want to run the Python code from.<br>Here’s a script you can use: <a href="https://github.com/agapasieka/cfg-project-group5">https://github.com/agapasieka/cfg-project-group5</a>. It was my group project for completing the Python course offered by <a href="https://codefirstgirls.com/">Code First Girls</a>.</li></ul><p><strong>Launch Codespace</strong>:</p><ul><li>Click the green &lt;&gt; Code button at the top-right of the repository.</li><li>Select the Codespaces tab.</li><li>Click Create codespace on main (or select another branch if needed).</li></ul><p><strong>Wait for Codespace to Start</strong>:</p><ul><li>GitHub will automatically create a development environment. This might take a minute or two.</li></ul><p><strong>Run the Python Code</strong>:</p><ul><li>Navigate to the script or file you want to test in the terminal.</li><li>Run the Python script using python script_name.py. If you&#39;re using the above script, the command to run the script will be as follows:</li></ul><pre>python analyse_data_with_user_input_v2.py</pre><p><strong>Review Output</strong>:</p><ul><li>The output will appear in the terminal. You can make changes or debug directly in the Codespace.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-HUPqxb1-0GDF1cRvb4Zg.png" /></figure><p>If you’re an Olympics fan, feel free to explore the menu options to discover more details about the 2024 Olympics.</p><p>I hope this was something cool you learnt today :) Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=902468f50b0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>