<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: truc3651</title>
    <description>The latest articles on DEV Community by truc3651 (@truc3651).</description>
    <link>https://dev.to/truc3651</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F662327%2F0e03153a-f02c-4ea5-82ae-be2b172bb740.jpg</url>
      <title>DEV Community: truc3651</title>
      <link>https://dev.to/truc3651</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/truc3651"/>
    <language>en</language>
    <item>
      <title>Securing Your Credentials with AWS Secrets Manager and KMS: A Complete Guide</title>
      <dc:creator>truc3651</dc:creator>
      <pubDate>Thu, 13 Mar 2025 10:42:16 +0000</pubDate>
      <link>https://dev.to/truc3651/securing-your-credentials-with-aws-secrets-manager-and-kms-a-complete-guide-4m54</link>
      <guid>https://dev.to/truc3651/securing-your-credentials-with-aws-secrets-manager-and-kms-a-complete-guide-4m54</guid>
      <description>&lt;p&gt;In today's digital landscape, protecting sensitive information is paramount. Whether you're managing database passwords, API keys, or other credentials, proper encryption is essential. In this guide, we'll explore how AWS Secrets Manager and Key Management Service (KMS) work together to secure your sensitive data, starting with fundamental cryptographic concepts and building to practical implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Cryptographic Foundations
&lt;/h2&gt;

&lt;p&gt;Before diving into AWS services, let's establish a solid understanding of the core encryption mechanisms that power modern security systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Symmetric Encryption: Simple but Powerful
&lt;/h3&gt;

&lt;p&gt;Symmetric encryption uses a single key for both encryption and decryption. Think of it like a physical key to your house - the same key locks and unlocks the door.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strengths:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt;: Symmetric algorithms are computationally efficient, making them ideal for encrypting large amounts of data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: The underlying mathematical operations are relatively straightforward&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Weaknesses:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key distribution problem&lt;/strong&gt;: How do you securely share the key with others who need it?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No inherent authentication&lt;/strong&gt;: The encryption itself doesn't verify who encrypted the data&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Asymmetric Encryption: The Public-Private Pair
&lt;/h3&gt;

&lt;p&gt;Asymmetric encryption uses two mathematically related keys: a public key that can be freely shared and a private key that must be kept secret. Data encrypted with the public key can only be decrypted with the corresponding private key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strengths:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solves the key distribution problem&lt;/strong&gt;: You can freely share your public key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Perfect for establishing secure connections&lt;/strong&gt;: Enables secure communication between parties who have never previously shared secrets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Weaknesses:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Computationally expensive&lt;/strong&gt;: Much slower than symmetric encryption&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key size requirements&lt;/strong&gt;: Requires longer keys to achieve the same security level as symmetric encryption&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Envelope Encryption: The Best of Both Worlds
&lt;/h2&gt;

&lt;p&gt;Envelope encryption combines symmetric and asymmetric encryption to leverage the strengths of both while mitigating their weaknesses. Here's how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate a data encryption key (DEK) using symmetric encryption&lt;/li&gt;
&lt;li&gt;Encrypt the actual data using this DEK&lt;/li&gt;
&lt;li&gt;Encrypt the DEK using an asymmetric key or another symmetric key (called the key encryption key or KEK)&lt;/li&gt;
&lt;li&gt;Store the encrypted DEK alongside the encrypted data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance efficiency&lt;/strong&gt;: The bulk of the data is encrypted using fast symmetric encryption&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified key management&lt;/strong&gt;: You only need to manage the KEK securely, not every individual DEK&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced security&lt;/strong&gt;: Even if a single DEK is compromised, other encrypted data remains secure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key rotation capability&lt;/strong&gt;: You can re-encrypt the DEK with a new KEK without having to re-encrypt all the data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Example: TLS/SSL and Envelope Encryption
&lt;/h2&gt;

&lt;p&gt;The Transport Layer Security (TLS) protocol, which secures most internet traffic today, is a perfect example of envelope encryption in action.&lt;/p&gt;

&lt;p&gt;When you connect to a secure website (HTTPS), here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Certificate Exchange&lt;/strong&gt;: The server presents its digital certificate containing its public key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Key Generation&lt;/strong&gt;: Your browser generates a random symmetric session key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Exchange&lt;/strong&gt;: Your browser encrypts this session key using the server's public key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure Communication&lt;/strong&gt;: All further communication is encrypted using the symmetric session key&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process elegantly solves the primary challenges of both encryption types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asymmetric encryption is used briefly for the secure exchange of the session key&lt;/li&gt;
&lt;li&gt;The computationally efficient symmetric encryption handles the bulk data transfer&lt;/li&gt;
&lt;li&gt;No pre-shared secrets are required to establish a secure connection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's visualize this process:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foam9kw29ms79f08vefcz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foam9kw29ms79f08vefcz.png" alt="Image description" width="800" height="756"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Envelope Encryption with AWS KMS and Secrets Manager
&lt;/h2&gt;

&lt;p&gt;AWS Key Management Service (KMS) and Secrets Manager use envelope encryption to protect your sensitive data. Let's see how to implement this with AWS CLI commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Generate a Data Key using KMS
&lt;/h3&gt;

&lt;p&gt;First, we'll generate a data key that will be used to encrypt our secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws kms generate-data-key &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--key-id&lt;/span&gt; &lt;span class="nb"&gt;alias&lt;/span&gt;/my-kms-key &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--key-spec&lt;/span&gt; AES_256 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--output&lt;/span&gt; json &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; data-key.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command returns both:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A plaintext version of the data key (to use for encryption)&lt;/li&gt;
&lt;li&gt;An encrypted version of the data key (encrypted by the KMS key)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's extract both parts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;data-key.json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; .Plaintext &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; data-key-plaintext.base64
&lt;span class="nb"&gt;cat &lt;/span&gt;data-key.json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; .CiphertextBlob &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; data-key-encrypted.base64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Encrypt Your Secret Using the Data Key
&lt;/h3&gt;

&lt;p&gt;Now we'll use the data key to encrypt our actual secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Decode the base64 data key&lt;/span&gt;
&lt;span class="nb"&gt;cat &lt;/span&gt;data-key-plaintext.base64 | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; data-key-plaintext.bin

&lt;span class="c"&gt;# Encrypt our secret using OpenSSL with the data key&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"MyDatabasePassword123!"&lt;/span&gt; | openssl enc &lt;span class="nt"&gt;-aes-256-cbc&lt;/span&gt; &lt;span class="nt"&gt;-salt&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-in&lt;/span&gt; /dev/stdin &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-out&lt;/span&gt; secret-encrypted.bin &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-pass&lt;/span&gt; file:./data-key-plaintext.bin

&lt;span class="c"&gt;# For security, immediately remove the plaintext data key&lt;/span&gt;
&lt;span class="nb"&gt;rm &lt;/span&gt;data-key-plaintext.base64 data-key-plaintext.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Store Both in AWS Secrets Manager
&lt;/h3&gt;

&lt;p&gt;Now we need to store both the encrypted secret and the encrypted data key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Convert the encrypted secret to base64&lt;/span&gt;
&lt;span class="nb"&gt;base64 &lt;/span&gt;secret-encrypted.bin &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; secret-encrypted.base64

&lt;span class="c"&gt;# Create a JSON structure for our secret&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; secret-payload.json &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
{
  "encryptedSecret": "&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;secret-encrypted.base64&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;",
  "encryptedDataKey": "&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;data-key-encrypted.base64&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"
}
&lt;/span&gt;&lt;span class="no"&gt;EOF

&lt;/span&gt;&lt;span class="c"&gt;# Store in Secrets Manager&lt;/span&gt;
aws secretsmanager create-secret &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"my-database-credentials"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--secret-string&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;secret-payload.json&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Retrieving and Decrypting the Secret
&lt;/h3&gt;

&lt;p&gt;When you need to retrieve and decrypt your secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Get the secret from Secrets Manager&lt;/span&gt;
aws secretsmanager get-secret-value &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--secret-id&lt;/span&gt; &lt;span class="s2"&gt;"my-database-credentials"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; retrieved-secret.json

&lt;span class="c"&gt;# Extract the components&lt;/span&gt;
&lt;span class="nb"&gt;cat &lt;/span&gt;retrieved-secret.json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.SecretString'&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.encryptedDataKey'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; retrieved-data-key.base64
&lt;span class="nb"&gt;cat &lt;/span&gt;retrieved-secret.json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.SecretString'&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.encryptedSecret'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; retrieved-secret.base64

&lt;span class="c"&gt;# Decrypt the data key using KMS&lt;/span&gt;
aws kms decrypt &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--ciphertext-blob&lt;/span&gt; fileb://&amp;lt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;retrieved-data-key.base64 | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--output&lt;/span&gt; text &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--query&lt;/span&gt; Plaintext &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; decrypted-data-key.base64

&lt;span class="c"&gt;# Use the decrypted data key to decrypt the secret&lt;/span&gt;
&lt;span class="nb"&gt;cat &lt;/span&gt;retrieved-secret.base64 | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; retrieved-secret.bin
&lt;span class="nb"&gt;cat &lt;/span&gt;decrypted-data-key.base64 | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; decrypted-data-key.bin

openssl enc &lt;span class="nt"&gt;-aes-256-cbc&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-salt&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-in&lt;/span&gt; retrieved-secret.bin &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-pass&lt;/span&gt; file:./decrypted-data-key.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output your original secret: &lt;code&gt;MyDatabasePassword123!&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplifying with AWS Secrets Manager's Native Functionality
&lt;/h2&gt;

&lt;p&gt;The steps above explicitly demonstrate the envelope encryption process. However, AWS Secrets Manager handles most of this complexity for you. Here's how to use it more directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Store a secret more simply (KMS envelope encryption happens automatically)&lt;/span&gt;
aws secretsmanager create-secret &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"my-simple-credential"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--secret-string&lt;/span&gt; &lt;span class="s2"&gt;"MyDatabasePassword123!"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--kms-key-id&lt;/span&gt; &lt;span class="nb"&gt;alias&lt;/span&gt;/my-kms-key

&lt;span class="c"&gt;# Retrieve and automatically decrypt the secret&lt;/span&gt;
aws secretsmanager get-secret-value &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--secret-id&lt;/span&gt; &lt;span class="s2"&gt;"my-simple-credential"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--query&lt;/span&gt; SecretString &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--output&lt;/span&gt; text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Don't We Need to Provide the Data Key When Decrypting?
&lt;/h2&gt;

&lt;p&gt;You may have noticed that when retrieving secrets, we don't need to manually provide the data key. This is because of how AWS implements envelope encryption:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The encrypted data key is stored alongside your encrypted data&lt;/li&gt;
&lt;li&gt;When you request the secret, AWS automatically:

&lt;ul&gt;
&lt;li&gt;Retrieves the encrypted data key&lt;/li&gt;
&lt;li&gt;Decrypts it using the KMS key (if you have permission)&lt;/li&gt;
&lt;li&gt;Uses the decrypted data key to decrypt your actual secret&lt;/li&gt;
&lt;li&gt;Returns the plaintext secret to you&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AWS maintains a complete history of all the keys that have been used, allowing you to decrypt data even after key rotation. This key history management is handled by KMS, relieving you of this complex burden.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By using envelope encryption, AWS combines the performance benefits of symmetric encryption with the key management advantages of asymmetric approaches. This approach allows you to focus on building your applications while ensuring your secrets remain secure.&lt;/p&gt;

</description>
      <category>kms</category>
      <category>secret</category>
      <category>secretmanager</category>
      <category>aws</category>
    </item>
    <item>
      <title>Blue/green deployment with helm hands-on</title>
      <dc:creator>truc3651</dc:creator>
      <pubDate>Thu, 19 Dec 2024 17:36:13 +0000</pubDate>
      <link>https://dev.to/truc3651/bluegreen-deployment-with-helm-hands-on-458c</link>
      <guid>https://dev.to/truc3651/bluegreen-deployment-with-helm-hands-on-458c</guid>
      <description>&lt;h2&gt;
  
  
  QuickCap
&lt;/h2&gt;

&lt;p&gt;Kubernetes uses RollingUpdate as the default deployment strategy, which transition to new version gradually. &lt;/p&gt;

&lt;p&gt;Blue/green deployment strategy is about there're always 2 replica versions of application, this makes it easier to rollback to the previous version, if something goes wrong with the new release, and of course it's ideal for stateless application only.&lt;/p&gt;

&lt;h2&gt;
  
  
  Foreword
&lt;/h2&gt;

&lt;p&gt;This post is about give you an overview picture of how blue/green deployment. There's no good practices, and re-use code well. If it's your thing, coninue reading :))&lt;/p&gt;

&lt;h2&gt;
  
  
  Resource
&lt;/h2&gt;

&lt;p&gt;Clone repo: &lt;a href="https://github.com/truc3651/devops" rel="noopener noreferrer"&gt;https://github.com/truc3651/devops&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick look at the structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm51fwzh5biu9zqznyzc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm51fwzh5biu9zqznyzc4.png" alt="Image description" width="509" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Folder app contains everything for helm to release our app.&lt;br&gt;
app/templates: where application template resident (deployment, config, secret, service)&lt;br&gt;
app/Chart.yaml: release information (app name, version)&lt;br&gt;
app/values.yaml: default environment variables that helm will use when install/upgrade app&lt;/p&gt;

&lt;p&gt;deployment.sh: contains job visualize how blue/green deployment&lt;/p&gt;
&lt;h2&gt;
  
  
  Get your hands dirty
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Install helm, kind&lt;/strong&gt;&lt;br&gt;
We use kind as local Kubernetes clusters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install helm kind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a default cluster&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind create cluster --name helm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have 1 control-plane&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp46av84o8vv2f6vsx8nq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp46av84o8vv2f6vsx8nq.png" alt="Image description" width="512" height="84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change mod script&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x ./deployment.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;First time deploy your application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./deployment.sh init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just create a deployment with 1 pod (default version blue)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg4veqpemy0ncgznr4lw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg4veqpemy0ncgznr4lw.png" alt="Image description" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the beginning, service points to pod has label app=app&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9go8r606lkrh8fbfyg4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9go8r606lkrh8fbfyg4.png" alt="Image description" width="512" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Release a new version&lt;/strong&gt;&lt;br&gt;
After weeks, your development team want to release new features.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./deployment.sh deploy-green
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see blue pod has been terminated, and a new green pod has been created, also green deployment created as well.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sbqz2kxpg7wfzfsvrcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sbqz2kxpg7wfzfsvrcn.png" alt="Image description" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our service points to pod which has label color=green&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fro5ps24r37ibt5szv82p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fro5ps24r37ibt5szv82p.png" alt="Image description" width="484" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Release a new version 3rd time&lt;/strong&gt;&lt;br&gt;
After many weeks, your team want to introduce bunch cool features&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./deployment.sh deploy-new-blue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, green pod has been terminated, and a new blue pod has been created.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9uzer4dga2k6p8csbsn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9uzer4dga2k6p8csbsn.png" alt="Image description" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And our service points to pod which has label color=blue&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53ixtnx1l9jvbckewhsj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53ixtnx1l9jvbckewhsj.png" alt="Image description" width="514" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rollback&lt;/strong&gt;&lt;br&gt;
The very new version has some critical bugs, so our team decides to rollback to the previous version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./deployment.sh rollback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see now green alive&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvl3nw5b4rz56eyvihhk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvl3nw5b4rz56eyvihhk.png" alt="Image description" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

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