tag:blogger.com,1999:blog-7630972433831227692024-03-18T12:02:40.235+05:30Linux, DevOps, Middleware and CloudSharing knowledge on Linux, DevOps, Middleware and Cloud Technologies!!Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.comBlogger157125tag:blogger.com,1999:blog-763097243383122769.post-26031794029224385582020-04-01T11:22:00.003+05:302022-09-06T14:53:43.333+05:30Integrate Jenkins with Azure Key Vault<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-size: large;">Jenkins has been one of the most used CI/CD tools. For every tool which we are using in our daily life, it becomes really challenges when it comes to handling secret information. I know there are lots of tools available provided with PAAS or in house hosting solution. But we need those tools to support integration with different toolsets without many efforts. </span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">In this particular blog, we will be discussing the integration of Jenkins with the <a href="https://docs.microsoft.com/en-us/azure/key-vault/basic-concepts" target="_blank">Azure Key Vault</a>. Thanks to all the guys who are continuously working for different communities and spending time to make product more flexible and enhancing the product capabilities.</span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-CIxcODI-z8k/XoQePfLEOAI/AAAAAAAAEBc/1lXQOZkJFVwDqMnqrwj0GOhwhmMQcKqQgCLcBGAsYHQ/s1600/Untitled%2BDiagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="125" data-original-width="447" src="https://1.bp.blogspot.com/-CIxcODI-z8k/XoQePfLEOAI/AAAAAAAAEBc/1lXQOZkJFVwDqMnqrwj0GOhwhmMQcKqQgCLcBGAsYHQ/s1600/Untitled%2BDiagram.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-size: large;">We are going to use <a href="https://plugins.jenkins.io/azure-keyvault/" target="_blank">Azure Key Vault</a> plugin for this. There are multiple ways to use this. But in this post, we'll go through the integration and then testing using declarative pipelines.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Pre-Requisites-</span><br />
<br />
<ul style="text-align: left;">
<li><span style="font-size: large;">Make sure you have running Jenkins setup</span></li>
<li><span style="font-size: large;">You have valid Azure subscription</span></li>
</ul>
<div>
<span style="font-size: large;">Implementation Steps-</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> 1. Create an Azure Key Vault using the below steps:</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<br />
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az login
You have logged in. Now let us find all the subscriptions to which you have access...
[
{
"cloudName": "AzureCloud",
"id": "dd019fb5-db8a-4e4f-96ec-fc8decd2db8b",
"isDefault": true,
"name": "<<accountid>>",
"state": "Enabled",
"tenantId": "d52c9ea1-7c21-47b1-82a3-33a74b1f74b8",
"user": {
"name": "<span style="font-size: 15.104px;"><<accountid>></accountid></span><span style="font-size: 15.104px;">",</span>
"type": "user"
}
}
]</accountid></pre>
<div>
</div>
<br />
<div>
<span style="font-size: large;"><br /></span></div>
<br />
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az ad sp create-for-rbac --name http://local-jenkins
Found an existing application instance of "7e575c9b-b902-4510-8a06-8cbe1639aba3". We will patch it
Creating a role assignment under the scope of "/subscriptions/dd019fb5-db8a-4e4f-96ec-fc8decd2db8b"
Role assignment already exits.
{
"appId": "7e575c9b-b902-4510-8a06-8cbe1639aba3",
"displayName": "local-jenkins",
"name": "http://local-jenkins",
"password": "e7157115-6e35-46f9-a811-c856ba9bb5c0",
"tenant": "d52c9ea1-7c21-47b1-82a3-33a74b1f74b8"
}</pre>
<div>
</div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $RESOURCE_GROUP_NAME=my-resource-group
kulsharm2@WKMIN5257929:~$ ⚙️ $az group create --name $RESOURCE_GROUP_NAME -l "East US"
{
"id": "/subscriptions/dd019fb5-db8a-4e4f-96ec-fc8decd2db8b/resourceGroups/my-resource-group",
"location": "eastus",
"managedBy": null,
"name": "my-resource-group",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null,
"type": "Microsoft.Resources/resourceGroups"
}</pre>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az group show --name $RESOURCE_GROUP_NAME -o table
Location Name
---------- -----------------
eastus my-resource-group</pre>
<div>
</div>
<br />
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $VAULT=jenkins-local
kulsharm2@WKMIN5257929:~$ ⚙️ $az keyvault create --resource-group $RESOURCE_GROUP_NAME --name $VAULT
{
"id": "/subscriptions/dd019fb5-db8a-4e4f-96ec-fc8decd2db8b/resourceGroups/my-resource-group/providers/Microsoft.KeyVault/vaults/jenkins-local",
"location": "eastus",
"name": "jenkins-local",
"properties": {
"accessPolicies": [
{
"applicationId": null,
"objectId": "fd5bcd48-13d1-40c5-98a3-d46442c5194e",
"permissions": {
"certificates": [
.
.
<<long output="" truncated="">></long></pre>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az keyvault list -o table
Location Name ResourceGroup
---------- ------------- -----------------
eastus jenkins-local my-resource-group</pre>
</div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az keyvault set-policy --resource-group $RESOURCE_GROUP_NAME --name $VAULT --secret-permissions get list --spn http://local-jenkins
{
"id": "/subscriptions/dd019fb5-db8a-4e4f-96ec-fc8decd2db8b/resourceGroups/my-resource-group/providers/Microsoft.KeyVault/vaults/jenkins-local",
"location": "eastus",
"name": "jenkins-local",
"properties": {
"accessPolicies": [
{
"applicationId": null,
"objectId": "fd5bcd48-13d1-40c5-98a3-d46442c5194e",
"permissions": {
"certificates": [
"get",
"list",
"delete",
"create",
"import",
"update",
"managecontacts",
"getissuers",
"listissuers",
"setissuers",
"deleteissuers",
"manageissuers",
<span style="font-size: 15.104px;"><<long output="" truncated="">></long></span></pre>
</div>
<div style="text-align: left;">
<span style="font-size: large;"> 2. Create one secret in the Azure Key Vault :</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">kulsharm2@WKMIN5257929:~$ ⚙️ $az keyvault secret set --vault-name $VAULT --name secret-key --value my-super-secret
{
"attributes": {
"created": "2020-04-01T05:18:37+00:00",
"enabled": true,
"expires": null,
"notBefore": null,
"recoveryLevel": "Purgeable",
"updated": "2020-04-01T05:18:37+00:00"
},
"contentType": null,
"id": "https://jenkins-local.vault.azure.net/secrets/secret-key/85a36fe61ba34f53b60217c5e08f1774",
"kid": null,
"managed": null,
"tags": {
"file-encoding": "utf-8"
},
"value": "my-super-secret"
}</pre>
</div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 3. Let's make changes on Jenkins side to complete the integration:</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 1. Install the plugin as below:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-sR8LviM_bl0/XoQlSvFPhYI/AAAAAAAAEB8/x8LaUcCgiwwSZXNY748bP9YPYtclLRKsQCLcBGAsYHQ/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="455" data-original-width="1600" height="182" src="https://1.bp.blogspot.com/-sR8LviM_bl0/XoQlSvFPhYI/AAAAAAAAEB8/x8LaUcCgiwwSZXNY748bP9YPYtclLRKsQCLcBGAsYHQ/s640/2.png" width="640" /></a></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> 2. Add the Azure Key Vault URL to Jenkins Configuration following "Manage Jenkins --> Configure System" as below :</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ginqIOE8ByA/XoQqkUmpGfI/AAAAAAAAEDU/EkYgCha9gQ4et7YF5aNiTdWsdRYVA4TtQCLcBGAsYHQ/s1600/Screenshot%2B2020-04-01%2Bat%2B11.14.37%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="323" data-original-width="1600" height="128" src="https://1.bp.blogspot.com/-ginqIOE8ByA/XoQqkUmpGfI/AAAAAAAAEDU/EkYgCha9gQ4et7YF5aNiTdWsdRYVA4TtQCLcBGAsYHQ/s640/Screenshot%2B2020-04-01%2Bat%2B11.14.37%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> </span><span style="font-size: large;"> </span></div>
<div>
<span style="font-size: large;"> 4. Add credentials by going through "Credentials --> System --> Global Credentials(unrestricted)" as below:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-QZZOMJfkDZc/XoQmH0BdrnI/AAAAAAAAECE/Un7Eth6pU08jCLEmR3VmL0oqZoUEFrczwCLcBGAsYHQ/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="507" data-original-width="1600" height="202" src="https://1.bp.blogspot.com/-QZZOMJfkDZc/XoQmH0BdrnI/AAAAAAAAECE/Un7Eth6pU08jCLEmR3VmL0oqZoUEFrczwCLcBGAsYHQ/s640/3.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<span style="font-size: large;"> </span></div>
<div>
<span style="font-size: large;"> 5. Create new credential as below-</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-44avsJBjRUs/XoQo1BjY4pI/AAAAAAAAECs/SB9CRhFd7UYq4CtlIJtDWKDnpxdE20U4QCLcBGAsYHQ/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="684" data-original-width="1600" height="272" src="https://1.bp.blogspot.com/-44avsJBjRUs/XoQo1BjY4pI/AAAAAAAAECs/SB9CRhFd7UYq4CtlIJtDWKDnpxdE20U4QCLcBGAsYHQ/s640/5.png" width="640" /></a></div>
<div>
<span style="font-size: large;"> </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> 6. Now, let's create a pipeline and try to fetch the secret we stored in AKV:</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">*** Pipeline Code ***
pipeline {
agent any
environment {
SECRET_KEY = credentials('secret-key')
}
stages {
stage('Foo') {
steps {
echo SECRET_KEY
echo SECRET_KEY.substring(0, SECRET_KEY.size() -1) // shows the right secret was loaded, don't do this for real secrets unless you're debugging
}
}
}
}</pre>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6zYWBuHNV74/XoQroHw8tWI/AAAAAAAAEDg/qA_dBCRDM-oYqveFGyBfWEw3KJu9SL0cwCLcBGAsYHQ/s1600/6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="631" data-original-width="1600" height="252" src="https://1.bp.blogspot.com/-6zYWBuHNV74/XoQroHw8tWI/AAAAAAAAEDg/qA_dBCRDM-oYqveFGyBfWEw3KJu9SL0cwCLcBGAsYHQ/s640/6.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Happy Learning!!</span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-77194056184323440072020-03-22T20:54:00.001+05:302020-03-22T21:03:55.500+05:30How to handle packaging in python using __init__.py <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ESkPjb85HWI/Xnd2W_78DVI/AAAAAAAAD_8/o9M5896qb6Uvfhj3DoTXPdXWamrgUhlSwCLcBGAsYHQ/s1600/Screenshot%2B2020-03-22%2Bat%2B7.57.31%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="178" data-original-width="542" src="https://1.bp.blogspot.com/-ESkPjb85HWI/Xnd2W_78DVI/AAAAAAAAD_8/o9M5896qb6Uvfhj3DoTXPdXWamrgUhlSwCLcBGAsYHQ/s1600/Screenshot%2B2020-03-22%2Bat%2B7.57.31%2BPM.png" /></a></div>
<br />
<span style="font-size: large;">Keeping in mind the current situation across the world. I hope everyone is doing good. Please take precautions and stay at home and keep your self busy in whatever way you want to be.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">I was reading the book "Python for DevOps" and came across the topic "Packaging". In every business, packaging plays a big role while it comes to product distribution. </span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">While it comes to IT software usually, below are the few things which should take care of :</span><br />
<br />
<ul style="text-align: left;">
<li><span style="font-size: large;">Descriptive Versioning </span></li>
<ul>
<li><span style="font-size: large;">In Python packages, the following two variants are used:</span></li>
<ul>
<li><span style="font-size: large;">major.minor</span></li>
<li><span style="font-size: large;">major.minor.micro</span></li>
</ul>
<li><span style="font-size: large;">major - for backward-incompatible changes</span></li>
<li><span style="font-size: large;">minor - adds features that are also backward compatible</span></li>
<li><span style="font-size: large;">micro - adds backward-compatible bug fixes.</span></li>
</ul>
</ul>
<br />
<ul style="text-align: left;">
<li><span style="font-size: large;">The Changelog</span></li>
<ul>
<li><span style="font-size: large;">This is a simple file that keeps track of all the changes we will be doing for each version upgrade.</span></li>
</ul>
</ul>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Not going in detail here, coming directly to implementation on how we can handle packaging in python using the "__init__.py" file. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">The tool used here for packaging is "<i>setuptools</i>" python module.</span></div>
<div>
<span style="font-size: large;">Now we'll create python virtual environment and add "<i>setuptools</i>" there as below - </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">$ python3 -m venv /tmp/packaging
$ source /tmp/packaging/bin/activate</pre>
</div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">$ pip3 install setuptools</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_Hdmtjo3KEk/Xnd8Idg0plI/AAAAAAAAEAg/ZNjUhyFCGio4AcWBb0tZ6sfZVuF7KshDACLcBGAsYHQ/s1600/Screenshot%2B2020-03-22%2Bat%2B8.22.55%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="403" data-original-width="1600" height="160" src="https://1.bp.blogspot.com/-_Hdmtjo3KEk/Xnd8Idg0plI/AAAAAAAAEAg/ZNjUhyFCGio4AcWBb0tZ6sfZVuF7KshDACLcBGAsYHQ/s640/Screenshot%2B2020-03-22%2Bat%2B8.22.55%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Tip - you can cross check the list of installed modules using pip3 as below.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-UlmBC9Vymys/Xnd8t0DXPhI/AAAAAAAAEAk/61sHCAU4fGkaVUwHYN4xiGKh4WnWbuFlwCLcBGAsYHQ/s1600/Screenshot%2B2020-03-22%2Bat%2B8.25.01%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="294" data-original-width="1600" height="115" src="https://1.bp.blogspot.com/-UlmBC9Vymys/Xnd8t0DXPhI/AAAAAAAAEAk/61sHCAU4fGkaVUwHYN4xiGKh4WnWbuFlwCLcBGAsYHQ/s640/Screenshot%2B2020-03-22%2Bat%2B8.25.01%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Now, let's see the code. I have simple hello-world examples as below</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $tree .
.
├── README
├── hello_world
│ ├── __init__.py
│ ├── hello_python.py
│ └── hello_world.py
└── setup.py
1 directory, 5 files</pre>
</div>
<div>
<span style="font-size: large;">Note -</span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-size: large;">README - simple instructions</span></li>
<li><span style="font-size: large;">hello_world(directory) - module name</span></li>
<li><span style="font-size: large;">__int__.py - organize modules while keeping them in directory</span></li>
<li><span style="font-size: large;">hello_*.py - two different module with different functionality</span></li>
<li><span style="font-size: large;">setup.py - required by "setuptools" to build a package.</span></li>
</ul>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
<div>
<span style="font-size: large;">Source code is available on GitHub page as well.</span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat hello_world/hello_world.py
def helloworld():
return "HELLO WORLD"</pre>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat hello_world/hello_python.py
def hellopython():
return "HELLO PYTHON3" </pre>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat hello_world/__init__.py
from .hello_python import hellopython
from .hello_world import helloworld</pre>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat setup.py
from setuptools import setup, find_packages
setup(
name="hello_example",
version="0.0.1",
author="Example Author",
author_email="author@example.com",
url="example.com",
description="A hello-world example package",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)</pre>
</div>
<div>
<span style="font-size: large;">Now, lets start packaging our hello world program:</span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $python3 setup.py sdist
running sdist
running egg_info
creating hello_example.egg-info
writing hello_example.egg-info/PKG-INFO
writing dependency_links to hello_example.egg-info/dependency_links.txt
writing top-level names to hello_example.egg-info/top_level.txt
writing manifest file 'hello_example.egg-info/SOURCES.txt'
reading manifest file 'hello_example.egg-info/SOURCES.txt'
writing manifest file 'hello_example.egg-info/SOURCES.txt'
running check
creating hello_example-0.0.1
creating hello_example-0.0.1/hello_example.egg-info
creating hello_example-0.0.1/hello_world
copying files to hello_example-0.0.1...
copying README -> hello_example-0.0.1
copying setup.py -> hello_example-0.0.1
copying hello_example.egg-info/PKG-INFO -> hello_example-0.0.1/hello_example.egg-info
copying hello_example.egg-info/SOURCES.txt -> hello_example-0.0.1/hello_example.egg-info
copying hello_example.egg-info/dependency_links.txt -> hello_example-0.0.1/hello_example.egg-info
copying hello_example.egg-info/top_level.txt -> hello_example-0.0.1/hello_example.egg-info
copying hello_world/__init__.py -> hello_example-0.0.1/hello_world
copying hello_world/hello_python.py -> hello_example-0.0.1/hello_world
copying hello_world/hello_world.py -> hello_example-0.0.1/hello_world
Writing hello_example-0.0.1/setup.cfg
creating dist
Creating tar archive
removing 'hello_example-0.0.1' (and everything under it)</pre>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">After this, you will see that the above command has created other folders as well and our packaged module has been stored in "<i>dist</i>" folder.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $tree .
.
├── README
├── dist
│ └── <i><b>hello_example-0.0.1.tar.gz</b></i>
├── hello_example.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ └── top_level.txt
├── hello_world
│ ├── __init__.py
│ ├── hello_python.py
│ └── hello_world.py
└── setup.py
3 directories, 10 files</pre>
</div>
<div>
<span style="font-size: large;">Now let's install and list down the modules using "<i>pip3</i>".</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $pip3 install dist/hello_example-0.0.1.tar.gz
Processing ./dist/hello_example-0.0.1.tar.gz
Installing collected packages: hello-example
Running setup.py install for hello-example ... done
Successfully installed hello-example-0.0.1
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $ pip3 list --format=columns
Package Version
------------- -------
<b><i>hello-example 0.0.1 </i></b>
pip 20.0.2
setuptools 41.2.0 </pre>
</div>
<div>
<span style="font-size: large;">As the module has been installed, let's test this first using "ipyhon" console and then using the python program.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $ipython3
/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py:931: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.7.7 (default, Mar 10 2020, 15:43:03)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import hello_world as hw
In [2]: hw.hellopython()
Out[2]: 'HELLO PYTHON3'
In [3]: hw.helloworld()
Out[3]: 'HELLO WORLD'
In [4]:</pre>
</div>
<div>
<span style="font-size: large;">Here you saw that I can call the function using my custom module "hello_world". </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Using this module in the program-</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border-bottom-color: rgb(221, 221, 221) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-width: 0px; border-right-width: 0px; border-top-color: rgb(221, 221, 221) !important; border-top-style: solid !important; border-top-width: 1px !important; box-sizing: border-box; color: #404040; font-family: "Droid Sans Mono", Courier, monospace !important; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: 1.5em !important; margin-bottom: 1.5em !important; orphans: 2; padding: 1em 2em !important; vertical-align: baseline; widows: 2; word-break: keep-all !important;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat example.py
import hello_world as hw
print("Calling Hello Python Function: "+hw.hellopython())
print("Calling Hello World Function: "+hw.helloworld())
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $python3 example.py
Calling Hello Python Function: HELLO PYTHON3
Calling Hello World Function: HELLO WORLD
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $</pre>
</div>
<div>
<br />
<span style="font-size: large;">Now, let's suppose you want to upgrade to version "0.0.2", then we will follow the below steps -</span><br />
<span style="font-size: large;"><br /></span>
<pre data-type="programlisting" style="background-color: #fbfbfb; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-width: 1px 0px; box-sizing: border-box; color: #404040; font-size: 15.104px; font-stretch: inherit; line-height: 1.5em; margin-bottom: 1.5em; padding: 1em 2em; vertical-align: baseline; word-break: keep-all;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat hello_world/hello_python.py
def hellopython():
return "HELLO PYTHON3 with version <b><i>**0.0.2**</i></b>"
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat hello_world/hello_world.py
def helloworld():
return "HELLO WORLD with version <b><i>** 0.0.2 **</i></b>"
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $cat setup.py
from setuptools import setup, find_packages
setup(
name="hello_example",
version="<b><i>0.0.2</i></b>",
author="Example Author",
author_email="author@example.com",
url="example.com",
description="A hello-world example package",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)</pre>
<span style="font-size: large;">Package it again - </span><br />
<pre data-type="programlisting" style="background-color: #fbfbfb; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-width: 1px 0px; box-sizing: border-box; color: #404040; font-size: 15.104px; font-stretch: inherit; line-height: 1.5em; margin-bottom: 1.5em; padding: 1em 2em; vertical-align: baseline; word-break: keep-all;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $ python3 setup.py sdist
running sdist
running egg_info
writing hello_example.egg-info/PKG-INFO
writing dependency_links to hello_example.egg-info/dependency_links.txt
writing top-level names to hello_example.egg-info/top_level.txt
reading manifest file 'hello_example.egg-info/SOURCES.txt'
writing manifest file 'hello_example.egg-info/SOURCES.txt'
running check
creating hello_example-0.0.2
creating hello_example-0.0.2/hello_example.egg-info
creating hello_example-0.0.2/hello_world
copying files to hello_example-0.0.2...
copying README -> hello_example-0.0.2
copying setup.py -> hello_example-0.0.2
copying hello_example.egg-info/PKG-INFO -> hello_example-0.0.2/hello_example.egg-info
copying hello_example.egg-info/SOURCES.txt -> hello_example-0.0.2/hello_example.egg-info
copying hello_example.egg-info/dependency_links.txt -> hello_example-0.0.2/hello_example.egg-info
copying hello_example.egg-info/top_level.txt -> hello_example-0.0.2/hello_example.egg-info
copying hello_world/__init__.py -> hello_example-0.0.2/hello_world
copying hello_world/hello_python.py -> hello_example-0.0.2/hello_world
copying hello_world/hello_world.py -> hello_example-0.0.2/hello_world
Writing hello_example-0.0.2/setup.cfg
Creating tar archive
removing 'hello_example-0.0.2' (and everything under it)</pre>
<span style="font-size: large;">Install new version -</span><br />
<span style="font-size: large;"><br /></span>
<pre data-type="programlisting" style="background-color: #fbfbfb; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-width: 1px 0px; box-sizing: border-box; color: #404040; font-size: 15.104px; font-stretch: inherit; line-height: 1.5em; margin-bottom: 1.5em; padding: 1em 2em; vertical-align: baseline; word-break: keep-all;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $pip3 install dist/hello_example-0.0.2.tar.gz
Processing ./dist/hello_example-0.0.2.tar.gz
Installing collected packages: hello-example
Attempting uninstall: hello-example
<b><i> Found existing installation: hello-example 0.0.1
Uninstalling hello-example-0.0.1:
Successfully uninstalled hello-example-0.0.1
Running setup.py install for hello-example ... done
Successfully installed hello-example-0.0.2</i></b></pre>
<span style="font-size: large;">Verify the installation - </span><br />
<pre data-type="programlisting" style="background-color: #fbfbfb; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-width: 1px 0px; box-sizing: border-box; color: #404040; font-size: 15.104px; font-stretch: inherit; line-height: 1.5em; margin-bottom: 1.5em; padding: 1em 2em; vertical-align: baseline; word-break: keep-all;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $ pip3 list --format=columns
Package Version
------------- -------
hello-example 0.0.2
pip 20.0.2
setuptools 41.2.0 </pre>
<span style="font-size: large;">Test again using the python program -</span><br />
<span style="font-size: large;"><br /></span>
<pre data-type="programlisting" style="background-color: #fbfbfb; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-width: 1px 0px; box-sizing: border-box; color: #404040; font-size: 15.104px; font-stretch: inherit; line-height: 1.5em; margin-bottom: 1.5em; padding: 1em 2em; vertical-align: baseline; word-break: keep-all;">(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $python3 example.py
<b><i>Calling Hello Python Function: HELLO PYTHON3 with version **0.0.2**
Calling Hello World Function: HELLO WORLD with version ** 0.0.2 **</i></b>
(packaging) kulsharm2@WKMIN5257929:/tmp/hello_world$ ⚙️ $</pre>
<br /></div>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-62408460015683613012019-11-27T15:13:00.000+05:302019-11-27T16:19:49.670+05:30Deploy and Scale Kubernetes Application using Spinnaker<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Deploy and Scale Kubernetes Application using Spinnaker-</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-wO3sjjifHaQ/Xd477n2-z8I/AAAAAAAAD4s/DSH1Kk4DBKwqjEqV27nF5K6xUvlZI4CHACLcBGAsYHQ/s1600/spinnaker%2Band%2Bkubernetes.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="600" data-original-width="800" height="480" src="https://1.bp.blogspot.com/-wO3sjjifHaQ/Xd477n2-z8I/AAAAAAAAD4s/DSH1Kk4DBKwqjEqV27nF5K6xUvlZI4CHACLcBGAsYHQ/s640/spinnaker%2Band%2Bkubernetes.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">In my last post <a href="https://linuxhelp4u.blogspot.com/2019/11/getting-started-with-spinnaker-locally.html" target="_blank">Getting started with Spinnaker</a>, we completed the installation and setup part of spinnaker. In this post, I'll be going through the "Deploying and Scaling application on Kubernetes using spinnaker".</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">In this particular exercise, we'll create a simple "nginx" deployment on kubernetes and expose that as a service. After that we'll see how we can scale up and down the deployment easily from Spinnaker Dashboard itself.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Fot this, first make sure we have done port-forwarding for required pods and able to access Spinnaker Dashboard. </span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Note - Before moving ahead, please make sure that "kubernetes" provider is enabled. You can check this on "Halyard" configuration as below.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><i>$ kubectl exec -it spinnaker-local-spinnake-halyard-0 /bin/bash -n spinnaker</i></span><br />
<span style="font-size: large;"><i>$ hal config list | grep -A 37 kubernetes</i></span><br />
<span style="font-size: large;"><i><br /></i></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-cQ0n9nlHKY8/Xd5Ur_KkReI/AAAAAAAAD70/aFuyU8XutfIxSXgnRaNUDeK3RuPdMGFcQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B4.16.09%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="88" data-original-width="1600" height="34" src="https://1.bp.blogspot.com/-cQ0n9nlHKY8/Xd5Ur_KkReI/AAAAAAAAD70/aFuyU8XutfIxSXgnRaNUDeK3RuPdMGFcQCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B4.16.09%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-20AtiBFVuTE/Xd5Utkm5xHI/AAAAAAAAD74/REVZ8MOhMsI3QSYE8u9UhyWKEUHtUbwagCLcBGAsYHQ/s1600/provider-enable.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="516" data-original-width="1600" height="206" src="https://1.bp.blogspot.com/-20AtiBFVuTE/Xd5Utkm5xHI/AAAAAAAAD74/REVZ8MOhMsI3QSYE8u9UhyWKEUHtUbwagCLcBGAsYHQ/s640/provider-enable.png" width="640" /></a></div>
<span style="font-size: large;"><i><br /></i></span>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">After that click on the Create Application in Application tab to below popup.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-VEi7Fy3LGjs/Xd4-Fx08_hI/AAAAAAAAD5I/LsASXa63oX8Eny0fBAYLu5Hq3dboIcAZACLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B2.42.38%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="748" data-original-width="1600" height="298" src="https://1.bp.blogspot.com/-VEi7Fy3LGjs/Xd4-Fx08_hI/AAAAAAAAD5I/LsASXa63oX8Eny0fBAYLu5Hq3dboIcAZACLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B2.42.38%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">After filling the required information and hitting the create button. You'll get landed on </span><span style="font-size: large;">below screen.</span></div>
<div>
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><a href="https://1.bp.blogspot.com/-LULk3hXpHXY/Xd4-dtPPDoI/AAAAAAAAD5Q/X7FF5OzuyHQaBmwT1HsVLk1SSWwKtXV7gCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B2.43.31%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1600" height="356" src="https://1.bp.blogspot.com/-LULk3hXpHXY/Xd4-dtPPDoI/AAAAAAAAD5Q/X7FF5OzuyHQaBmwT1HsVLk1SSWwKtXV7gCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B2.43.31%2BPM.png" width="640" /></a></span></div>
<span style="font-size: large;">
</span></div>
<div>
<span style="font-size: large;">There are few other terms which you can check on documents like "Clusters, Load Balancers, Server Group" etc.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Here, we'll create a Server Group which will basically contain our deployment manifest(below).</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<pre style="white-space: pre-wrap; word-wrap: break-word;"><i>---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30000
selector: </i></pre>
<div>
<i><span style="white-space: pre-wrap;"> app: nginx</span><span style="font-size: large;"> </span></i></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Once you click on "Create Server Group", You'll see below screen where we need to paste above yaml and hit create.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-sjH6njTUTSg/Xd4__gl-ayI/AAAAAAAAD5c/233KmxNVq3sn82EhlzN_T2a9zY_J45I1wCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B2.49.44%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1600" height="356" src="https://1.bp.blogspot.com/-sjH6njTUTSg/Xd4__gl-ayI/AAAAAAAAD5c/233KmxNVq3sn82EhlzN_T2a9zY_J45I1wCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B2.49.44%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Below will be the end state, if everything goes well.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-cD_Xd2KR1rc/Xd5APUhVmGI/AAAAAAAAD5w/JWdB7jkIbVU5SOi8rspDJ2hh0cGaHyUdQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B2.51.33%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1600" height="356" src="https://1.bp.blogspot.com/-cD_Xd2KR1rc/Xd5APUhVmGI/AAAAAAAAD5w/JWdB7jkIbVU5SOi8rspDJ2hh0cGaHyUdQCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B2.51.33%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Now, lets inspect our deployment. </span></div>
<div>
<span style="font-size: large;">On Cluster tab we can see the deployment and number of replicas(pod) available in this deployment as below -</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-8cfi5VMm-pE/Xd5Av8lribI/AAAAAAAAD58/IffMQJYs-p86vyLfj9TrAj9rumJh6iHyACLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B2.54.03%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1600" height="356" src="https://1.bp.blogspot.com/-8cfi5VMm-pE/Xd5Av8lribI/AAAAAAAAD58/IffMQJYs-p86vyLfj9TrAj9rumJh6iHyACLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B2.54.03%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Please verify the same from CLI using kubectl-</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Az5e2hgQwG8/Xd5BfKgQCmI/AAAAAAAAD6E/dG6tuEawq4wVrUytH_T7t1j3wCQghtsTgCLcBGAsYHQ/s1600/k8s-cli-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1600" height="356" src="https://1.bp.blogspot.com/-Az5e2hgQwG8/Xd5BfKgQCmI/AAAAAAAAD6E/dG6tuEawq4wVrUytH_T7t1j3wCQghtsTgCLcBGAsYHQ/s640/k8s-cli-1.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Check for the services in Load Balancer Section -</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-V8mE9iFPQGk/Xd5CICnyqiI/AAAAAAAAD6M/0Krg3Z2vwSEL0gCwn0iDaPxHqiKRtNE8wCLcBGAsYHQ/s1600/k8s-cli-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="888" data-original-width="1600" height="354" src="https://1.bp.blogspot.com/-V8mE9iFPQGk/Xd5CICnyqiI/AAAAAAAAD6M/0Krg3Z2vwSEL0gCwn0iDaPxHqiKRtNE8wCLcBGAsYHQ/s640/k8s-cli-2.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Verify same using CLI -</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qWLpaoNtM5w/Xd5CZPUwpfI/AAAAAAAAD6U/y_OtlKE2PwAlgJZoCMPqQ94HpOOWCWyUgCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B3.01.02%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="108" data-original-width="1600" height="42" src="https://1.bp.blogspot.com/-qWLpaoNtM5w/Xd5CZPUwpfI/AAAAAAAAD6U/y_OtlKE2PwAlgJZoCMPqQ94HpOOWCWyUgCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B3.01.02%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Access the service -</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-7pokdqA_uZs/Xd5CwfN_IeI/AAAAAAAAD6c/gifFAkhPeoM9aQO7Z-vLnNwxroICG1RPQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B3.02.04%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="108" data-original-width="1600" height="42" src="https://1.bp.blogspot.com/-7pokdqA_uZs/Xd5CwfN_IeI/AAAAAAAAD6c/gifFAkhPeoM9aQO7Z-vLnNwxroICG1RPQCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B3.02.04%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-UUkW7AOL_oc/Xd5CwfoWdNI/AAAAAAAAD6g/_PG88FwP9nExA1zW_BjmkWYsyAuOjJbhwCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B3.02.27%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="369" data-original-width="1600" height="146" src="https://1.bp.blogspot.com/-UUkW7AOL_oc/Xd5CwfoWdNI/AAAAAAAAD6g/_PG88FwP9nExA1zW_BjmkWYsyAuOjJbhwCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B3.02.27%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<br /></div>
<div>
<span style="font-size: large;">Scale up the Deployment from 1 to 4 pods and verify the results-</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-9zjHh9p6Yx4/Xd5Dw30mY8I/AAAAAAAAD60/oJ_m5KzSZuoaDVeiu08CEC8U9OFxUpm9wCEwYBhgL/s1600/Screenshot%2B2019-11-27%2Bat%2B3.03.53%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="369" data-original-width="1600" height="146" src="https://1.bp.blogspot.com/-9zjHh9p6Yx4/Xd5Dw30mY8I/AAAAAAAAD60/oJ_m5KzSZuoaDVeiu08CEC8U9OFxUpm9wCEwYBhgL/s640/Screenshot%2B2019-11-27%2Bat%2B3.03.53%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-e2kncuIFBu0/Xd5DxIMWyVI/AAAAAAAAD64/jIIOWIKuKBwbY28t9Lyt-UNg3Nk4jETTQCEwYBhgL/s1600/Screenshot%2B2019-11-27%2Bat%2B3.04.15%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="369" data-original-width="1600" height="146" src="https://1.bp.blogspot.com/-e2kncuIFBu0/Xd5DxIMWyVI/AAAAAAAAD64/jIIOWIKuKBwbY28t9Lyt-UNg3Nk4jETTQCEwYBhgL/s640/Screenshot%2B2019-11-27%2Bat%2B3.04.15%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-YSMoi2iBwV8/Xd5Dw5PhdCI/AAAAAAAAD6w/o5F90SKW3Mogc0dvT1BnrUGvRLLDHoblgCEwYBhgL/s1600/Screenshot%2B2019-11-27%2Bat%2B3.05.09%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="507" data-original-width="1600" height="202" src="https://1.bp.blogspot.com/-YSMoi2iBwV8/Xd5Dw5PhdCI/AAAAAAAAD6w/o5F90SKW3Mogc0dvT1BnrUGvRLLDHoblgCEwYBhgL/s640/Screenshot%2B2019-11-27%2Bat%2B3.05.09%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-JzYS5gNiyq0/Xd5Dx10MNSI/AAAAAAAAD68/yVGigQTQ0ssWbYf61NjQ0VcxH6i7-pztQCEwYBhgL/s1600/Screenshot%2B2019-11-27%2Bat%2B3.05.41%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="804" data-original-width="1600" height="320" src="https://1.bp.blogspot.com/-JzYS5gNiyq0/Xd5Dx10MNSI/AAAAAAAAD68/yVGigQTQ0ssWbYf61NjQ0VcxH6i7-pztQCEwYBhgL/s640/Screenshot%2B2019-11-27%2Bat%2B3.05.41%2BPM.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-AYBs2RNH27I/Xd5DyYigI8I/AAAAAAAAD7A/YtlSoEFEBf0oyl5c6Atnmv3pil7RcH2-gCEwYBhgL/s1600/Screenshot%2B2019-11-27%2Bat%2B3.06.17%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="254" data-original-width="1600" height="100" src="https://1.bp.blogspot.com/-AYBs2RNH27I/Xd5DyYigI8I/AAAAAAAAD7A/YtlSoEFEBf0oyl5c6Atnmv3pil7RcH2-gCEwYBhgL/s640/Screenshot%2B2019-11-27%2Bat%2B3.06.17%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">So, this was the simple how-to for managing the K8S manifest. In the next post, I will try to explore the integration on Jenkins with Spinnaker and auto triggering Spinnaker Deployment based on Jenkins events.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com4tag:blogger.com,1999:blog-763097243383122769.post-44238214578518584272019-11-26T18:06:00.002+05:302019-12-02T12:32:59.698+05:30Getting Started with Spinnaker locally using minikube(local Kubernetes)<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-JGzjpQg72Jg/Xd0LK7YVGQI/AAAAAAAAD0I/HrQ4IqCE-1U3fGWftZG5k3nk84wXRYvPACLcBGAsYHQ/s1600/download.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="225" data-original-width="225" height="400" src="https://1.bp.blogspot.com/-JGzjpQg72Jg/Xd0LK7YVGQI/AAAAAAAAD0I/HrQ4IqCE-1U3fGWftZG5k3nk84wXRYvPACLcBGAsYHQ/s400/download.jpeg" width="400" /></a></div>
<span style="font-size: large;">Before jumping to Installation and setup part, first of all, lets briefly summarize about the "What is Spinnaker"</span><br />
<br />
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<br />
<h2 style="text-align: left;">
Spinnaker : </h2>
<h2 style="text-align: left;">
<span style="background-color: white; color: #139bb4; font-family: "assistant" , sans-serif; font-size: large; font-weight: 100;"> <a href="https://www.spinnaker.io/" target="_blank">Spinnaker</a> is an open-source, multi-cloud continuous delivery platform for releasing software changes with high velocity and confidence.</span></h2>
<div>
<span style="font-size: large;"> I am not going in many details about the functionality here but would like to highlight the main architectural component which I think we should know at least before starting playing with this. This will help you in troubleshooting if got stuck in between.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">So, Spinnaker is composed on multiple components. You will be able to see all these after we complete the setup. List of different components is as below(currently just copy-pasting from the official site)-</span></div>
<div>
<ol style="text-align: left;">
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/deck" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Deck</a> is the browser-based UI.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/gate" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Gate</a> is the API gateway.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">The Spinnaker UI and all api callers communicate with Spinnaker via Gate.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/orca" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Orca</a> is the orchestration engine. It handles all ad-hoc operations and pipelines. Read more on the <a href="https://www.spinnaker.io/guides/developer/service-overviews/orca" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Orca Service Overview</a>.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/clouddriver" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Clouddriver</a> is responsible for all mutating calls to the cloud providers and for indexing/caching all deployed resources.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/front50" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Front50</a> is used to persist the metadata of applications, pipelines, projects and notifications.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/rosco" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Rosco</a> is the bakery. It produces immutable VM images (or image templates) for various cloud providers.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">It is used to produce machine images (for example <a href="https://cloud.google.com/compute/docs/images" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">GCE images</a>, <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">AWS AMIs</a>, <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/about-images" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Azure VM images</a>). It currently wraps <a href="https://www.packer.io/" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">packer</a>, but will be expanded to support additional mechanisms for producing images.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/igor" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Igor</a> is used to trigger pipelines via continuous integration jobs in systems like Jenkins and Travis CI, and it allows Jenkins/Travis stages to be used in pipelines.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/echo" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Echo</a> is Spinnaker’s eventing bus.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">It supports sending notifications (e.g. Slack, email, SMS), and acts on incoming webhooks from services like Github.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/fiat" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Fiat</a> is Spinnaker’s authorization service. </span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">It is used to query a user’s access permissions for accounts, applications and service accounts.</span></div>
</li>
<li style="box-sizing: border-box; margin-bottom: 0.5em;"><div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><a href="https://github.com/spinnaker/kayenta" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Kayenta</a> provides automated canary analysis for Spinnaker.</span></div>
</li>
</ol>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; text-align: left; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"> </span>11.<span style="font-size: large;"> <a href="https://github.com/spinnaker/halyard" style="box-sizing: border-box; color: #52adc8; text-decoration: none; transition: all 0.2s ease-in-out 0s;">Halyard</a> is Spinnaker’s configuration service.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; text-align: left; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">Halyard manages the lifecycle of each of the above services. It only interacts with these services during Spinnaker startup, updates, and rollbacks.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><br /></span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">Note - In our setup "Fiat and Kayenta" will not be present as this is not available in the helm chart that we have installed on minikube.</span></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;">Along with Architecture, I guess we should know the ports mapping as well.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kr0ldkhMMb0/Xd0Ose9VbgI/AAAAAAAAD0o/-EpWiEUdcXw-C3OAtvJDMX0nigJZfzcqQCEwYBhgL/s1600/Screenshot%2B2019-11-26%2Bat%2B5.08.10%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1024" data-original-width="1600" height="408" src="https://1.bp.blogspot.com/-kr0ldkhMMb0/Xd0Ose9VbgI/AAAAAAAAD0o/-EpWiEUdcXw-C3OAtvJDMX0nigJZfzcqQCEwYBhgL/s640/Screenshot%2B2019-11-26%2Bat%2B5.08.10%2BPM.png" width="640" /></a></div>
<div style="box-sizing: border-box; margin-bottom: 1.3em; orphans: 3; transition: all 0.2s ease-in-out 0s; widows: 3;">
<span style="font-size: large;"><br /></span></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<h3>
<span style="font-size: large;">Minikube - </span></h3>
<div>
<span style="font-size: large;"> Minikube provides a way to setup Kubernetes locally for development purpose. I am not going in details about the installation. Please go through my previous blog post if you want to install <a href="https://linuxhelp4u.blogspot.com/2018/04/minikube-how-to-set-up-local-kubernetes.html" target="_blank">minikube</a>.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">After installation, let's start minikube cluster. I am starting with my custom configuration so that it should be able to handle the load.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-GBiXezfKxf8/Xd0Qwvjf0_I/AAAAAAAAD0w/SHs-H7QBAXwDuJCE-R7UQlEwI9-kPRfBQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.17.01%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="684" data-original-width="1600" height="272" src="https://1.bp.blogspot.com/-GBiXezfKxf8/Xd0Qwvjf0_I/AAAAAAAAD0w/SHs-H7QBAXwDuJCE-R7UQlEwI9-kPRfBQCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.17.01%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<h3>
<span style="font-size: large;">Other Tools -</span></h3>
<span style="font-size: large;"> Apart from minikube, below are the other tools that we need and I am supposing that these are already installed.</span><br />
<div style="text-align: left;">
<ol style="text-align: left;">
<li><span style="font-size: large;">helm</span></li>
<li><span style="font-size: large;">kubectl</span></li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kflr7ushYdk/Xd0TEkrXDpI/AAAAAAAAD1c/4RMmLhq_YOY8Q8uyKKru5-3Y8cMg1An0gCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.26.51%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="290" data-original-width="1600" height="115" src="https://1.bp.blogspot.com/-kflr7ushYdk/Xd0TEkrXDpI/AAAAAAAAD1c/4RMmLhq_YOY8Q8uyKKru5-3Y8cMg1An0gCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.26.51%2BPM.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
<br />
<div>
<span style="font-size: large;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-size: large;">Install Spinnaker -</span></h2>
<div>
<span style="font-size: large;"> Now, we have minikube with helm installed and running. We are ready to install spinnaker. We will install spinnaker using helm chart.</span></div>
<div>
<span style="font-size: large;">Helm is a templating engine for k8s deployments. We need to provide values those templates. So, to start with they are providing the default set of values which we are going to use.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Spinnaker helm chart - </span><a href="https://github.com/helm/charts/tree/master/stable/spinnaker">https://github.com/helm/charts/tree/master/stable/spinnaker</a></div>
<div>
<br /></div>
<div>
<span style="font-size: large;">Download the default values file form above helm repo.</span><br />
<blockquote class="tr_bq">
<span style="font-size: large;">$ curl -Lo values.yaml https://raw.githubusercontent.com/kubernetes/charts/master/stable/spinnaker/values.yaml</span></blockquote>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-AJJDJ8qTKxQ/Xd0UkXlOdfI/AAAAAAAAD1o/zW95I6XWqDYcKi6ezCrOYpxRDlPc-fMuQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.33.17%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="267" data-original-width="1600" height="106" src="https://1.bp.blogspot.com/-AJJDJ8qTKxQ/Xd0UkXlOdfI/AAAAAAAAD1o/zW95I6XWqDYcKi6ezCrOYpxRDlPc-fMuQCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.33.17%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Now, let's install the spinnaker to K8S cluter.</span></div>
<blockquote class="tr_bq">
<span style="font-size: large;">$ helm install -n spinnaker-local stable/spinnaker -f values.yaml --timeout 300 --namespace spinnaker</span></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-MGkn3Nus42U/Xd0X9iCCUZI/AAAAAAAAD2U/1yTjm-HqCmErs76Af3dNHDmbG9fNhN2tgCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.47.41%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="884" data-original-width="1600" height="352" src="https://1.bp.blogspot.com/-MGkn3Nus42U/Xd0X9iCCUZI/AAAAAAAAD2U/1yTjm-HqCmErs76Af3dNHDmbG9fNhN2tgCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.47.41%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-RTw3fp73JwY/Xd0YLiRM39I/AAAAAAAAD2Y/tt5nS7eo9WgynDbMly-xry8THymMz-1YQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.48.40%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="842" data-original-width="1600" height="336" src="https://1.bp.blogspot.com/-RTw3fp73JwY/Xd0YLiRM39I/AAAAAAAAD2Y/tt5nS7eo9WgynDbMly-xry8THymMz-1YQCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.48.40%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-IiW2Oxak8c8/Xd0YURgShwI/AAAAAAAAD2g/MSBTSIh3_CwXe1wU2HBWFVz-BfwMoeOlwCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.49.09%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="568" data-original-width="1600" height="226" src="https://1.bp.blogspot.com/-IiW2Oxak8c8/Xd0YURgShwI/AAAAAAAAD2g/MSBTSIh3_CwXe1wU2HBWFVz-BfwMoeOlwCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.49.09%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><b>Tip - </b>In case you get timed out exception in first run(like below). Then please delete the helm installation using "<b><i>helm del --purge {release-name}</i></b>" and re-run the same command again.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-KOL9Yz6dTLs/Xd30rHRjShI/AAAAAAAAD4Q/H1tws2eBPzsO5DIBKqq-5t6z33Ucd5xGACLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B4.36.51%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="104" data-original-width="1600" height="40" src="https://1.bp.blogspot.com/-KOL9Yz6dTLs/Xd30rHRjShI/AAAAAAAAD4Q/H1tws2eBPzsO5DIBKqq-5t6z33Ucd5xGACLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B4.36.51%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">After successful installation, check for the pods in "spinnaker" namespace. All should be in running state. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Pl6XBvGtGlE/Xd3z605o2bI/AAAAAAAAD4I/aZbAblOEIgQdZIAa8BEPk3DyxBt5IJBUgCLcBGAsYHQ/s1600/Screenshot%2B2019-11-27%2Bat%2B9.25.01%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="748" data-original-width="1600" height="298" src="https://1.bp.blogspot.com/-Pl6XBvGtGlE/Xd3z605o2bI/AAAAAAAAD4I/aZbAblOEIgQdZIAa8BEPk3DyxBt5IJBUgCLcBGAsYHQ/s640/Screenshot%2B2019-11-27%2Bat%2B9.25.01%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">P.S. - Please ignore the hal status in above output. Its taking some time to start :).</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">To access the Spinnaker UI, follow the above instructions. If you notice then in above output we are doing the port-forward for two pods. As per the architecture, these two components are responsible for below functionalities.</span></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: large;">First one is "deck" - which is providing the UI dashboard</span></li>
<li><span style="font-size: large;">Second one the "gate" - which is responsible for accesing the apis.</span></li>
</ul>
<blockquote class="tr_bq">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">#export DECK_POD=$(kubectl get pods --namespace spinnaker -l "cluster=spin-deck" -o jsonpath="{.items[0].metadata.name}")<br />#export GATE_POD=$(kubectl get pods --namespace spinnaker -l "cluster=spin-gate" -o jsonpath="{.items[0].metadata.name}")<br />#echo $DECK_POD<br />#echo $GATE_POD<br />#alias ui='kubectl port-forward --namespace spinnaker $DECK_POD 9000'<br />#alias api='kubectl port-forward --namespace spinnaker $GATE_POD 8084'<br />#ui & api &</span></blockquote>
<blockquote class="tr_bq">
</blockquote>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><a href="https://1.bp.blogspot.com/-K94vwi5vCEc/Xd0aXT9gsVI/AAAAAAAAD3A/q_9Q2TBbjFweXednLE44s6WKpE_S4yQXQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B5.58.01%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="315" data-original-width="1600" height="124" src="https://1.bp.blogspot.com/-K94vwi5vCEc/Xd0aXT9gsVI/AAAAAAAAD3A/q_9Q2TBbjFweXednLE44s6WKpE_S4yQXQCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B5.58.01%2BPM.png" width="640" /></a></span></div>
<span style="font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><a href="https://1.bp.blogspot.com/-W6IN9XVT-ZQ/Xd0a_Hji0oI/AAAAAAAAD3I/YnVB-R_Mm-oDgaEuFVagJLQcSm26YbY3ACLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B6.00.38%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="214" data-original-width="1600" height="84" src="https://1.bp.blogspot.com/-W6IN9XVT-ZQ/Xd0a_Hji0oI/AAAAAAAAD3I/YnVB-R_Mm-oDgaEuFVagJLQcSm26YbY3ACLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B6.00.38%2BPM.png" width="640" /></a></span></div>
<span style="font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><br /></span></div>
<span style="font-size: large;">
</span>
<h3 style="text-align: left;">
<span style="font-size: large;">
Access the Spinnaker Dashboard</span></h3>
<span style="font-size: large;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-T_CzCWvdpzU/Xd0b_o09YHI/AAAAAAAAD3U/8RhLqhwtQFkKrQPhB-AgMGi8gIPMZRMMwCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B6.04.35%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="504" data-original-width="1600" height="200" src="https://1.bp.blogspot.com/-T_CzCWvdpzU/Xd0b_o09YHI/AAAAAAAAD3U/8RhLqhwtQFkKrQPhB-AgMGi8gIPMZRMMwCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B6.04.35%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-4G0M4NRT_zQ/Xd0cF-tBONI/AAAAAAAAD3Y/KHApx9CrTIks8Kdan-ePPed89TWrUyOVQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-26%2Bat%2B6.04.45%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="504" data-original-width="1600" height="200" src="https://1.bp.blogspot.com/-4G0M4NRT_zQ/Xd0cF-tBONI/AAAAAAAAD3Y/KHApx9CrTIks8Kdan-ePPed89TWrUyOVQCLcBGAsYHQ/s640/Screenshot%2B2019-11-26%2Bat%2B6.04.45%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
In next post we'll try to create pipelines which will deploy entities on kubernetes. Also in later posts we'll explore more on the integration with different providers e.g. Jenkins/Cloud vendors.</div>
</span></div>
<div>
<br /></div>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
</div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com3tag:blogger.com,1999:blog-763097243383122769.post-17649320890692666222019-11-08T15:51:00.002+05:302019-11-08T15:57:22.619+05:30Taints and Tolerations in Kubernetes<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-left: 1em; margin-right: 1em;">
</div>
<div style="margin-left: 1em; margin-right: 1em;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DNButWUWvNs/XcUxaWYlW_I/AAAAAAAADyw/0icmVE7OetQLTktdkN5uEdEHymYKzeRBgCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.39.48%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="386" data-original-width="1506" height="164" src="https://1.bp.blogspot.com/-DNButWUWvNs/XcUxaWYlW_I/AAAAAAAADyw/0icmVE7OetQLTktdkN5uEdEHymYKzeRBgCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.39.48%2BPM.png" width="640" /></a></div>
</div>
<br />
<span style="font-size: large;"> We all know that Kubernetes is powerful orchestration tool in the world of containers. The whole complexity of managing, distributing multiple containers across the cluster is being taken care Kubernetes OOB. In shorts it takes care of all the heavy and complex lifting for us.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Since, its K8S who takes care of all distribution and scheduling of pods across different nodes in the cluster. So, what we if we want to run specific pod on specific node only. Luckily we have option to manage this as well. In K8S its called "<i><b>taint and toleration</b></i>".</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">In general terms:</span><br />
<div style="text-align: left;">
<span style="font-size: large;"> - Taint is the capability of the node which makes node to do not let any pod to be scheduled on it.</span></div>
<span style="font-size: large;"> - On the other hand, Toleration is another capability makes that particular pod to be tolerated by specific Node.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">To summarise, Taint and Toleration are used to set restrictions on the what pods can be scheduled on a node.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Let us suppose we have 3 node cluster as below and below is the state when we have pods running in normal scenarios.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-0ONDvQjDAr4/XcUxb1LsF7I/AAAAAAAADy0/BHHMRIwurRc04s6qLABysSvxiM5F4krIwCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.40.12%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="384" data-original-width="802" height="306" src="https://1.bp.blogspot.com/-0ONDvQjDAr4/XcUxb1LsF7I/AAAAAAAADy0/BHHMRIwurRc04s6qLABysSvxiM5F4krIwCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.40.12%2BPM.png" width="640" /></a></div>
<span style="font-size: large;"><br /></span>
<br />
<div class="" style="clear: both; text-align: left;">
<span style="font-size: large;">Now suppose, we got a requirements where we want to schedule only specific pods on Node1 and nothing should be scheduled on that. For this now lets add a taint called "<span style="color: blue;">taint=blue</span>" on Node1. After this no pod will be able to schedule on this Node, until we add tolerations to specific pod to get scheduled on Node1.</span></div>
<div class="" style="clear: both; text-align: left;">
<span style="font-size: large;">Below, we added "<span style="color: blue;">blue</span>" toleration to pod "<span style="color: blue;">D</span>" and then after below will be the status.</span><br />
<span style="font-size: large;"><br /></span></div>
<div class="" style="clear: both; text-align: left;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-0TCDa75ki-s/XcUxcw9fGyI/AAAAAAAADy4/rT_alfdjc-QQVY8fINvXam6MMrr-70VCQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.40.21%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="384" data-original-width="802" height="306" src="https://1.bp.blogspot.com/-0TCDa75ki-s/XcUxcw9fGyI/AAAAAAAADy4/rT_alfdjc-QQVY8fINvXam6MMrr-70VCQCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.40.21%2BPM.png" width="640" /></a></div>
<div style="text-align: left;">
</div>
</div>
<br />
<span style="font-size: large;"><b><i>Demo -</i></b></span><br />
<span style="font-size: large;"> In below, fresh setup we'll see we don't have any taint set on worker node, though we have a taint set on Master node. That is the reason that by default nothing will be scheduled on master node.</span><br />
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-3hDf8Vl-woI/XcUxdfxlxZI/AAAAAAAADy8/-x4z7f914i0khejnKyChsvRmVqQ0YEG9gCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.40.39%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="268" data-original-width="1286" height="131" src="https://1.bp.blogspot.com/-3hDf8Vl-woI/XcUxdfxlxZI/AAAAAAAADy8/-x4z7f914i0khejnKyChsvRmVqQ0YEG9gCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.40.39%2BPM.png" width="640" /></a></div>
<div style="text-align: left;">
</div>
<span style="font-size: large;"><br /></span>
<br />
<div style="text-align: center;">
<br /></div>
<br />
<span style="font-size: large;">Now, lets add a taint "Taint=Dog" to worker node and try to schedule a pod on this.</span><br />
<br />
<div style="text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-nD39ccgo0Z0/XcUxiLphs7I/AAAAAAAADzA/pBgHJIKA9gUKwuZPlizPAxJGjL9dxPo6ACLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.40.51%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="164" data-original-width="1286" height="80" src="https://1.bp.blogspot.com/-nD39ccgo0Z0/XcUxiLphs7I/AAAAAAAADzA/pBgHJIKA9gUKwuZPlizPAxJGjL9dxPo6ACLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.40.51%2BPM.png" width="640" /></a></div>
<br />
<br />
<span style="font-size: large;">Create a pod and see the status of the pod-</span><br />
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fshaQxx1tAI/XcUxjDWwMEI/AAAAAAAADzE/ouEdzPw_uyoHEs-uqMQSiKfIXQoERmpbACLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.41.05%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="340" data-original-width="1284" height="168" src="https://1.bp.blogspot.com/-fshaQxx1tAI/XcUxjDWwMEI/AAAAAAAADzE/ouEdzPw_uyoHEs-uqMQSiKfIXQoERmpbACLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.41.05%2BPM.png" width="640" /></a></div>
<br />
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;">You noticed that status is pending, let's see what logs say. If you see the last line it says</span> "<b><i><span style="font-size: large;">0/2 nodes are available: 2 node(s) had taints that the pod didn't tolerate</span></i></b>".</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-7K8fEP1LjNQ/XcUxlZesKWI/AAAAAAAADzI/trQQSyIEwrg1JjwwkaR6MIApZFvF9ELYwCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.41.18%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="178" data-original-width="1288" height="88" src="https://1.bp.blogspot.com/-7K8fEP1LjNQ/XcUxlZesKWI/AAAAAAAADzI/trQQSyIEwrg1JjwwkaR6MIApZFvF9ELYwCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.41.18%2BPM.png" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;">Now lets create a new pod "dog" which should be tolerate to Node1.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-3V-mxV6YIrY/XcUxlzBzV3I/AAAAAAAADzM/C9siGqli0-8XEIwZcu4gheVhG900NnXiQCLcBGAsYHQ/s1600/Screenshot%2B2019-11-08%2Bat%2B2.41.45%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1328" data-original-width="1288" height="640" src="https://1.bp.blogspot.com/-3V-mxV6YIrY/XcUxlzBzV3I/AAAAAAAADzM/C9siGqli0-8XEIwZcu4gheVhG900NnXiQCLcBGAsYHQ/s640/Screenshot%2B2019-11-08%2Bat%2B2.41.45%2BPM.png" width="620" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">You'll see that after adding tolerance to the pod it got scheduled to Node01 and the other pod is still in pending state.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">I hope this clears out the concept of taint and toleration in K8S.</span></div>
<div style="text-align: left;">
<br /></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com4tag:blogger.com,1999:blog-763097243383122769.post-53361722184159401642019-08-21T18:52:00.002+05:302019-10-09T11:44:58.627+05:30Terraform setting up clustered web server !! Getting Started Part-3!!<div dir="ltr" style="text-align: left;" trbidi="on">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- test -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-0018691690291724"
data-ad-slot="7696655871"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<span style="font-size: large;">Last two posts first we saw the basics of terraform "<a href="https://linuxhelp4u.blogspot.com/2019/08/getting-started-with-terraform.html" target="_blank">Part-1</a>" and then created simple web server "<a href="https://linuxhelp4u.blogspot.com/2019/08/terraform-setting-up-simple-web-server.html" target="_blank">Part-2</a>". </span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Now as we know that running single web server in production is never a good idea. We always need services which should be highly available as well as should be scalable as per the requirements.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Creating and managing a cluster always going to be a pain point. Fortunately with new cloud technologies now its possible to automate all this and things will be much easier to manage. In this tutorial we'll use AWS's "Auto Scaling Group (ASG)".</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"> An ASG takes care of everything automatically, including launching a cluster of EC2 instances , monitoring the health of each instance, replacing the failed instances and adjusting the size of cluster in response to the load.</span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-V9PfHdkRkBA/XYRfH-WCERI/AAAAAAAADuE/QIsUJMKxYQIhGKcvc1c4CtU3buu_bUBgACLcBGAsYHQ/s1600/Screenshot%2B2019-09-20%2Bat%2B10.39.27%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1440" data-original-width="1600" height="576" src="https://1.bp.blogspot.com/-V9PfHdkRkBA/XYRfH-WCERI/AAAAAAAADuE/QIsUJMKxYQIhGKcvc1c4CtU3buu_bUBgACLcBGAsYHQ/s640/Screenshot%2B2019-09-20%2Bat%2B10.39.27%2BAM.png" width="640" /></a></div>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><br /></span>
<br />
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;">A full working ASG stack include multiple resources to make a working cluster. It starts with "<b><i>launch configuration</i></b>" which basically specify how a particular EC2 instance will be configured.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Now, in Fig-1, you saw that we have two EC2 instances and each instance will be having its own IP address. Problem is that what will be end point that you will be provide to your users. Also, later on what we had some issue issues with any of the server ASG can destroy the faulty server and launch a server with new IP. It will be difficult to handle such a situation. </span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"> One way to solve this issue is to use Load Balancer to distribute traffic to backend servers and give LB IP intact DNS to all the users to access the services. </span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-4lT9lxRBReo/XYRenj31rrI/AAAAAAAADt8/flyZWw_iWrEtGxvbIAONh5rNh2wX9twNwCLcBGAsYHQ/s1600/Screenshot%2B2019-09-20%2Bat%2B10.36.55%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1148" data-original-width="1320" height="556" src="https://1.bp.blogspot.com/-4lT9lxRBReo/XYRenj31rrI/AAAAAAAADt8/flyZWw_iWrEtGxvbIAONh5rNh2wX9twNwCLcBGAsYHQ/s640/Screenshot%2B2019-09-20%2Bat%2B10.36.55%2BAM.png" width="640" /></a></div>
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">AWS offers three type of Load Balancers-</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 1.) Application Load balancer(ALB) :</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> Best suited for load balancing of HTTP and HTTPS traffic. Operates at the application layer (Layer 7) of the OSI model.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> </span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 2.) Network Load Balancer(NLB) :</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> Best suited for load balancing of TCP, UDP and TLS traffic. Operates at the transport layer (Layer 4) of the OSI model.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 3.) Classic Load Balancer(CLB) :</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> This is legacy load balancer that predates both ALB and NLB. It can handle all types of traffic that ALB and NLB can handle.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Now a days most of the application either use ALB or NLB. In our case we are going to handle HTTP traffic, so we will use ALB.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Again, ALB consists of several parts:</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">1.) Listener - listen on specific port and protocol.</span></div>
<div style="text-align: left;">
<span style="font-size: large;">2.) Listener Rule - takes request that comes to listener and send those that match specific paths e.g. /foo or /bar to specific target group.</span></div>
<div style="text-align: left;">
<span style="font-size: large;">3.) Target Groups - One of more servers that receive requests from the load balancer. Target group also perform health checks on those servers and only sends requests to the healthy servers.</span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-NZTg2YLiFpg/XYRfXuzLyhI/AAAAAAAADuI/GooFEZAP5VEd-TQUipsBitQsjSwgMz-KACLcBGAsYHQ/s1600/Screenshot%2B2019-09-20%2Bat%2B10.40.39%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="648" data-original-width="1308" height="316" src="https://1.bp.blogspot.com/-NZTg2YLiFpg/XYRfXuzLyhI/AAAAAAAADuI/GooFEZAP5VEd-TQUipsBitQsjSwgMz-KACLcBGAsYHQ/s640/Screenshot%2B2019-09-20%2Bat%2B10.40.39%2BAM.png" width="640" /></a></div>
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<div style="text-align: left;">
<span style="font-size: large;">You can get the code from my GitHub repo <a href="https://github.com/deepforu47/DevOps/tree/master/terraform/getting-started/cluster-webserver" target="_blank">here</a>.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Please see all the steps in below screen shots -</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-swkjDeKiScs/XV1Dxxrp8-I/AAAAAAAADpo/F55x4w53jmE6MsgVbxi9LCJEAlepkBytwCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.39.00%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1275" data-original-width="1600" height="508" src="https://1.bp.blogspot.com/-swkjDeKiScs/XV1Dxxrp8-I/AAAAAAAADpo/F55x4w53jmE6MsgVbxi9LCJEAlepkBytwCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.39.00%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-s5AHxZhA3pc/XV1D6mo5ISI/AAAAAAAADps/39Nvai6j6cQqyrd_uAYDbFzvgcUVrlk4QCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.39.17%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1275" data-original-width="1600" height="510" src="https://1.bp.blogspot.com/-s5AHxZhA3pc/XV1D6mo5ISI/AAAAAAAADps/39Nvai6j6cQqyrd_uAYDbFzvgcUVrlk4QCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.39.17%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-LxD_oPYv8mk/XV1ECdjoRYI/AAAAAAAADp0/VveXDCpJOhgPXEg7TKtL5o0TnvnPFJc9ACLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.39.29%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1275" data-original-width="1600" height="510" src="https://1.bp.blogspot.com/-LxD_oPYv8mk/XV1ECdjoRYI/AAAAAAAADp0/VveXDCpJOhgPXEg7TKtL5o0TnvnPFJc9ACLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.39.29%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-g8rHubgCwSs/XV1EJrdj-zI/AAAAAAAADp4/aCF15mWDNh4ZkOWo24CYDspAEwDqSXkTwCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.39.47%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1275" data-original-width="1600" height="510" src="https://1.bp.blogspot.com/-g8rHubgCwSs/XV1EJrdj-zI/AAAAAAAADp4/aCF15mWDNh4ZkOWo24CYDspAEwDqSXkTwCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.39.47%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-F8e-ktR0y_s/XV1ERD7M0jI/AAAAAAAADqA/f8pM2oIH6_EtCWl1gaSkOMfpq9Om7PReQCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.40.25%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="454" data-original-width="1600" height="180" src="https://1.bp.blogspot.com/-F8e-ktR0y_s/XV1ERD7M0jI/AAAAAAAADqA/f8pM2oIH6_EtCWl1gaSkOMfpq9Om7PReQCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.40.25%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Check the status on your aws console and access site from browser as well :</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-OVnZ-FBNw4Y/XV1EfkTlsMI/AAAAAAAADqM/e8M155NENesi91G9PwhPj6KOyVRdzGWYgCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.41.30%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="907" data-original-width="1600" height="362" src="https://1.bp.blogspot.com/-OVnZ-FBNw4Y/XV1EfkTlsMI/AAAAAAAADqM/e8M155NENesi91G9PwhPj6KOyVRdzGWYgCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.41.30%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_PutRzUQZ9Q/XV1EzS33s0I/AAAAAAAADqY/KS3e-sbQ8Cg2IWFjaphdPTnyFFoCo_WmACLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.48.30%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="907" data-original-width="1600" height="362" src="https://1.bp.blogspot.com/-_PutRzUQZ9Q/XV1EzS33s0I/AAAAAAAADqY/KS3e-sbQ8Cg2IWFjaphdPTnyFFoCo_WmACLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.48.30%2BPM.png" width="640" /></a></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Now, lets destroy whole the whole setup with one command :).</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-M306fT8NFGU/XV1FZF10wHI/AAAAAAAADqg/WD4u_A9o_IgLVJQ6feLeIQMnKoayVfsKwCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.49.58%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="963" data-original-width="1600" height="384" src="https://1.bp.blogspot.com/-M306fT8NFGU/XV1FZF10wHI/AAAAAAAADqg/WD4u_A9o_IgLVJQ6feLeIQMnKoayVfsKwCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.49.58%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-yJ1Lq7egl1Q/XV1Fg8RUVtI/AAAAAAAADqk/pe5b5uJ27387aTFWlkUAsTHKXehgJnsygCLcBGAs/s1600/Screenshot%2B2019-08-21%2Bat%2B6.50.24%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="963" data-original-width="1600" height="384" src="https://1.bp.blogspot.com/-yJ1Lq7egl1Q/XV1Fg8RUVtI/AAAAAAAADqk/pe5b5uJ27387aTFWlkUAsTHKXehgJnsygCLcBGAs/s640/Screenshot%2B2019-08-21%2Bat%2B6.50.24%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com6tag:blogger.com,1999:blog-763097243383122769.post-76400356235843750892019-08-11T10:40:00.001+05:302019-09-20T10:42:53.608+05:30Terraform setting up simple web server !! Getting Started Part-2!!<div dir="ltr" style="text-align: left;" trbidi="on">
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script><br />
<span style="font-size: large;">In our last post "<a href="https://linuxhelp4u.blogspot.com/2019/08/getting-started-with-terraform.html">Getting started with terraform</a>", we just learn how to launch a simple EC2 instance in AWS. In this article we will dig more and will try to create a simple web server and try to access that.</span><br />
<br />
<h3 style="text-align: left;">
Architecture -</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-SgQ4inZyh0k/XYRfu-eJUmI/AAAAAAAADuU/ZqC2Fzr4Hk0mCPwQnKbfzh3SL2ckXDa5gCLcBGAsYHQ/s1600/Screenshot%2B2019-09-20%2Bat%2B10.42.15%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1051" data-original-width="1600" height="420" src="https://1.bp.blogspot.com/-SgQ4inZyh0k/XYRfu-eJUmI/AAAAAAAADuU/ZqC2Fzr4Hk0mCPwQnKbfzh3SL2ckXDa5gCLcBGAsYHQ/s640/Screenshot%2B2019-09-20%2Bat%2B10.42.15%2BAM.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<br />
<br />
We are not installing proper web-server, its just a hack. Using busybody to launch http process.<br />
<br />
<pre data-code-language="bash" data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border: 0px; box-sizing: border-box; color: #404040; font-family: "Ubuntu Mono", monospace; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 25px; margin-left: 20px; margin-top: 25px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: keep-all !important;"><code class="c" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #0099ff; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: italic; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">#!/bin/bash</code>
<code class="nb" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #336666; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">echo</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"Hello, World"</code> > index.html
nohup busybox httpd -f -p <code class="m" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #ff6600; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">8080</code> <code class="p" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: black; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline;">&</code></pre>
<pre data-code-language="terraform" data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border: 0px; box-sizing: border-box; color: #404040; font-family: "Ubuntu Mono", monospace; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 25px; margin-left: 20px; margin-top: 25px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: keep-all !important;"><code class="kr" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #006699; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; font-weight: bold; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">resource</code> <code class="s" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"aws_instance" "example"</code> <code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">{</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> ami</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"ami-0cfee17793b08a293"</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> instance_type</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"t2.micro"</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> user_data</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"><< - EOF // Together<-eof code="">
<code class="c1" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #35586c; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: italic; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> #!/bin/bash</code>
<code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">echo</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"Hello, World"</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">></code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">index</code><code class="p" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: black; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline;">.</code><code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">html</code>
<code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">nohup</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">busybox</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">httpd</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">-f</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">-p</code> <code class="m" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #ff6600; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">8080</code> <code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">&</code>
<code class="err" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">EOF</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> tags</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">{</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> Name</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"terraform-example"</code>
<code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">}</code>
<code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">}</code></-eof></code></pre>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<div style="text-align: left;">
<div style="text-align: left;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: white; color: #333333; font-family: serif;">The << - EOF (together)</span></span><span style="background-color: white; color: #333333; font-family: "ubuntu mono" , monospace;"><-eof span=""><span style="background-color: white; color: #333333; font-family: serif;"><span style="font-family: "ubuntu mono" , monospace; font-variant-ligatures: normal; orphans: 2; widows: 2;"><-eof span=""> and </-eof></span></span><code style="background-color: white; border: 0px; box-sizing: border-box; color: #333333; font-family: "ubuntu mono", monospace; font-stretch: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">EOF </code><span style="background-color: white; color: #333333; font-family: serif;">are Terraform’s </span><span style="background-color: white; border: 0px; box-sizing: border-box; color: #333333; font-family: serif; font-stretch: inherit; font-style: italic; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">heredoc</span><span style="background-color: white; color: #333333; font-family: serif;"> syntax, which allows us to create multiline strings without having to insert newline characters all over the place.</span></-eof></span></span></div>
</div>
</div>
</div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="background-color: white; color: #333333; font-family: serif;"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="background-color: white; font-variant-ligatures: normal; orphans: 2; widows: 2;"><span style="color: #333333; font-family: serif;">We need to do some more changes before making this to work. By <span style="caret-color: rgb(51, 51, 51);">default</span> aws deny all incoming and outgoing traffic from any EC2 instance. So, to allow http traffic on the web server we need to add a rule which will allow traffic on port 8080.</span></span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="background-color: white; font-variant-ligatures: normal; orphans: 2; widows: 2;"><span style="color: #333333; font-family: serif;"><br /></span></span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="background-color: white; font-variant-ligatures: normal; orphans: 2; widows: 2;"><span style="color: #333333; font-family: serif;">For this we will create a security group as below :</span></span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="background-color: white; font-variant-ligatures: normal; orphans: 2; widows: 2;"><span style="color: #333333; font-family: serif;"><br /></span></span></span></div>
<pre data-code-language="terraform" data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border: 0px; box-sizing: border-box; color: #404040; font-family: "Ubuntu Mono", monospace; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 25px; margin-left: 20px; margin-top: 25px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: keep-all !important;"><code class="kr" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #006699; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; font-weight: bold; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">resource</code> <code class="s" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"aws_security_group" "example-ec2-sg"</code> <code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">{ </code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> name</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"terraform-example-instance" // Name of the security Group</code>
<code class="kd" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #006699; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; font-weight: bold; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">ingress</code> <code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">{</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> from_port</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="m" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #ff6600; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">8080</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> to_port</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="m" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #ff6600; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">8080</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> protocol</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"tcp"</code>
<code class="na" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #330099; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;"> cidr_blocks</code> <code class="o" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #555555; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">=</code> <code class="p" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: black; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline;">[</code><code class="s2" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: #cc3300; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">"0.0.0.0/0"</code><code class="p" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; color: black; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline;">]. // Allow from everything</code>
<code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">}</code>
<code class="-Punctuation" style="-webkit-font-smoothing: antialiased; border: 0px; box-sizing: border-box; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline;">}</code></pre>
<div style="text-align: left;">
<span style="background-color: white; color: #333333; font-family: serif; font-size: large; white-space: normal;">Creating this new security </span><span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);">group will not be enough, until we configure our EC2 instance to use this security group. To do that we should be aware of terraform <b><i>expressions.</i></b></span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><b><i><br /></i></b></span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;">An <b><i>expression</i></b> in terraform is something which return values. Terraform support number of <b><i>expressions</i></b>, but here we will use the type of <i style="font-weight: bold;">reference </i> which allow us to access the values from other code. Here we need the <i style="font-weight: bold;">ID </i>of the security group in EC2 configuration. For this format will be something like below-</span></div>
<div style="text-align: left;">
<i style="color: #333333; font-family: serif; font-weight: bold;"><br /></i></div>
<div style="text-align: left;">
<code class="err" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2;"><provider>_<type></type></provider></code><code class="p" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; orphans: 2; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline; white-space: pre-wrap; widows: 2;">.</code><code class="err" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2;"><name></name></code><code class="p" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: 1.5em !important; margin: 0.75em 0px 1.25em !important; orphans: 2; overflow-wrap: break-word; padding: 0px; text-align: inherit; vertical-align: baseline; white-space: pre-wrap; widows: 2;">.</code><code class="err" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2;"><attribute></attribute></code></div>
<div style="text-align: left;">
<code class="err" style="-webkit-font-smoothing: antialiased; background-color: #fbfbfb; border: 0px; box-sizing: border-box; color: #aa0000; font-family: "Ubuntu Mono", monospace; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant-alternates: inherit; font-variant-caps: inherit; font-variant-east-asian: inherit; font-variant-ligatures: inherit; font-variant-numeric: inherit; font-variant-position: inherit; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2;">e.g. aws_security_group.example-ec2-sg.id</code></div>
<div style="text-align: left;">
<i style="color: #333333; font-family: serif; font-weight: bold;"><br /></i></div>
<div style="text-align: left;">
<i style="color: #333333; font-family: serif; font-weight: bold;"> </i><span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);">Now use this security group ID in "<i style="font-weight: bold;">vpc_security_group_ids</i>" argument of aws_instance. So the final terraform file will be as below -</span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qPdu24fvg6I/XU-uKN1HhzI/AAAAAAAADn4/lRMfh-bFvrUIhLlGmy8zj6rAoSwrC64vwCLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.26.43%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1157" data-original-width="1600" height="462" src="https://1.bp.blogspot.com/-qPdu24fvg6I/XU-uKN1HhzI/AAAAAAAADn4/lRMfh-bFvrUIhLlGmy8zj6rAoSwrC64vwCLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.26.43%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;">Now, lets go ahead and apply these changes. This will replace existing server and create NSG and associate that with new EC2.</span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);">Output of $<b><i>terraform apply</i></b></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-aFiPRq5Rhqg/XU-vKE4vU4I/AAAAAAAADoM/-1UYbwOIc7wNWI4HLyYDBFClMUScxBB_QCLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.28.37%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1581" data-original-width="1600" height="632" src="https://1.bp.blogspot.com/-aFiPRq5Rhqg/XU-vKE4vU4I/AAAAAAAADoM/-1UYbwOIc7wNWI4HLyYDBFClMUScxBB_QCLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.28.37%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kL5w86HWd0k/XU-vKMo_8-I/AAAAAAAADoQ/RnqVa0m3xlMz8JXAWFNbQDB9bUJgknJLwCLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.28.56%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1581" data-original-width="1600" height="632" src="https://1.bp.blogspot.com/-kL5w86HWd0k/XU-vKMo_8-I/AAAAAAAADoQ/RnqVa0m3xlMz8JXAWFNbQDB9bUJgknJLwCLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.28.56%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-aviMTza6WJY/XU-vJ1b9IwI/AAAAAAAADoI/jI48rM6Pv5c6pVDmWX4GE-afjetXF70VgCLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.30.52%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1093" data-original-width="1600" height="436" src="https://1.bp.blogspot.com/-aviMTza6WJY/XU-vJ1b9IwI/AAAAAAAADoI/jI48rM6Pv5c6pVDmWX4GE-afjetXF70VgCLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.30.52%2BAM.png" width="640" /></a></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><b><i><br /></i></b></span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);">Lets check aws console, grab Public IP and try to access web server either via browser or cli(curl e.g)-</span></span></div>
<div style="text-align: left;">
<a href="https://1.bp.blogspot.com/-Y_IJfYWali8/XU-v2fO2AOI/AAAAAAAADog/Ih2SpfhzkBkHWLWxgxE2cxJ6IqLZQD1gwCLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.33.49%2BAM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="278" data-original-width="1600" height="110" src="https://1.bp.blogspot.com/-Y_IJfYWali8/XU-v2fO2AOI/AAAAAAAADog/Ih2SpfhzkBkHWLWxgxE2cxJ6IqLZQD1gwCLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.33.49%2BAM.png" width="640" /></a><span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><br /></span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-n2dyUzWYxAM/XU-wTm96a-I/AAAAAAAADoo/bhtLTiCn4Wks28BcWw_YQ6IpiTgpEIW-ACLcBGAs/s1600/Screenshot%2B2019-08-11%2Bat%2B11.35.45%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="278" data-original-width="1600" height="110" src="https://1.bp.blogspot.com/-n2dyUzWYxAM/XU-wTm96a-I/AAAAAAAADoo/bhtLTiCn4Wks28BcWw_YQ6IpiTgpEIW-ACLcBGAs/s640/Screenshot%2B2019-08-11%2Bat%2B11.35.45%2BAM.png" width="640" /></a></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;"><span style="caret-color: rgb(51, 51, 51);"><br /></span></span></div>
<div style="text-align: left;">
<span style="color: #333333; font-family: serif; font-size: large;">Thats all for this post. Later we will see how to use variables (Input and Output) to make it more generic and setup cluster on webservers.</span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com2tag:blogger.com,1999:blog-763097243383122769.post-53119438404822046002019-08-09T18:23:00.002+05:302019-10-09T11:43:20.349+05:30Getting started with terraform<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<i style="font-weight: bold;">What is Terraform -</i></h2>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- test -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-0018691690291724"
data-ad-slot="7696655871"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> Ok, so Terraform is Open-Source <b><i>Infrastructure-as-Code</i></b>(IAC) software tool which created by <a href="https://www.hashicorp.com/">HashiCrop</a>. The idea behind IAC is to define, deploy, update and destroy your infrastructure without any much difficulties. The main idea behind this is to treat everything as a code. No matter what it is. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">In this article, I am going in deep to explain about the software and compare this with other lots of available tool sets which together can be replaced this e.g. ansible, chef, puppet, salt, CloudFormation, ARM etc. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">In this specific article, I'll just show how easily we can launch a basic EC2 instance with a small code set. Terraform is simple binary which you can download and put that in your path. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Below is the main architecture diagram which we are going to simulate.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://learning.oreilly.com/library/view/terraform-up/9781492046899/assets/tur2_0105.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Provisioning tools can be used with your cloud provider to create servers, databases, load balancers, and all other parts of your infrastructure." border="0" height="640" src="https://learning.oreilly.com/library/view/terraform-up/9781492046899/assets/tur2_0105.png" width="292" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Create a file "main.tf" where tf stands for teffaform. Add below code snippet to this file.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-TyfPIKBX6NI/XU1leCgj7nI/AAAAAAAADmI/gX9S6z2UNVABnhZAUCiJ7VeiA5YZnHuRQCLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B5.51.52%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="443" data-original-width="1600" height="177" src="https://1.bp.blogspot.com/-TyfPIKBX6NI/XU1leCgj7nI/AAAAAAAADmI/gX9S6z2UNVABnhZAUCiJ7VeiA5YZnHuRQCLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B5.51.52%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Set up your AWS credentials. Here for just testing you can set below variable with you AWS access and secret keys. There are other better ways to handle your credentials, but here I am just using these variable for testing.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<pre data-type="programlisting" style="-webkit-font-smoothing: antialiased; background-color: rgb(251, 251, 251) !important; border: 0px; box-sizing: border-box; color: #404040; font-family: "Ubuntu Mono", monospace; font-size: 15.104px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-ligatures: normal; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 25px; margin-left: 20px; margin-top: 25px; orphans: 2; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: keep-all !important;">$ export AWS_ACCESS_KEY_ID=(your access key id)
$ export AWS_SECRET_ACCESS_KEY=(your secret access key)</pre>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Next, step is to initialise the terraform, using <i style="font-weight: bold;">$terraform init, </i>reason for doing this is because when you specify the provider on the first line, terraform was not having specific plugins to do his job. So after this command it will actually generate a <i style="font-weight: bold;">".terraform" </i>directory with all the required plugin for mentioned provider.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="text-align: left;">
<b>Output -</b></h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-68w2xbYjMYE/XU1m84MSy4I/AAAAAAAADmU/iQXGDV04EpgBg-FF-jYuKKu3QLayC1YuQCLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B5.58.21%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1300" data-original-width="1600" height="516" src="https://1.bp.blogspot.com/-68w2xbYjMYE/XU1m84MSy4I/AAAAAAAADmU/iQXGDV04EpgBg-FF-jYuKKu3QLayC1YuQCLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B5.58.21%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script>
<br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Next is to check if everything is correct before implementing the changes. You can use <i style="font-weight: bold;">"$terraform plan" </i>to check this as below:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6bHTepBuLtc/XU1qQSFWCAI/AAAAAAAADmw/uzIgrkazzAYPrJEUQDHvcSc1BDYTRttCQCEwYBhgL/s1600/Screenshot%2B2019-08-09%2Bat%2B6.12.03%2BPM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" data-original-height="1600" data-original-width="1550" height="640" src="https://1.bp.blogspot.com/-6bHTepBuLtc/XU1qQSFWCAI/AAAAAAAADmw/uzIgrkazzAYPrJEUQDHvcSc1BDYTRttCQCEwYBhgL/s640/Screenshot%2B2019-08-09%2Bat%2B6.12.03%2BPM.png" width="620" /></a><a href="https://1.bp.blogspot.com/-2vUXzZalhJ0/XU1qSCnN9AI/AAAAAAAADm0/Zw-NlEVy1lUkctPnhcmMFkN5WhH9DbqkgCEwYBhgL/s1600/Screenshot%2B2019-08-09%2Bat%2B6.12.22%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1543" data-original-width="1600" height="616" src="https://1.bp.blogspot.com/-2vUXzZalhJ0/XU1qSCnN9AI/AAAAAAAADm0/Zw-NlEVy1lUkctPnhcmMFkN5WhH9DbqkgCEwYBhgL/s640/Screenshot%2B2019-08-09%2Bat%2B6.12.22%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Finally, Let apply these changes to launch the EC2 instance in AWS.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6POLGUY88zo/XU1rVhEdmQI/AAAAAAAADnE/dIPXu8jnkRYQK8U768rkB5S_sQlSbyYYACLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B6.15.31%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1543" data-original-width="1600" height="616" src="https://1.bp.blogspot.com/-6POLGUY88zo/XU1rVhEdmQI/AAAAAAAADnE/dIPXu8jnkRYQK8U768rkB5S_sQlSbyYYACLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B6.15.31%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-oSrN2QP_D7U/XU1rX-RMBpI/AAAAAAAADnI/CxxvfeByu8kIctb06XRaxeXlz0Y5ot-kQCLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B6.15.41%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1543" data-original-width="1600" height="616" src="https://1.bp.blogspot.com/-oSrN2QP_D7U/XU1rX-RMBpI/AAAAAAAADnI/CxxvfeByu8kIctb06XRaxeXlz0Y5ot-kQCLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B6.15.41%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-q77P2q2-M5w/XU1rZWJWpYI/AAAAAAAADnM/2StT33AblQwqKBThp1bDbfp1WhqVG4DJgCLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B6.16.55%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1543" data-original-width="1600" height="616" src="https://1.bp.blogspot.com/-q77P2q2-M5w/XU1rZWJWpYI/AAAAAAAADnM/2StT33AblQwqKBThp1bDbfp1WhqVG4DJgCLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B6.16.55%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Check AWS console for the instance availability:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-YK7jAeYC_qI/XU1r3sR-bJI/AAAAAAAADnY/n3ayVTnPip4IFwtjEoX7st2kzgcqi_usQCLcBGAs/s1600/Screenshot%2B2019-08-09%2Bat%2B6.19.21%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1008" data-original-width="1600" height="402" src="https://1.bp.blogspot.com/-YK7jAeYC_qI/XU1r3sR-bJI/AAAAAAAADnY/n3ayVTnPip4IFwtjEoX7st2kzgcqi_usQCLcBGAs/s640/Screenshot%2B2019-08-09%2Bat%2B6.19.21%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com3tag:blogger.com,1999:blog-763097243383122769.post-58392248748466554302019-07-28T12:32:00.003+05:302019-08-11T10:38:23.439+05:30Kubernetes Access Control Overview and setup up RBAC in Kubernetes Cluster<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="font-size: large;"><span style="font-family: Calibri;">You may have already seen lots of articles discussing about RBAC implementation in Kubernetes Cluster. In this article I am sharing the basic RBAC implementation which I have tested on my local Kubernetes cluster using </span><span style="font-family: Calibri;">Minikube</span><span style="font-family: Calibri;">.</span></span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0in; margin-top: 0pt; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Calibri;"><br /></span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0in; margin-top: 0pt; unicode-bidi: embed; word-break: normal;">
<span style="font-size: large;"><span style="font-family: Calibri;">Below are the details about </span><span style="font-family: Calibri;">Minikube</span><span style="font-family: Calibri;">and </span><span style="font-family: Calibri;">Kubectl</span><span style="font-family: Calibri;">, I am using for this test.</span></span></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; direction: ltr; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; margin-bottom: 0pt; margin-left: 0in; margin-top: 0pt; orphans: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; unicode-bidi: embed; white-space: normal; widows: auto; word-break: normal; word-spacing: 0px;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fxw2NNSlxWE/XT0v4wYok8I/AAAAAAAADjU/azuUvJGn7X8U6bY_AHEQ7rxZwik5Hu23ACLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B10.47.08%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="582" data-original-width="1600" height="232" src="https://1.bp.blogspot.com/-fxw2NNSlxWE/XT0v4wYok8I/AAAAAAAADjU/azuUvJGn7X8U6bY_AHEQ7rxZwik5Hu23ACLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B10.47.08%2BAM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<h3 style="text-align: left;">
Kubernetes Basic Architecture - </h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2KmjZm-x-DY/XT06My99d9I/AAAAAAAADjg/RM5I8AqTjfc5-2JXOY4ajWIl8ECSMkeWQCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B11.31.05%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="851" data-original-width="1600" height="340" src="https://1.bp.blogspot.com/-2KmjZm-x-DY/XT06My99d9I/AAAAAAAADjg/RM5I8AqTjfc5-2JXOY4ajWIl8ECSMkeWQCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B11.31.05%2BAM.png" width="640" /></a></div>
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0in; margin-top: 0pt; unicode-bidi: embed; word-break: normal;">
<div style="text-align: left;">
<span style="font-family: "calibri"; font-size: 18pt;"></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri"; font-size: 18pt;"><span style="font-family: "calibri"; font-size: 18pt;"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri"; font-size: 18pt;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "calibri"; font-size: large;"><span style="font-family: "calibri"; font-size: 18pt;">In Kubernetes, you must be authenticated (or logged in) before your request can be authorized (granted permission to access). </span><span style="font-family: "calibri"; font-size: 18pt;">You can go through official documentation for more details </span><span style="font-family: "calibri"; font-size: 18pt;"><a href="http://You may have already seen lots of articles discussing about RBAC implementation in Kubernetes Cluster. In this article I am sharing the basic RBAC implementation which I have tested on my local Kubernetes cluster using Minikube.">Accessing Control Overview</a></span><span style="font-family: "calibri"; font-size: 18pt;">.</span></span></div>
<br />
<span style="font-family: "calibri"; font-size: large;"><br /></span></div>
<span style="font-family: calibri; font-size: large;">There are two types for requests made to Kubernetes API-Serve one is the external request made by human being and another is internal from pod using service accounts. </span><br />
<span style="font-family: calibri; font-size: large;"><br /></span>
<span style="font-family: calibri; font-size: large;">In this post we'll discuss about first type. Note that external users not stored in Kubernetes, these will be stored somewhere in external system and there are multiple type of authentications. We will discuss here with x509 certificates.</span><br />
<span style="font-family: calibri;"><br /></span>
<br />
<h3 style="text-align: left;">
<span style="font-family: calibri; font-size: large;">Authentication and Autherization Process-</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-sU8IPvbRIrw/XT06rVAHUHI/AAAAAAAADjo/BUMpZXjJtSk6FWddYxdEiobs9O3fZAKHACLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B11.33.11%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="851" data-original-width="1600" height="340" src="https://1.bp.blogspot.com/-sU8IPvbRIrw/XT06rVAHUHI/AAAAAAAADjo/BUMpZXjJtSk6FWddYxdEiobs9O3fZAKHACLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B11.33.11%2BAM.png" width="640" /></a></div>
<div>
<span style="font-family: calibri; font-size: large;"><br /></span></div>
<h4 style="text-align: left;">
<span style="font-size: large;"><span style="font-family: calibri;">Setup -</span><span style="font-family: calibri;">Let's start with setup.</span></span></h4>
<div style="text-align: left;">
</div>
<ol style="text-align: left;">
<li><span style="font-family: calibri;"><span style="font-size: large;">Create a new user and its certificate and key using existing minikube CA details.</span></span></li>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script>
<ul>
<li><span style="font-family: calibri; font-size: large;">Check existing contexts. We will be working on Minikube Cluster.</span></li>
</ul>
</ol>
<blockquote class="tr_bq">
<i><span style="font-size: large;">$ kubectl config view -o jsonpath='{"Cluster-name\t\t\tServer\n"}{range .clusters[*]}{.name}{"\t\t"}{.cluster.server}{"\n"}{end}'</span></i></blockquote>
<br />
<div style="text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-1Fx8-X6uFfE/XT08p2Fj2-I/AAAAAAAADj0/wydcAwaQylYYVSqr-dzptPtQcdui2qesACLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B11.41.29%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="309" data-original-width="1600" height="122" src="https://1.bp.blogspot.com/-1Fx8-X6uFfE/XT08p2Fj2-I/AAAAAAAADj0/wydcAwaQylYYVSqr-dzptPtQcdui2qesACLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B11.41.29%2BAM.png" width="640" /></a></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div style="text-align: left;">
<ul style="text-align: left;"><ul>
<li><span style="font-family: calibri; font-size: large;">Fetch the API-SERVER details-</span></li>
</ul>
</ul>
</div>
<br />
<blockquote class="tr_bq">
<i><span style="font-size: large;">$export CLUSTER_NAME=minikube<br />$APISERVER=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$CLUSTER_NAME\")].cluster.server}")<br />$ echo $APISERVER</span></i></blockquote>
<div style="text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-sJTgMsp_mcM/XT09afU1gJI/AAAAAAAADj8/JrvcF1UgP24nQ7ZjWJq_VYMlD2rNBQRIACLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B11.44.53%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="309" data-original-width="1600" height="122" src="https://1.bp.blogspot.com/-sJTgMsp_mcM/XT09afU1gJI/AAAAAAAADj8/JrvcF1UgP24nQ7ZjWJq_VYMlD2rNBQRIACLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B11.44.53%2BAM.png" width="640" /></a></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<ul style="text-align: left;"><ul>
<li><span style="font-family: calibri; font-size: large;">Create key for new user "kuldeep". Then create csr(certificate singing request). Note down the format "/CN=kuldeep/O=qa-reader" . CN = UserName, O=Role in which User will be added later on.</span></li>
</ul>
</ul>
<div>
<blockquote class="tr_bq">
<span style="font-size: large;"><i>$openssl genrsa -out kuldeep.key 2048</i><i>$openssl req -new -key kuldeep.key -out kuldeep.csr -subj "/CN=kuldeep/O=qa-reader"</i><i>$openssl x509 -req -in kuldeep.csr -CA ~/.minikube/ca.crt -CAkey ~/.minikube/ca.key -CAcreateserial -out kuldeep.crt -days 500</i></span></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-n48JcqSTpsw/XT1ALbG7BXI/AAAAAAAADkI/gOfkf1NSb04QlDPKrUD6A5sJr8xMyMKWgCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B11.55.18%2BAM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1000" data-original-width="1600" height="400" src="https://1.bp.blogspot.com/-n48JcqSTpsw/XT1ALbG7BXI/AAAAAAAADkI/gOfkf1NSb04QlDPKrUD6A5sJr8xMyMKWgCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B11.55.18%2BAM.png" width="640" /></a></div>
<br />
<span style="font-size: large;">2. Now lets add a new context with new credentials for user kuldeep. Note that we have set qa as default namespace for "kuldeep-context" configured for user "kuldeep".</span><br />
<blockquote class="tr_bq">
<i><span style="font-size: large;">$kubectl config get-contexts<br />$kubectl config set-credentials kuldeep --client-certificate=/Users/kulsharm2/k8s-rbac/kuldeep.crt --client-key=/Users/kulsharm2/k8s-rbac/kuldeep.key<br />$kubectl config set-context kuldeep-context --cluster=minikube --namespace=qa --user=kuldeep<br />$kubectl config get-contexts</span></i></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-gqXqhHGtDz8/XT1C2LyNRxI/AAAAAAAADkU/ZCpTRhK8C9gnS1Pyc52GjXsWYMtyMIaZwCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B12.08.04%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="569" data-original-width="1600" height="226" src="https://1.bp.blogspot.com/-gqXqhHGtDz8/XT1C2LyNRxI/AAAAAAAADkU/ZCpTRhK8C9gnS1Pyc52GjXsWYMtyMIaZwCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B12.08.04%2BPM.png" width="640" /></a></div>
</div>
</div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri; font-size: large;">3. Create namespace qa and check if "kuldeep" user have permission to access it. We should get forbidden as till now we configured authentication not authorization.</span></div>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-RuL2eJ1BUcA/XT1Dm1NDvPI/AAAAAAAADkc/eYeFXCPgtaYXEIm317_K_t_cS555_RP_QCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B12.11.18%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="264" data-original-width="1600" height="104" src="https://1.bp.blogspot.com/-RuL2eJ1BUcA/XT1Dm1NDvPI/AAAAAAAADkc/eYeFXCPgtaYXEIm317_K_t_cS555_RP_QCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B12.11.18%2BPM.png" width="640" /></a></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri; font-size: large;">As expected we got "Forbidden". Let move to next part of Authorization.</span></div>
<div>
<span style="font-family: calibri; font-size: large;"><br /></span></div>
<div>
<span style="font-family: calibri; font-size: large;">4. Authorizing "kuldeep" user to list and watch the deployment/pod entities in qa namespace. For this first we need to create a role and then bind that role with user "kuldeep", After Adding below, you will be able to list down pods and deployments in <b><i>"qa"</i></b> namespace.</span></div>
<div>
<span style="font-family: calibri; font-size: large;"><br /></span></div>
<h4 style="text-align: left;">
<span style="font-family: calibri; font-size: large;">roles.yaml-</span></h4>
<div>
<blockquote class="tr_bq">
<i><span style="font-size: large;">kind: Role<br />apiVersion: rbac.authorization.k8s.io/v1beta1<br />metadata:<br /> namespace: qa<br /> name: qa_reader_role<br />rules:<br />- apiGroups: ["", "extensions", "apps"]<br /> resources: ["pods", "deployments"]<br /> verbs: ["get", "list", "watch"] </span></i></blockquote>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<h4 style="text-align: left;">
<span style="font-family: calibri; font-size: large;">roles-binding.yaml-</span></h4>
<div>
<blockquote class="tr_bq">
<span style="font-size: large;"><i>kind: RoleBinding</i><i>apiVersion: rbac.authorization.k8s.io/v1beta1</i><i>metadata:</i><i> name: qa_reader_binding</i><i> namespace: qa</i><i>subjects:</i><i>- kind: User</i><i> name: kuldeep</i><i> apiGroup: ""</i><i>roleRef:</i><i> kind: Role</i><i> name: qa_reader_role</i><i> apiGroup: ""</i></span></blockquote>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-MJtWPxFs6-o/XT1HNa_mZdI/AAAAAAAADko/T4FQKws5o_kEOoLQMBmLHQhyfLUHrOMGwCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B12.25.35%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="785" data-original-width="1600" height="314" src="https://1.bp.blogspot.com/-MJtWPxFs6-o/XT1HNa_mZdI/AAAAAAAADko/T4FQKws5o_kEOoLQMBmLHQhyfLUHrOMGwCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B12.25.35%2BPM.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri; font-size: large;">Now, since we have provided permission for pod and deployment objects. Lets reconfirm this by accessing other objects e.g. configmap or secrets. You should get Forbidden for these.</span></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-0q0kKAVxfb0/XT1H3zRIbKI/AAAAAAAADkw/5VtIN3By8KQw-a5oyp1SJv_KK0yeRZRugCLcBGAs/s1600/Screenshot%2B2019-07-28%2Bat%2B12.29.26%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="540" data-original-width="1600" height="216" src="https://1.bp.blogspot.com/-0q0kKAVxfb0/XT1H3zRIbKI/AAAAAAAADkw/5VtIN3By8KQw-a5oyp1SJv_KK0yeRZRugCLcBGAs/s640/Screenshot%2B2019-07-28%2Bat%2B12.29.26%2BPM.png" width="640" /></a></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<div>
<span style="font-family: calibri;"><br /></span></div>
<br />
<div style="text-align: left;">
<span style="font-family: calibri;">Hope you will like this!!</span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com5tag:blogger.com,1999:blog-763097243383122769.post-22182354419553964652019-07-20T23:27:00.001+05:302019-07-21T19:13:39.046+05:30How to check Mac OS X Version and other related information<div dir="ltr" style="text-align: left;" trbidi="on">
There are few ways you can use to check OS X version.<br />
<br />
<div style="text-align: left;">
First and simple one is the GUI. Just click on the <span style="background-color: white; color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;">Apple menu (</span><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"></span><span style="background-color: white; color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;">) at the top left of your screen, and choose </span><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;">About This Mac.</span></div>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qtAuZFCaBq0/XTNOSy0qsMI/AAAAAAAADgM/RpGVkpqkDUgSDR7afmuQr8zXaEiiB2ISQCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B8.33.08%2BPM.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="608" data-original-width="612" height="198" src="https://1.bp.blogspot.com/-qtAuZFCaBq0/XTNOSy0qsMI/AAAAAAAADgM/RpGVkpqkDUgSDR7afmuQr8zXaEiiB2ISQCLcBGAs/s200/Screenshot%2B2019-07-20%2Bat%2B8.33.08%2BPM.png" width="200" /></a></div>
<a href="https://1.bp.blogspot.com/-bp0uc2SqKEw/XTNPlXZDH2I/AAAAAAAADgY/O3JPfC5T7lwpq9Z8aq9iuPVsQWcVcC2xQCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B10.56.03%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="686" data-original-width="1176" height="185" src="https://1.bp.blogspot.com/-bp0uc2SqKEw/XTNPlXZDH2I/AAAAAAAADgY/O3JPfC5T7lwpq9Z8aq9iuPVsQWcVcC2xQCLcBGAs/s320/Screenshot%2B2019-07-20%2Bat%2B10.56.03%2BPM.png" width="320" /></a><br />
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;">What but if you don't have access to GUI or you want to fetch these details through scripts, then you can use below CLI methods to find out the same.</span><br />
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><br /></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);">1. <i style="font-weight: bold;">sw_vers - </i>This command will show the ProductName, ProductVersion and BuildVersion.</span></span><br />
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);"><br /></span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-reiNnCsssQg/XTNR9dsbKvI/AAAAAAAADgk/FRQc9QM0lvAoZHWmM5peOXcuumhsCn31QCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.09.07%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="438" data-original-width="776" height="356" src="https://1.bp.blogspot.com/-reiNnCsssQg/XTNR9dsbKvI/AAAAAAAADgk/FRQc9QM0lvAoZHWmM5peOXcuumhsCn31QCLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.09.07%2BPM.png" width="640" /></a> <a href="https://1.bp.blogspot.com/-KdF3_3OsuqU/XTNTljSJzwI/AAAAAAAADg4/-7K6IPzGzCw7nhu1JCvgx97nxc3_bRKEQCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.16.27%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="296" data-original-width="1098" height="171" src="https://1.bp.blogspot.com/-KdF3_3OsuqU/XTNTljSJzwI/AAAAAAAADg4/-7K6IPzGzCw7nhu1JCvgx97nxc3_bRKEQCLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.16.27%2BPM.png" width="640" /></a></div>
<br />
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);"><br /></span></span>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);"><b><i>2. System Profile (system_profile) - </i></b></span></span><br />
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);"><br /></span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kn7U-a9ZDyk/XTNTKNhUc6I/AAAAAAAADgw/YYFOe4mWpMM5CSkuYlCwRGWb2wGvZkHbACLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.14.50%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="726" data-original-width="1288" height="360" src="https://1.bp.blogspot.com/-kn7U-a9ZDyk/XTNTKNhUc6I/AAAAAAAADgw/YYFOe4mWpMM5CSkuYlCwRGWb2wGvZkHbACLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.14.50%2BPM.png" width="640" /></a></div>
<span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);"><br /></span></span>
<b><i><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif;"><span style="caret-color: rgb(17, 17, 17);">3. </span></span><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;">Mac OS X user defaults system</span></i></b><br />
<b><i><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span></i></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-HWZWAeUmf30/XTNULlIMKWI/AAAAAAAADhE/ogLj2cPZ9R4HflgzLLABQ47jganubXMrgCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.18.36%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="203" data-original-width="1600" height="80" src="https://1.bp.blogspot.com/-HWZWAeUmf30/XTNULlIMKWI/AAAAAAAADhE/ogLj2cPZ9R4HflgzLLABQ47jganubXMrgCLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.18.36%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>4. Let the System speak it for you :)-</i></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-wty0lZT4IgA/XTRr8LrBMYI/AAAAAAAADhs/xZLsWAOnd48bIvWRKzUu2nT2tK_RkJo6ACLcBGAs/s1600/Screenshot%2B2019-07-21%2Bat%2B7.12.42%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="858" height="297" src="https://1.bp.blogspot.com/-wty0lZT4IgA/XTRr8LrBMYI/AAAAAAAADhs/xZLsWAOnd48bIvWRKzUu2nT2tK_RkJo6ACLcBGAs/s640/Screenshot%2B2019-07-21%2Bat%2B7.12.42%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>5. Kernal and Machine Architecture Details(uname)-</i></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-iSPjhfoWAIQ/XTNVqEdpTvI/AAAAAAAADhQ/0Rinacb3G5o_sRJnv87356-79ZGMHan1gCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.25.33%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="367" data-original-width="1600" height="144" src="https://1.bp.blogspot.com/-iSPjhfoWAIQ/XTNVqEdpTvI/AAAAAAAADhQ/0Rinacb3G5o_sRJnv87356-79ZGMHan1gCLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.25.33%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>Different available options-</i></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-oDVJvPMDBNI/XTNV3_5ONNI/AAAAAAAADhU/jqGhyxvikSM0ToO5NEA4SR42bofAFyWYQCLcBGAs/s1600/Screenshot%2B2019-07-20%2Bat%2B11.22.19%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="399" data-original-width="1600" height="156" src="https://1.bp.blogspot.com/-oDVJvPMDBNI/XTNV3_5ONNI/AAAAAAAADhU/jqGhyxvikSM0ToO5NEA4SR42bofAFyWYQCLcBGAs/s640/Screenshot%2B2019-07-20%2Bat%2B11.22.19%2BPM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i><br /></i></b></div>
<b><i><span style="color: #111111; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 16px;"><br /></span></i></b></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com1tag:blogger.com,1999:blog-763097243383122769.post-29125594728513037102019-07-08T21:37:00.002+05:302019-09-05T09:21:04.636+05:30Running and Dynamically Scaling your Jenkins (CI/CD) platform on Kubernetes<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script>
<span style="color: blue;"><span style="background-color: white;">Overview</span></span></h2>
Now a days in the fast moving and changing world, we need a CI/CD platform which we can scale in/out as per requirements. This auto scaling feature help us to be cost effective and don't need to worry about the changing demands.<br />
<br />
In this article will go through the implementation of same kind of setup. Here we'll create Jenkins setup which will be on Kubernetes and scale automatically as per needs.<br />
<br />
Interesting thing is that for this demo you don't need any specific inhouse or cloud platform. We are going to do this exercise using Docker Desktop. I have done this on Windows, but if you can use this for Mac as well.<br />
<br />
Just want to summarize the tools, not going in deapth as assuming that most of the guys are aware on these tool sets. Otherwise suggest to follow documentation.<br />
<br />
<h3 style="text-align: left;">
Jenkins - </h3>
<div style="text-align: left;">
<a href="https://jenkins.io/" target="_blank">Jenkins </a>is the leading open source automation server, Jenkins provides
hundreds of plugins to support building, deploying and automating
any project. We can install Jenkins using native system packages, container platform like docker or can be run standalone on any machine with a JRE installed.</div>
<br />
<br />
<h3 style="text-align: left;">
Kubernetes -</h3>
<div style="text-align: left;">
<a href="https://kubernetes.io/" target="_blank">Kubernetes</a> is an open source container orchestration platform. This project is being managed by <a href="https://www.cncf.io/" target="_blank">CNCF </a>. </div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<h3 style="text-align: left;">
Final Setup -</h3>
Below is the final setup that we are going to build. In this setup we initially we'll be having one Master Pod running and slaves will be provisioned dynamically based on the requirements.<br />
- This will help us "Not to worry about adding extra node, when demands gets increased".<br />
- New slave node will be added dynamically and the jobs be executed on new pods. After job execution pods will get terminated.<br />
<br /></div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-d3qxViRdhzg/XSB0tLT-fjI/AAAAAAAADc0/7fkN6rM_k1gKODbXFq935DMzWptCzmtygCLcBGAs/s1600/k1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="487" data-original-width="785" height="397" src="https://1.bp.blogspot.com/-d3qxViRdhzg/XSB0tLT-fjI/AAAAAAAADc0/7fkN6rM_k1gKODbXFq935DMzWptCzmtygCLcBGAs/s640/k1.png" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
</div>
<h3 style="text-align: left;">
Setup Requirements-</h3>
To complete this guide, you will need the following:<br />
<ul>
<li><b>Docker Desktop - </b>Used <b>Docker Desktop </b>on my local system, but this can be done on high capacity on-prem servers or any cloud based solutions.</li>
<li><b>Docker Hub account</b>: We will need an account with a container image repository to push the custom images for our Jenkins master and agents.</li>
<li><b>kubectl </b>- A cli tool to connect to local kubernetes cluster. </li>
</ul>
<h2 id="building-custom-images-for-jenkins">
Lets Build Docker Images for Jenkins</h2>
Let’s start by building docker images for our Jenkins components and then push them to <a href="https://hub.docker.com/">Docker Hub</a>.<br />
After instaled the "Docker Desktop" and exposing that on "localhost", you will able to able to run all docker commands.<br />
Once everything is in place, lets start with creating <a href="https://docs.docker.com/engine/reference/builder/">Dockerfiles</a>.<br />
<h3 id="writing-the-jenkins-master-dockerfile">
Dockerfile for Jenkins Master - </h3>
We can begin by creating a file called <code>Dockerfile </code>in "master" folder in the current directory to define the Jenkins master image:<br />
<br />
<blockquote class="tr_bq">
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
FROM jenkins/jenkins:lts<br />
# Plugins for better UX (not mandatory) <br />
RUN /usr/local/bin/install-plugins.sh ansicolor<br />
RUN /usr/local/bin/install-plugins.sh greenballs<br />
# Plugin for scaling Jenkins agents<br />
RUN /usr/local/bin/install-plugins.sh kubernetes <br />
USER jenkins</div>
</blockquote>
<br />
<br />
<h3 id="writing-the-jenkins-agent-dockerfiles">
Dockerfile for Jenkins Agent - </h3>
Now lets create two new folder "slave1" and "slave2" for demonstrating how jenkins can identify the correct agent for different jobs.<br />
Create an empty uniq file in the each directory. We will copy this to the image as an identifier for each agent we are building:<br />
<h4 style="text-align: left;">
<b> Slave1 -</b></h4>
<blockquote class="tr_bq">
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
FROM jenkins/jnlp-slave<br />
# For testing purpose only<br />
COPY empty-test-file /jenkins-slave1<br />
ENTRYPOINT ["jenkins-slave"]</div>
</blockquote>
<h3 id="building-the-images-and-pushing-to-docker-hub">
Slave2 - </h3>
<blockquote class="tr_bq">
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
FROM jenkins/jnlp-slave<br />
# For testing purpose only<br />
COPY empty-test-file /jenkins-slave2<br />
ENTRYPOINT ["jenkins-slave"]</div>
</blockquote>
<h3 id="building-the-images-and-pushing-to-docker-hub">
</h3>
<h3 id="building-the-images-and-pushing-to-docker-hub">
</h3>
<h3 id="building-the-images-and-pushing-to-docker-hub">
Lets Build docker Images and Push those to Docker Hub</h3>
<b>Note: In the command below, replace <code><dockerhub_user></dockerhub_user></code> with your Docker Hub account name.</b><br />
<i><b>From "master" folder - </b></i><br />
$<i>docker build -t deepforu47/jenkins-master .</i><br />
<i><b>From "slave1" folder -</b> </i><br />
$<i>docker build -t deepforu47/jenkins-slave-jnlp1 .</i><br />
<i><b>From "slave2" folder -</b></i> <br />
$<i>docker build -t deepforu47/jenkins-slave-jnlp2 .</i><br />
<br />
<br />
<b>Log in to Docker Hub(My case picked existing credentials, but it will ask you for username and password) -</b><br />
<i>$ docker login<br />Authenticating with existing credentials...<br />Login Succeeded</i><b><br /></b><br />
<br />
Now, push the image to your Docker Hub account:<br />
<b>Note: In the command below, be sure to substitute your own Docker Hub account again.</b><br />
<br />
$ docker push deepforu47/jenkins-master<br />
$ docker push deepforu47/jenkins-slave-jnlp1<br />
$ docker push deepforu47/jenkins-slave-jnlp2<br />
<br />
Below is the screenshot from my dockerhub account -<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<b><a href="https://1.bp.blogspot.com/-AgqPnUVMj_I/XSB2IwuzioI/AAAAAAAADdA/gu5WYdMWC2sY8TjBvi3kxC9zqL3vRSKIACLcBGAs/s1600/k2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="407" data-original-width="1216" height="211" src="https://1.bp.blogspot.com/-AgqPnUVMj_I/XSB2IwuzioI/AAAAAAAADdA/gu5WYdMWC2sY8TjBvi3kxC9zqL3vRSKIACLcBGAs/s640/k2.png" width="640" /></a></b></div>
<br />
<h3 id="building-the-images-and-pushing-to-docker-hub">
</h3>
<br />
<h2 id="deploying-jenkins-to-the-cluster">
Deploying Jenkins to the Local Docker Desktop Cluster - </h2>
<div id="writing-the-jenkins-agent-dockerfiles" style="text-align: left;">
Now lets first create a k8s deployment entity for deploying jenkins master node.<br />
<br />
<h4 style="text-align: left;">
Deployment.yaml </h4>
</div>
<b>Note: Make sure to change <code><dockerhub_user></dockerhub_user></code> to your Docker Hub account name in the file below.</b><br />
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
<div>
<span style="color: #d4d4d4;"> apiVersion: extensions/v1beta1<br /> kind: Deployment<br /> metadata:<br /> name: jenkins<br /> spec:<br /> replicas: 1<br /> template:<br /> metadata:<br /> labels:<br /> app: jenkins<br /> spec:<br /> containers:<br /> - name: jenkins<br /> image: deepforu47/jenkins-master<br /> env:<br /> - name: JAVA_OPTS<br /> value: -Djenkins.install.runSetupWizard=false<br /> ports:<br /> - name: http-port<br /> containerPort: 8080<br /> - name: jnlp-port<br /> containerPort: 50000<br /> volumeMounts:<br /> - name: jenkins-home<br /> mountPath: /var/jenkins_home<br /> volumes:<br /> - name: jenkins-home<br /> emptyDir: {}</span></div>
</div>
<br />
<br />
Now, lets create k8s services, one to access Jenkins and second for the internal communication between jenkins master and agent nodes.<br />
<br />
<h4 style="text-align: left;">
Service.yaml</h4>
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
apiVersion: v1<br />
kind: Service<br />
metadata:<br />
name: jenkins<br />
spec:<br />
type: ClusterIP<br />
ports:<br />
- port: 80<br />
targetPort: 8080<br />
selector:<br />
app: jenkins<br />
---<br />
<br />
apiVersion: v1<br />
kind: Service<br />
metadata:<br />
name: jenkins-jnlp<br />
spec:<br />
type: ClusterIP<br />
ports:<br />
- port: 50000<br />
targetPort: 50000<br />
selector:<br />
app: jenkins</div>
<h4 style="text-align: left;">
</h4>
<h4 style="text-align: left;">
</h4>
<h4 style="text-align: left;">
Now lets deploy these manifiest to cluster with below commands- </h4>
$<i>kubectl apply -f deployment.yaml</i><br />
$<i>kubectl apply -f service.yaml </i><br />
<br />
After this below is what you will get after queries kubernetes for pod and services.<br />
<br />
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, 'Courier New', monospace; font-size: 14px; font-weight: normal; line-height: 19px; white-space: pre;">
<div>
<span style="color: #d4d4d4;"> $ kubectl get pods <br /> NAME READY STATUS RESTARTS AGE <br /> jenkins-6c94659b89-dsbxx 1/1 Running 1 3d <br /> <br /> $ kubectl get svc <br /> NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE <br /> jenkins ClusterIP 10.106.79.175 <none> 80/TCP 3d <br /> jenkins-jnlp ClusterIP 10.97.51.149 <none> 50000/TCP 3d <br /> kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d </none></none></none></span></div>
</div>
<br />
<i> </i><br />
<br />
<br />
<h1 class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="">
Expose the jenkins service-</h1>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now, lets expose the jenkins service and try to access jenkins locally.</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, 'Courier New', monospace; font-size: 14px; font-weight: normal; line-height: 19px; white-space: pre;">
<div>
<span style="color: #d4d4d4;"> $ kubectl port-forward svc/jenkins 80:80<br /> Forwarding from 127.0.0.1:80 -> 8080<br /> Forwarding from [::1]:80 -> 8080<br /> Handling connection for 80<br /> Handling connection for 80<br /> Handling connection for 80</span></div>
</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<h1 class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="">
<span id="goog_193636758"></span><span id="goog_193636759"></span> </h1>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-rJcO3KnsGFU/XSNcA38w85I/AAAAAAAADdc/rLqBWsYtZwQQaJmz_yB5KkiDQ2KSXXbAgCEwYBhgL/s1600/jenkins1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="395" data-original-width="1307" height="192" src="https://1.bp.blogspot.com/-rJcO3KnsGFU/XSNcA38w85I/AAAAAAAADdc/rLqBWsYtZwQQaJmz_yB5KkiDQ2KSXXbAgCEwYBhgL/s640/jenkins1.png" width="640" /></a></div>
<h1 class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="">
Enable the Jenkins Slaves Autoscaling-</h1>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now, configure jenkins with kubernetes cloud plugin so that it can spin up new jenkins slave pod and scale automatically . </div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
First of disable default master agent by going to "<i><b>Manage Jenkins</b></i>" --> "<i><b>Manage Nodes</b></i>" and then remove the all agent other than "<i><b>Master</b></i>". </div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Finally it will be like below -</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-rJCt6xEV9w0/XSNfHE94h4I/AAAAAAAADdo/mEZ3hHdy4hEOx5E0UB7zfBAIcBhDTWDCACLcBGAs/s1600/jenkins2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="315" data-original-width="1310" height="152" src="https://1.bp.blogspot.com/-rJCt6xEV9w0/XSNfHE94h4I/AAAAAAAADdo/mEZ3hHdy4hEOx5E0UB7zfBAIcBhDTWDCACLcBGAs/s640/jenkins2.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
After this change the number of executor to 0 by clicking on configure gear.</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ClvjQjSYwsw/XSNfmMmMQvI/AAAAAAAADdw/rr8O5eyVvnMD89E25IX3D5gCHbB6IqZYgCLcBGAs/s1600/jenkins3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="393" data-original-width="1314" height="190" src="https://1.bp.blogspot.com/-ClvjQjSYwsw/XSNfmMmMQvI/AAAAAAAADdw/rr8O5eyVvnMD89E25IX3D5gCHbB6IqZYgCLcBGAs/s640/jenkins3.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<h4 class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Configure Jenkins Kubernetes plugins-</h4>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now install "kubernetes" plugin by going to "<b>Manage Jenkins</b>" <b>--> </b>"<b>Manage Plugins</b>". Search for "Kubernetes Plugin" in available and install.</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6iqgMMBhBYs/XSNgp3cRMmI/AAAAAAAADd8/8uBdEQsupkAOqmu3QlV2z-R6xQ-yIW3LwCLcBGAs/s1600/jenkins4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="497" data-original-width="1319" height="240" src="https://1.bp.blogspot.com/-6iqgMMBhBYs/XSNgp3cRMmI/AAAAAAAADd8/8uBdEQsupkAOqmu3QlV2z-R6xQ-yIW3LwCLcBGAs/s640/jenkins4.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now, configure the kubenetes plugin. Go to <b>"Manage Jenkins" --> "Configure System". </b>Scroll down to cloud section and <b>"Add a new cloud" </b>and select <b>"Kubernetes"</b>.</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-n2Mclbg0VZE/XSNiMXZPTRI/AAAAAAAADeI/nuQXy6LfKEYpU8cKf0HW1H6c1p2Bin8xQCLcBGAs/s1600/jenkins5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="557" data-original-width="1314" height="270" src="https://1.bp.blogspot.com/-n2Mclbg0VZE/XSNiMXZPTRI/AAAAAAAADeI/nuQXy6LfKEYpU8cKf0HW1H6c1p2Bin8xQCLcBGAs/s640/jenkins5.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<b><a href="https://1.bp.blogspot.com/-hDPv3SNNGh4/XSNitQIh3sI/AAAAAAAADeQ/D1c1hNzpFsET-CzoeRKxexMq1dr6JomtQCLcBGAs/s1600/jenkins6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="523" data-original-width="1310" height="254" src="https://1.bp.blogspot.com/-hDPv3SNNGh4/XSNitQIh3sI/AAAAAAAADeQ/D1c1hNzpFsET-CzoeRKxexMq1dr6JomtQCLcBGAs/s640/jenkins6.png" width="640" /></a></b></div>
<br />
<br />
<br />
Go to the <b>Images</b> section, click the <b>Add Pod Template</b> button, and select <b>Kubernetes Pod Template</b>. Fill out the <b>Name</b> and <b>Labels</b>
fields with unique values to identify your first agent.<br />
<br />
We will use
the label to specify which agent image should be used to run each build.<br />
Next, in the <b>Containers</b> field, click the <b>Add Container</b> button and select <b>Container Template</b>. In the section that appears, fill out the following fields:<br />
<ul>
<li><b>Name</b>: <code>jnlp</code> (this is required by the Jenkins agent)</li>
<li><b>Docker image</b>: <code><dockerhub_user>deepforu47/jenkins-slave-jnlp1</dockerhub_user></code> (make sure to change the Docker Hub username)</li>
<li><b>Command to run</b>: Delete the value here</li>
<li><b>Arguments to pass to the command</b>: Delete the value here</li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qVfBoECJtIU/XSNjfigK6SI/AAAAAAAADec/qn2velOjSEcFcpF-8XP6rSGp68e1TCsUQCLcBGAs/s1600/jenkins7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="571" data-original-width="1302" height="280" src="https://1.bp.blogspot.com/-qVfBoECJtIU/XSNjfigK6SI/AAAAAAAADec/qn2velOjSEcFcpF-8XP6rSGp68e1TCsUQCLcBGAs/s640/jenkins7.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Follow the same steps for second template -</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-FMFUB1IbQLw/XSNj5wWepgI/AAAAAAAADek/Wnwue9CkxUU53M1h9kLN6LeEe-shJaDsgCLcBGAs/s1600/jenkins8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="565" data-original-width="1302" height="276" src="https://1.bp.blogspot.com/-FMFUB1IbQLw/XSNj5wWepgI/AAAAAAAADek/Wnwue9CkxUU53M1h9kLN6LeEe-shJaDsgCLcBGAs/s640/jenkins8.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<h4 class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Test the dynamic build job-</h4>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now, create two new jobs. Make sure to update the <b>Label Expression</b> field, type
the label you set for first and second Jenkins agent image. </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-RXCtP1VEe6k/XSNl8e7905I/AAAAAAAADew/Ez3JojuWedAsCUt2WlY4mjMiEu5wdsWggCLcBGAs/s1600/jenkins9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="554" data-original-width="1214" height="292" src="https://1.bp.blogspot.com/-RXCtP1VEe6k/XSNl8e7905I/AAAAAAAADew/Ez3JojuWedAsCUt2WlY4mjMiEu5wdsWggCLcBGAs/s640/jenkins9.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-i1Oe1crtXXk/XSNmOoY26EI/AAAAAAAADe4/feUGsoyaiXQ69__Hwpyya5mGMyKE9OBGACLcBGAs/s1600/jenkins10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="547" data-original-width="1241" height="282" src="https://1.bp.blogspot.com/-i1Oe1crtXXk/XSNmOoY26EI/AAAAAAAADe4/feUGsoyaiXQ69__Hwpyya5mGMyKE9OBGACLcBGAs/s640/jenkins10.png" width="640" /></a></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
Now, try to build these jobs and you will be the new slave pods created. After jobs finished, these newly created pods will get terminated automatically.</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br /></div>
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; line-height: 19px; text-align: left; white-space: pre;">
<div>
<span style="color: #d4d4d4;"> $ kubectl get pod <br /> NAME READY STATUS RESTARTS AGE <br /> jenkins-6c94659b89-dsbxx 1/1 Running 1 3d <br /> <br /><br /> $ kubectl get pod -w <br /> NAME READY STATUS RESTARTS AGE <br /> jenkins-6c94659b89-dsbxx 1/1 Running 1 3d <br /> jenkins-slave-jnlp1-jjkwh 1/1 Running 0 7s <br /> jenkins-slave-jnlp2-1fpkf 1/1 Running 0 7s <br /> <br /><br /> $ kubectl get pod <br /> NAME READY STATUS RESTARTS AGE <br /> jenkins-6c94659b89-dsbxx 1/1 Running 1 3d <br /> jenkins-slave-jnlp1-jjkwh 1/1 Terminating 0 15s <br /> jenkins-slave-jnlp2-1fpkf 1/1 Running 0 15s <br /> <br /><br /> $ kubectl get pod <br /> NAME READY STATUS RESTARTS AGE <br /> jenkins-6c94659b89-dsbxx 1/1 Running 1 3d </span></div>
</div>
<div class="kg kh du aq ap ds ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="" style="text-align: left;">
<br />
Note - You can see all the codebase on my github account i.e. <a href="https://github.com/deepforu47/k8s-jenkins">https://github.com/deepforu47/k8s-jenkins.</a></div>
</div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-0018691690291724", enable_page_level_ads: true }); </script>Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-43811732526093662612019-06-03T12:40:00.001+05:302019-06-03T12:57:39.244+05:30Points to keep in mind while starting you migration journey towards Kubernetes <div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Things to bear in mind while migrating to Kubernetes : </h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-yMDJe_kBwYU/XPTL3wkG1ZI/AAAAAAAADZI/F_YQbqF2U608WMnrnz63tdgYeenYoiXTACLcBGAs/s1600/Kubernetes_New.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="389" data-original-width="730" height="170" src="https://1.bp.blogspot.com/-yMDJe_kBwYU/XPTL3wkG1ZI/AAAAAAAADZI/F_YQbqF2U608WMnrnz63tdgYeenYoiXTACLcBGAs/s320/Kubernetes_New.png" width="320" /></a></div>
<div>
<br /></div>
<span style="font-family: "georgia" , "times new roman" , serif;">Recently I have been reading book "Cloud Native DevOps with Kubernetes" and found some interesting facts about the migration towards container and Kubernetes. Thought of sharing those with you.</span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">Below are the point we should know and consider while moving towards cloud native or DevOps culture using kubernetes.</span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Kubernetes clusters are made up of master nodes, which run the control plane, and worker nodes, which run your workloads. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Production clusters must be highly available, meaning that the failure of a master node won’t lose data or affect the operation of the cluster. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• It’s a long way from a simple demo cluster to one that’s ready for critical production workloads. High availability, security, and node management are just some of the issues involved. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Managing your own clusters requires a significant investment of time, effort, and expertise. Even then, you can still get it wrong. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Managed services like Google Kubernetes Engine, Azure Kubernetes Services, Amazon EKS and many other cloud providers do all the heavy lifting for you, at much lower cost than self-hosting. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Turnkey services are a good compromise between self-hosted and fully managed Kubernetes. Turnkey providers like Stackpoint manage the master nodes for you, while you run worker nodes on your own machines. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• If you have to host your own cluster,<b><i> kops</i></b> is a mature and widely used tool that can provision and manage production-grade clusters on AWS and Google Cloud. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• You should use managed Kubernetes if you can. This is the best option for most businesses in terms of cost, overhead, and quality. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• If managed services aren’t an option, consider using turnkey services as a good compromise. </span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><br /></span>
<span style="font-family: "georgia" , "times new roman" , serif;">• Don’t self-host your cluster without sound business reasons. If you do self-host, don’t underestimate the engineering time involved for the initial setup and ongoing maintenance overhead.</span><br />
<div>
<br />
#kubernetes #DevOps #Cloudnative #docker #container</div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com6tag:blogger.com,1999:blog-763097243383122769.post-6584229022276067492019-01-25T17:36:00.001+05:302019-01-26T00:37:21.088+05:30Kubernetes || Remove Namespace stuck in terminating state after delete<div dir="ltr" style="text-align: left;" trbidi="on">
Currently, we are getting some issues while deleting the namespace in Kubernetes(AKS). When we run "<i><b>kubectl delete ns</b></i>" command, it got stuck and after sometime, if we abort this it will remain in terminating state forever.<br />
<br />
Below is the kubernetes version we are using-<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.5", GitCommit:"753b2dbc622f5cc417845f0ff8a77f539a4213ea", GitTreeState:"clean", BuildDate:"2018-11-26T14:31:35Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}</code></pre>
Here, we will see how we can use the workaround to remove the stuck namespace.<br />
1. Create test Namespace-<br />
<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl create ns test
namespace/test created
$ kubectl get ns test
NAME STATUS AGE
test Active 45s</code></pre>
2, Try to delete namespace. You will notice that below command got stuck there. I will hit "ctrl+c" to abort and then check status.<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl delete ns test
namespace "test" deleted
^C
$ kubectl get ns test
NAME STATUS AGE
test Terminating 3m</code></pre>
You saw that namespace is still there in terminating state. Now in below steps we will discuss about the workaround.<br />
<span style="color: inherit; font-size: inherit;"><br /></span> 1. Get the json output for above namespace-<br />
<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl get ns test -ojson > test.json
$ cat test.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2019-01-25T11:34:16Z",
"deletionTimestamp": "2019-01-25T11:36:27Z",
"name": "test",
"resourceVersion": "6575638",
"selfLink": "/api/v1/namespaces/test",
"uid": "25e3d87e-2095-11e9-bbb7-36dd4f9e3a95"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"phase": "Terminating"
}
}</code></pre>
2. You saw the "<span style="color: inherit; font-family: monospace , monospace; font-size: inherit; white-space: pre-wrap;">finalizers</span>" object in above json file. Please remove the line with "<span style="color: inherit; font-family: monospace , monospace; font-size: inherit; white-space: pre-wrap;">kubernetes</span>". So, the file will look like below -<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ sed -i "/"kubernetes"/d" test.json && cat test.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2019-01-25T11:34:16Z",
"deletionTimestamp": "2019-01-25T11:36:27Z",
"name": "test",
"resourceVersion": "6575638",
"selfLink": "/api/v1/namespaces/test",
"uid": "25e3d87e-2095-11e9-bbb7-36dd4f9e3a95"
},
"spec": {
"finalizers": [
]
},
"status": {
"phase": "Terminating"
}
}</code></pre>
3. Start the kube proxy using comand "<b><i>kubectl proxy</i></b>"<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl proxy
Starting to serve on 127.0.0.1:8001</code></pre>
4. Now on other terminal run below command-<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ curl -H "Content-Type: application/json" -X PUT --data-binary @test.json http://127.0.0.1:8001/api/v1/namespaces/test/finalize
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "test",
"selfLink": "/api/v1/namespaces/test/finalize",
"uid": "25e3d87e-2095-11e9-bbb7-36dd4f9e3a95",
"resourceVersion": "6577114",
"creationTimestamp": "2019-01-25T11:34:16Z",
"deletionTimestamp": "2019-01-25T11:36:27Z"
},
"spec": {
},
"status": {
"phase": "Terminating"
}</code></pre>
5. Check is namespace has been deleted or not-<br />
<pre style="background: linear-gradient(rgb(255, 255, 255) 0px, rgb(255, 255, 255) 0.75rem, rgb(245, 247, 250) 0.75rem, rgb(245, 247, 250) 2.75rem, rgb(255, 255, 255) 2.75rem, rgb(255, 255, 255) 4rem) 0% 0% / 100% 4rem rgb(255, 255, 255); border-radius: 4px; border: 1px solid rgb(211, 218, 234); box-sizing: border-box; color: #333333; font-family: monospace, monospace; font-size: 14px; line-height: 2rem; margin-bottom: 1.33999rem; overflow-wrap: break-word; overflow: auto; padding: 0.66001rem 9.5px 9.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: monospace, monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">$ kubectl get ns test
Error from server (NotFound): namespaces "test" not found</code></pre>
Here you go!! Its deleted. This is some kind of bug in K8S. I haven't checked if this have been already fixed on higher version.</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com10tag:blogger.com,1999:blog-763097243383122769.post-8916839600324756382019-01-18T20:33:00.000+05:302019-01-18T20:33:11.531+05:30TMUX (part-2) Installation and Basics<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
In the last Article (<a href="https://linuxhelp4u.blogspot.com/2019/01/tmux-terminal-multiplexer-intro-part-1.html" style="font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; text-decoration-line: none;"><span style="color: red;">tmux-Terminal Multiplexer Intro - Part-1</span></a>), we just discussed what is tmux, comparison with terminals and how this can be helpful in our day to day activities.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Today, lets discuss about the Installation and some basics stuff about the tmux.</div>
<div style="text-align: left;">
<br /></div>
<h2 style="text-align: left;">
Installation-</h2>
<div>
So, if you are using mac then install tmux as below:</div>
<div style="text-align: left;">
$ <span style="color: magenta;">brew install tmux </span></div>
<div style="text-align: left;">
<span style="color: magenta;"><br /></span></div>
<div style="text-align: left;">
If using ubuntu then you can install using "apt-get" as below:</div>
<div style="text-align: left;">
$ <span style="color: magenta;">sudo apt-get install -y tmux </span></div>
<div style="text-align: left;">
<span style="color: magenta;"><br /></span></div>
<div style="text-align: left;">
To verify, if the installation is completed successfully by checking the version-</div>
<div style="text-align: left;">
<div>
<span style="color: magenta;"> $ tmux -V</span></div>
<div>
<span style="color: magenta;"> </span> tmux 2.6</div>
<div>
<span style="color: magenta;"><br /></span></div>
<div>
If you want then you can also do the installation using the source code.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Starting tmux:</h3>
<div>
Start tmux just typing using command "tmux":<br />
<span style="color: magenta;"> $ </span><span class="" style="color: magenta;">tmux</span><span style="color: magenta;"> </span><br />
So when you will just hit enter, you'll notice that you will be get landed to another window as show in below screen shot. Yes, you are right, so that will be your workspace where you are going to work. You can do everything here, as you do with your normal terminals.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://1.bp.blogspot.com/-BOetkVQvULQ/XEHeL6pbQ2I/AAAAAAAAE48/sYoZi15ZSvEvvPS6xjkJyBXyilzKwST2wCLcBGAs/s1600/1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="668" data-original-width="1380" height="307" src="https://1.bp.blogspot.com/-BOetkVQvULQ/XEHeL6pbQ2I/AAAAAAAAE48/sYoZi15ZSvEvvPS6xjkJyBXyilzKwST2wCLcBGAs/s640/1.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig-1 tmux terminal(See at the bottom the red highlighted)</td></tr>
</tbody></table>
<br />
To exit this, just type "exit" command and then you will be back to your standard terminal.<br />
<br />
Another thing to notice, if you doing stuff for just a short period, then maybe this is not the best way to work with tmux sessions. Instead, We can create "named sessions", that we can then use later on.<br />
<br />
<h3 style="text-align: left;">
Create Named Sessions:</h3>
</div>
<div>
On a single terminal, we can create multiple sessions by giving them a particular name and then organize them as needed. Now, using below command, I'll create 2 sessions with name "<b>Dev</b>" and "<b>Test</b>". </div>
<div>
<span style="color: magenta;"> $ </span><span class="" style="color: magenta;">tmux</span><span style="color: magenta;"> new-session -s Dev</span></div>
<div>
<span style="color: magenta;"> $ </span><span class="" style="color: magenta;">tmux</span><span style="color: magenta;"> new-session -s Test<br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-r4Ply17_AaA/XEHirOmuwdI/AAAAAAAAE5I/Hr-vYfrt4eAVZ13efUQxQhLo60yVPuyPwCLcBGAs/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="549" data-original-width="1246" height="280" src="https://2.bp.blogspot.com/-r4Ply17_AaA/XEHirOmuwdI/AAAAAAAAE5I/Hr-vYfrt4eAVZ13efUQxQhLo60yVPuyPwCLcBGAs/s640/2.png" width="640" /></a></div>
<div>
<span style="color: magenta;"><br /></span></div>
<div>
For now it may be doesn't seem useful. But what we you want to execute some long running process e.g. any monitoring process or any long DB query and don't want to scare the screen all the time. In these kind of situation, you can take help on tmux feature which helps us to run jobs in background and help us to catch the things latter on. Let's see how we can do this.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Detaching and Attaching the Sessions:</h3>
<div>
Now, lets see how we can detach and then later attach to the same screen. Now, I have two sessions "Dev" and "Test". I am going to run "top" command in "Dev" and monitor the partition in another "Test" Session.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-fMvPBtINQQM/XEHkwp2kiDI/AAAAAAAAE5U/YxivkMCX-mEFC4D7uxI6HhKkXmH3i9u8ACLcBGAs/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="584" data-original-width="1246" height="297" src="https://3.bp.blogspot.com/-fMvPBtINQQM/XEHkwp2kiDI/AAAAAAAAE5U/YxivkMCX-mEFC4D7uxI6HhKkXmH3i9u8ACLcBGAs/s640/3.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Now, we can detach from both sessions using the combination of PREFIX(<b><u><i>Ctrl+b</i></u></b>) followed by "<b><i><u>d</u></i></b>". In below screenshot, I have detached both sessions and now back to the standard terminal.</div>
<div>
On the standard terminal, you list down the active sessions as well.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-F_06FKiTC_I/XEHpRg9125I/AAAAAAAAE5g/eHC6uOdWI9ohLM8iCRqamBwEvSeWKlqGwCLcBGAs/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="572" data-original-width="620" height="590" src="https://2.bp.blogspot.com/-F_06FKiTC_I/XEHpRg9125I/AAAAAAAAE5g/eHC6uOdWI9ohLM8iCRqamBwEvSeWKlqGwCLcBGAs/s640/4.png" width="640" /></a></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Reattaching to Existing Sessions:</h3>
<div>
Now, you know to detach from the session and run the stuff in the background. On the next day lets support if want to see whats going on inside these sessions, then you have flexibility yo reattach to these as shown below:</div>
<div>
<br /></div>
<div>
<span style="color: magenta;"> $ </span><span class="" style="color: magenta;">tmux</span><span style="color: magenta;"> attach -t Dev</span></div>
<div>
<span style="color: magenta;"> $ </span><span class="" style="color: magenta;">tmux</span><span style="color: magenta;"> attach -t Test</span></div>
<div>
<span style="color: magenta;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-OA1HYBsGRBQ/XEHqW5oftsI/AAAAAAAAE5o/9DH2Y97JiA4cWpp1o4ZVBoyTSBwYv7CtQCLcBGAs/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="579" data-original-width="1260" height="294" src="https://4.bp.blogspot.com/-OA1HYBsGRBQ/XEHqW5oftsI/AAAAAAAAE5o/9DH2Y97JiA4cWpp1o4ZVBoyTSBwYv7CtQCLcBGAs/s640/5.png" width="640" /></a></div>
<div>
<span style="color: magenta;"><br /></span></div>
<div>
<br /></div>
<div>
That's all for now. Please try your self and check if this can be useful for you.</div>
</div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-35410357414500425862019-01-11T20:33:00.003+05:302019-01-11T20:40:20.735+05:30tmux-Terminal Multiplexer Intro - Part-1<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
tmux - Everything in one terminal( Mouse-Free Development ;) )</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-LhpGPShyNQI/XDixwLSjUkI/AAAAAAAAE4g/QjQopNO-aW0PRTAFEQ2HbNE24e9hHCE4gCEwYBhgL/s1600/2019-01-11%2B16_07_28-2019-01-11%2B15_15_37-kuldeep%2540DD5B-LX-7173HDJ_%2B%257E.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="833" data-original-width="1600" height="332" src="https://4.bp.blogspot.com/-LhpGPShyNQI/XDixwLSjUkI/AAAAAAAAE4g/QjQopNO-aW0PRTAFEQ2HbNE24e9hHCE4gCEwYBhgL/s640/2019-01-11%2B16_07_28-2019-01-11%2B15_15_37-kuldeep%2540DD5B-LX-7173HDJ_%2B%257E.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<h3 style="text-align: left;">
What is tmux- </h3>
<div>
<div style="text-align: left;">
tmux is a terminal multiplexer. It helps us to use one single terminal/window to launch multiple terminals. e.g. in your first terminal launch tmux and then load top command. After that, you can create another window and load some database CLI console. Now we have two programs running in the same original terminal. An interesting thing is that within the same session, you can switch back and forth these programs.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Nowadays each modern Operating System provides terminals with multitab functionality. its not something new with tmux. But main feature that tmux provides is running more than one programs simultaneous. In tmux, we have a feature called "pane". "Pane" is again a new window inside tmux window. We can have multiple panes which can be arranged in horizontal or vertical. This again helps us to run multiple programs on same screen. And yes, everything without mouse :).</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Below is the example of pane. One single tmux window having 6 pane-</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ri-Z8M6blyc/XDiuJvTK47I/AAAAAAAAE4Q/TQPAFqV9RAsYslr1SSUFIx4Ddz5N413oQCLcBGAs/s1600/2019-01-11%2B15_52_31-kuldeep%2540DD5B-LX-7173HDJ_%2B%257E.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="835" data-original-width="1600" height="332" src="https://1.bp.blogspot.com/-ri-Z8M6blyc/XDiuJvTK47I/AAAAAAAAE4Q/TQPAFqV9RAsYslr1SSUFIx4Ddz5N413oQCLcBGAs/s640/2019-01-11%2B15_52_31-kuldeep%2540DD5B-LX-7173HDJ_%2B%257E.png" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
</div>
Another interesting thing about the tmux is that you can detach from the current session. This will help us to keep the long process running in the background. This will be a bit familiar to the guys who have used "GNU-screen" already. tmux is a bit similar to GNU-screen, but it provides many more features without any complex configuration. I think which makes it really cool and fun to work with. Along with this tmux has a client-server model. So everything can be controlled from one central location.<br />
<br />
In the next article, we will discuss the Installation and basic usages of tmux to start with. So subscribe and keep visiting.</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-23729908358720457512018-10-10T18:14:00.003+05:302018-10-10T18:19:44.471+05:30How to change data directory for Docker with systemd<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
How to change the data directory for Docker with systemd ?</h2>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-lS_W3DpPWVY/W731MANoSiI/AAAAAAAAElU/Fe-o9YRWxTAXNpBE8rEYaJSxn6B46D-FwCLcBGAs/s1600/2018-10-10%2B14_48_14-Windows%2BDefault%2BLock%2BScreen.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="470" data-original-width="560" height="167" src="https://1.bp.blogspot.com/-lS_W3DpPWVY/W731MANoSiI/AAAAAAAAElU/Fe-o9YRWxTAXNpBE8rEYaJSxn6B46D-FwCLcBGAs/s200/2018-10-10%2B14_48_14-Windows%2BDefault%2BLock%2BScreen.png" width="200" /></a></div>
<br />
Recently I was playing with docker and got the issue with system space utilization which got full when I tried to pull some new images form docker hub. The reason was that partition was full where docker was storing all data including images.<br />
<br />
Usually, By default docker store its all data in /var/ partition which is usually will be in root"/" partition or have can have the separate partition. In my case that was in root "/" partition. So I thought of moving this data directory to somewhere else. Moving this directly to non OS or non-default partition will be a good habit as it will not harm data if something goes wrong with the system.<br />
<br />
<h3 style="text-align: left;">
<span style="font-weight: normal;">You have different option to do this -</span></h3>
1. Use "--graph=/data/docker/data" in systemd file i.e. "/usr/lib/systemd/system/docker.service" as below -<br />
<br />
<i>ExecStart=/usr/bin/dockerd --graph="/data/docker/data"</i><br />
<br />
2. Create daemon.json file with below content-<br />
<br />
# cat /etc/docker/daemon.json<br />
{<br />
..<br />
"graph": "/data/docker/data"<br />
..<br />
}<br />
<br />
<h4 style="text-align: left;">
Other Useful hacks -</h4>
<div>
Full Information about docker service -</div>
<div>
<div>
# systemctl show docker </div>
<div>
Type=notify</div>
<div>
Restart=on-failure</div>
<div>
NotifyAccess=main</div>
<div>
RestartUSec=100ms</div>
<div>
TimeoutStartUSec=infinity</div>
<div>
TimeoutStopUSec=1min 30s</div>
<div>
RuntimeMaxUSec=infinity</div>
<div>
WatchdogUSec=0</div>
<div>
WatchdogTimestamp=Wed 2018-10-10 18:06:50 IST</div>
<div>
WatchdogTimestampMonotonic=6232790274</div>
<div>
FailureAction=none</div>
<div>
PermissionsStartOnly=no</div>
<div>
RootDirectoryStartOnly=no</div>
<div>
RemainAfterExit=no</div>
<div>
GuessMainPID=yes</div>
<div>
MainPID=6076</div>
<div>
ControlPID=0</div>
<div>
FileDescriptorStoreMax=0</div>
<div>
NFileDescriptorStore=0</div>
<div>
StatusErrno=0</div>
<div>
Result=success</div>
<div>
ExecMainStartTimestamp=Wed 2018-10-10 18:06:48 IST</div>
<div>
ExecMainStartTimestampMonotonic=6231265813</div>
<div>
ExecMainExitTimestampMonotonic=0</div>
</div>
<div>
.</div>
<div>
.</div>
<div>
.</div>
<div>
<br /></div>
More detailed info on <a href="https://docs.docker.com/v1.12/engine/admin/systemd/#/custom-docker-daemon-options">official site</a> .<br />
<br />
Happy Learning !!<br />
<br />
<br /></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com2tag:blogger.com,1999:blog-763097243383122769.post-54748497981815240852018-08-15T17:57:00.002+05:302018-08-15T19:41:09.394+05:30Push Docker Images to Azure Container Registry (ACR)<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
How to Push you custom Docker Images to Azure Container Registry?</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-bZGM2n2kRNA/W3Po2T4p5-I/AAAAAAAAD6Y/ZWDnpzhpfbMsDcjhFbTiJWJqEy8EAbzQQCLcBGAs/s1600/build-a-docker-swarm-cluster-on-azure-1-638.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="359" data-original-width="638" height="225" src="https://1.bp.blogspot.com/-bZGM2n2kRNA/W3Po2T4p5-I/AAAAAAAAD6Y/ZWDnpzhpfbMsDcjhFbTiJWJqEy8EAbzQQCLcBGAs/s400/build-a-docker-swarm-cluster-on-azure-1-638.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
In this post, We will be going to see that how we can tag and push our custom docker images to ACR i.e. Azure Container Registry. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h3 style="clear: both; text-align: left;">
Azure CLI</h3>
<div class="separator" style="clear: both; text-align: left;">
We are going to use Azure CLI during whole setup. So make sure you have Azure CLI installed and you are able to run "az" command. You can check your CLI version using |<i>az --version</i>| as below-</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-acGtvjwytUA/W3PrBYQoU9I/AAAAAAAAD6k/hvUJCXzQWjwCvbRL8OvhQm98jKFqi_N_gCLcBGAs/s1600/2018-08-15%2B10_56_38-Select%2BAdministrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="51" data-original-width="253" height="78" src="https://4.bp.blogspot.com/-acGtvjwytUA/W3PrBYQoU9I/AAAAAAAAD6k/hvUJCXzQWjwCvbRL8OvhQm98jKFqi_N_gCLcBGAs/s400/2018-08-15%2B10_56_38-Select%2BAdministrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
If you don't have installed. you can download and install it from |https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest|.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<blockquote class="tr_bq" style="clear: both; text-align: left;">
<i>Note - I am assuming here that -</i><br />
<ul style="text-align: left;">
<li><i>you have already logged in with Azure CLI. If you haven't, then please do that using |az login|.</i></li>
</ul>
<ul style="text-align: left;">
<li><i>You have already created ACR in specific Resource Group. If not, then do that using |az group create [OPTIONS]|.</i></li>
</ul>
</blockquote>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h3 style="clear: both; text-align: left;">
Login to Azure Container Registry-</h3>
<div class="separator" style="clear: both; text-align: left;">
Fetch name of ACR using command |az acr list -g {group_name} -o table|.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-0Wl_yXWVYSQ/W3QSlYFj02I/AAAAAAAAD6w/gaDoHxFwtXMoPMIw40zYkTQvTafNi9hcwCLcBGAs/s1600/2018-08-15%2B13_43_26-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="131" data-original-width="1338" height="60" src="https://4.bp.blogspot.com/-0Wl_yXWVYSQ/W3QSlYFj02I/AAAAAAAAD6w/gaDoHxFwtXMoPMIw40zYkTQvTafNi9hcwCLcBGAs/s640/2018-08-15%2B13_43_26-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Then, use command |az acr login --name [Registry Name]| to log in to your Azure Container Registry:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-DWwTh81-MM4/W3QZzMecYLI/AAAAAAAAD7o/GMX8IWNtWyoWiWxVCW2lqt6Lr3Nfipw1gCLcBGAs/s1600/2018-08-15%2B14_15_53-Blogger_%2BLinux%252C%2BDevOps%252C%2BMiddleware%2Band%2BCloud%2B-%2BCreate%2Bpost.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="57" data-original-width="858" height="42" src="https://3.bp.blogspot.com/-DWwTh81-MM4/W3QZzMecYLI/AAAAAAAAD7o/GMX8IWNtWyoWiWxVCW2lqt6Lr3Nfipw1gCLcBGAs/s640/2018-08-15%2B14_15_53-Blogger_%2BLinux%252C%2BDevOps%252C%2BMiddleware%2Band%2BCloud%2B-%2BCreate%2Bpost.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h3 style="clear: both; text-align: left;">
Tag your Docker Image-</h3>
<div>
One important thing here, if want to push docker image to registry then that should be tagged with registry name or here with loginServer name of registry. Actually these tags will be used for routing when we push these tagged images to registry.</div>
<div>
<br /></div>
<div>
So, lets find out the loginServer name for Azure Container Registry. Use below command for the same -</div>
<div>
<br /></div>
<div>
| az acr list -g [Group Name] --query "[].{acrLoginServer:loginServer}" -o table|</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-_KCgn7p5DjQ/W3QV-6uzVII/AAAAAAAAD7E/rxrpCU7tyLgc8EY1MG7Yw49tBvrgGCLtQCLcBGAs/s1600/2018-08-15%2B13_59_28-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="115" data-original-width="945" height="75" src="https://3.bp.blogspot.com/-_KCgn7p5DjQ/W3QV-6uzVII/AAAAAAAAD7E/rxrpCU7tyLgc8EY1MG7Yw49tBvrgGCLtQCLcBGAs/s640/2018-08-15%2B13_59_28-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div>
<br /></div>
<div>
Now, we'll tag the one of the available image and then will push that to azure container registry.</div>
<div>
<br /></div>
<h4 style="text-align: left;">
List of Current Images -</h4>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/--Ri7I_7eFz0/W3QXFVGcw7I/AAAAAAAAD7M/oZtUBQ7v8jEZPaItrjR9wt7WrcDZcvcXQCLcBGAs/s1600/2018-08-15%2B14_03_08-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="86" data-original-width="1452" height="35" src="https://2.bp.blogspot.com/--Ri7I_7eFz0/W3QXFVGcw7I/AAAAAAAAD7M/oZtUBQ7v8jEZPaItrjR9wt7WrcDZcvcXQCLcBGAs/s640/2018-08-15%2B14_03_08-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div>
<br /></div>
<h4 style="text-align: left;">
Tag Image with ID |7b46b9b6f72a| -</h4>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-bz3l39eTfLA/W3QXTmTQypI/AAAAAAAAD7Q/Fsve2bv1poAuolr7S2hU0VwznD5TAGCcACLcBGAs/s1600/2018-08-15%2B14_04_57-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="54" data-original-width="798" height="42" src="https://4.bp.blogspot.com/-bz3l39eTfLA/W3QXTmTQypI/AAAAAAAAD7Q/Fsve2bv1poAuolr7S2hU0VwznD5TAGCcACLcBGAs/s640/2018-08-15%2B14_04_57-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div>
<br /></div>
<h4 style="text-align: left;">
List Images again-</h4>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-2mcEdTRN5BQ/W3QXqWq7_PI/AAAAAAAAD7c/fZ-V0Rwr_Bkb7Xx7C9i5iLBPWs2JjHuWwCLcBGAs/s1600/2018-08-15%2B14_07_11-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="148" data-original-width="1405" height="66" src="https://4.bp.blogspot.com/-2mcEdTRN5BQ/W3QXqWq7_PI/AAAAAAAAD7c/fZ-V0Rwr_Bkb7Xx7C9i5iLBPWs2JjHuWwCLcBGAs/s640/2018-08-15%2B14_07_11-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div>
<br /></div>
<div>
You can see new image tagged starting with the same name as ACR registry. Now lets push this image to ACR.<br />
<br />
<h4 style="text-align: left;">
Push Image to ACR</h4>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-IHpNRWywPLw/W3QaCLOGx7I/AAAAAAAAD7s/m7GJK5iHb1MhqcDsU8aui_SNQmfOdQXEACLcBGAs/s1600/2018-08-15%2B14_17_45-MINGW64__c_Users_kuldeep.d.sharma_test.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="149" data-original-width="820" height="116" src="https://2.bp.blogspot.com/-IHpNRWywPLw/W3QaCLOGx7I/AAAAAAAAD7s/m7GJK5iHb1MhqcDsU8aui_SNQmfOdQXEACLcBGAs/s640/2018-08-15%2B14_17_45-MINGW64__c_Users_kuldeep.d.sharma_test.png" width="640" /></a></div>
<div>
</div>
<div>
Check if Images have been uploaded successfully to ACR-</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-V2Bi90sztxI/W3QbgZTYySI/AAAAAAAAD78/aAJHhOEvWx8Ymzh2VriG0CGzO8hvFWQkACLcBGAs/s1600/2018-08-15%2B14_22_54-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="265" data-original-width="841" height="200" src="https://1.bp.blogspot.com/-V2Bi90sztxI/W3QbgZTYySI/AAAAAAAAD78/aAJHhOEvWx8Ymzh2VriG0CGzO8hvFWQkACLcBGAs/s640/2018-08-15%2B14_22_54-Administrator_%2Bc__windows_system32_windowspowershell_v1.0_powershell.exe.png" width="640" /></a></div>
<div>
<br /></div>
<div>
You can note down the highlighted one that we pushed before and it is there in ACR. Of course, You can verify this all from Azure Portal as well.</div>
<div>
<br /></div>
<div>
That\s all for now. Happy Learning :)!!</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com5tag:blogger.com,1999:blog-763097243383122769.post-1397225288910975342018-07-26T16:28:00.001+05:302018-07-26T17:13:03.176+05:30Site Reliability Engineering Cookbook<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe src="https://drive.google.com/file/d/1x4-T9d_kx76sUmHQokEih2GRgRTnySFw/preview" width="640" height="480"></iframe></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com1tag:blogger.com,1999:blog-763097243383122769.post-6621117900072668572018-04-30T14:46:00.002+05:302018-04-30T14:51:37.595+05:30Minikube - How to set up local kubernetes cluster<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Question - How to setup local kubernetes cluster using minikube?</h2>
First of all lets describe briefly about "What is kubernetes?". Well, Kubernetes is open-source container orchestration tool which is used for deployments automation and scaling of containers on large scale environments. There are plenty of other features that it can do. Please go to the main site (https://kubernetes.io/) to explore more.<br />
<br />
In this specific post, we'll try to setup full kubernetes cluster on local machine. This should be used on Production like env, this is only for doing local testing and getting test of kubernetes on local server without investing much.<br />
We will make use of "minikube" for this setup. Below is the "minikube" Architecture.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-3UWNODEJAlE/Wty_rQwXCjI/AAAAAAAADvk/srjSzC_hH8QQE5ZMi-r9So1ji4fWIv-AwCLcBGAs/s1600/2018-04-22%2B22_28_09-Introduction%2Bto%2BMinikube%2B%2528run%2BKubernetes%2Blocally%2B%2529.png" imageanchor="1"><img border="0" data-original-height="724" data-original-width="1357" height="339" src="https://3.bp.blogspot.com/-3UWNODEJAlE/Wty_rQwXCjI/AAAAAAAADvk/srjSzC_hH8QQE5ZMi-r9So1ji4fWIv-AwCLcBGAs/s400/2018-04-22%2B22_28_09-Introduction%2Bto%2BMinikube%2B%2528run%2BKubernetes%2Blocally%2B%2529.png" width="640" /></a></div>
<br />
<h3 style="text-align: left;">
Env and Version Details -</h3>
- Host OS - Windows 10<br />
- Hypervisor - Vritualbox<br />
<br />
<h3 style="text-align: left;">
Requirements -</h3>
<h4 style="text-align: left;">
1. Hypervisor - </h4>
<div style="text-align: left;">
Install some kind of hypervisor that minikube will use to create VM and spin up kubernetes cluster on one server.</div>
So, if you don't have, then please install. Below are the options for different distros-<br />
<div style="background: none; border: 0px; box-sizing: border-box; letter-spacing: 0.1px; line-height: 1.75em; text-align: left;">
If you do not already have a hypervisor installed, install one now.<br />
- For OS X, install <a href="https://www.virtualbox.org/wiki/Downloads" style="background: none; border: 0px; box-sizing: border-box; margin: 0px;">VirtualBox</a> or <a href="https://www.vmware.com/products/fusion" style="background: none; border: 0px; box-sizing: border-box; margin: 0px;">VMware Fusion</a>, or <a href="https://github.com/moby/hyperkit" style="background: none; border: 0px; box-sizing: border-box; margin: 0px;">HyperKit</a>.<br />
- For Linux, install <a href="https://www.virtualbox.org/wiki/Downloads" style="background: none; border: 0px; box-sizing: border-box; margin: 0px;">VirtualBox</a> or <a href="http://www.linux-kvm.org/" style="background: none; border: 0px; box-sizing: border-box; margin: 0px;">KVM</a>.</div>
<div style="background: none; border: 0px; box-sizing: border-box; letter-spacing: 0.1px; line-height: 1.75em; text-align: left;">
<span style="background-color: white; letter-spacing: 0.1px;"> - </span><span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">For Windows, install </span><a href="https://www.virtualbox.org/wiki/Downloads" style="background: none rgb(255, 255, 255); border: 0px; box-sizing: border-box; font-family: Roboto, sans-serif; font-size: 16px; letter-spacing: 0.1px; margin: 0px;">VirtualBox</a><span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"> or </span><a href="https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/quick_start/walkthrough_install" style="background: none rgb(255, 255, 255); border: 0px; box-sizing: border-box; font-family: Roboto, sans-serif; font-size: 16px; letter-spacing: 0.1px; margin: 0px;">Hyper-V</a></div>
<div style="background: none; border: 0px; box-sizing: border-box; letter-spacing: 0.1px; line-height: 1.75em; text-align: left;">
<strong style="background: none rgb(255, 255, 255); border: 0px; box-sizing: border-box; font-family: Roboto, sans-serif; font-size: 16px; letter-spacing: 0.1px; margin: 0px;">Note:</strong><span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"> Minikube has support which provides us option to define which HyperVisor we want to use. Parameter is </span><code class="highlighter-rouge" style="background: none rgb(247, 247, 247); border: 0px; box-sizing: border-box; color: #303030; display: inline-block; font-family: "Roboto Mono", monospace; font-size: 14px; font-weight: bold; letter-spacing: 0.1px; margin: 0px; padding: 2px 4px; vertical-align: baseline;">--vm-driver={Value}</code><span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">. If you want to install this on same host instead of any VM, please use </span><span style="background-color: #f7f7f7; color: #303030; font-family: "roboto mono" , monospace; font-size: 14px; font-weight: 700; letter-spacing: 0.1px;">--vm-driver=none. </span><span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">Docker is needed for this, but you don't need a hypervisor.</span></div>
<h4 style="background: none; border: 0px; box-sizing: border-box; letter-spacing: 0.1px; line-height: 1.75em; text-align: left;">
<span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">2. Install kubernetes controller i.e. kubectl -</span></h4>
<div>
<span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"> "kubectl" is command line tool which is used to manage and deploy deployments on kubernetes. There are different of ways to do this based on different OS. Since we are doing this on windows, so for windows you either can use "chocolatey" package manager or simply download using curl or from browser and set that exeutable to PATH variable.</span><br />
<span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"><br /></span> <span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">e.g. </span><br />
<pre class="highlight" style="background: rgb(247, 247, 247); border: 0px; box-sizing: border-box; color: #222222; font-family: Roboto, sans-serif; font-size: 16px; margin-bottom: 20px; margin-top: 20px; overflow-x: auto; padding: 15px; position: relative;"><code style="background-attachment: initial; background-clip: initial; background-image: none; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; box-sizing: border-box; color: #303030; display: inline-block; font-family: "Roboto Mono", monospace; font-size: 14px; font-weight: bold; margin: 0px; padding: 0px; vertical-align: baseline;">curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/windows/amd64/kubectl.exe</code></pre>
<span style="background-color: white; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"><b><i> Check below for stable version -</i></b></span><br />
<a href="https://storage.googleapis.com/kubernetes-release/release/stable.txt" style="background: none rgb(255, 255, 255); border: 0px; box-sizing: border-box; color: #222222; font-family: Roboto, sans-serif; font-size: 16px; letter-spacing: 0.1px; margin: 0px;">https://storage.googleapis.com/kubernetes-release/release/stable.txt</a><span style="background-color: white; color: #222222; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;">.</span><br />
<span style="background-color: white; color: #222222; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"><br /></span><span style="background-color: white; color: #222222; font-family: "roboto" , sans-serif; font-size: 16px; letter-spacing: 0.1px;"><b><i> Check for version -</i></b></span><br />
<blockquote class="tr_bq">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;">>kubectl version --client</span></span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;">Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.2", GitCommit:"bdaeafa71f6c7c04636251031f93464384d54963", GitTreeState:"clean", BuildDate:"2017-10-24T19:48:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"windows/amd64"}</span></span></blockquote>
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="background-color: white; letter-spacing: 0.1px;"></span></span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"><br /></span></span>
<br />
<h4 style="text-align: left;">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"><b>3. Install Minikube -</b></span></span></h4>
<div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"> Download particular version from "https://github.com/kubernetes/minikube/releases" and move binary to system PATH in same as you did for kubectl.</span></span></div>
<div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"><br /></span></span></div>
<div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"> check minikube version and start your local kubernetes cluster using virtualbox.</span></span></div>
<div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"><br /></span></span></div>
<div style="text-align: left;">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;"><b>- Check Version :</b></span></span></div>
<div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"></span><br />
<blockquote class="tr_bq" style="letter-spacing: 0.1px;">
<span style="color: #222222; font-family: "roboto" , sans-serif;">> minikube version</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">minikube version: v0.23.0</span></blockquote>
<span style="color: #222222; font-family: "roboto" , sans-serif;"> </span><br />
<div style="letter-spacing: 0.1px;">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><b>- Start :</b></span></div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"> </span><br />
<div>
<blockquote class="tr_bq" style="letter-spacing: 0.1px;">
<span style="color: #222222; font-family: "roboto" , sans-serif;">> minikube start --vm-driver virtualbox</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Starting local Kubernetes v1.8.0 cluster...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Starting VM...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Getting VM IP address...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Moving files into cluster...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Setting up certs...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Connecting to cluster...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Setting up kubeconfig...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Starting cluster components...</span><br />
<span style="color: #222222; font-family: "roboto" , sans-serif;">Kubectl is now configured to use the cluster.</span></blockquote>
<div style="letter-spacing: 0.1px;">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><b>- Chech status :</b></span></div>
<div>
<blockquote class="tr_bq">
<span style="color: #222222; font-family: "roboto" , sans-serif;"><span style="letter-spacing: 0.1px;">>minikube status</span><span style="letter-spacing: 0.1px;">minikube: Running</span><span style="letter-spacing: 0.1px;">cluster: Running</span><span style="letter-spacing: 0.1px;">kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100</span></span></blockquote>
</div>
</div>
<span style="color: #222222; font-family: "roboto" , sans-serif;"> <div style="letter-spacing: 0.1px;">
<b>- Get Cluster info:</b></div>
<div>
<blockquote class="tr_bq" style="letter-spacing: 0.1px;">
>kubectl cluster-info<br />
Kubernetes master is running at https://192.168.99.100:8443</blockquote>
<div style="letter-spacing: 0.1px;">
<br /></div>
<div style="letter-spacing: 0.1px;">
<b>- Other kubectl handy commands:</b></div>
<div>
<blockquote>
>kubectl get po<br />
NAME READY STATUS RESTARTS AGE<br />
nginx-node-d747bd6df-prrpb 1/1 Running 1 18h<br />
<br />
>kubectl get services<br />
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<br />
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 7d<br />
nginx-node LoadBalancer 10.0.0.68 <pending> 80:32033/TCP 7d<br />
<br />
>kubectl get deployment<br />
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE<br />
nginx-node 1 1 1 1 7d<br />
<br />
>kubectl get all<br />
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE<br />
deploy/nginx-node 1 1 1 1 7d<br />
<br />
NAME DESIRED CURRENT READY AGE<br />
rs/nginx-node-d747bd6df 1 1 1 7d<br />
<br />
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE<br />
deploy/nginx-node 1 1 1 1 7d<br />
<br />
NAME DESIRED CURRENT READY AGE<br />
rs/nginx-node-d747bd6df 1 1 1 7d<br />
<br />
NAME READY STATUS RESTARTS AGE<br />
po/nginx-node-d747bd6df-prrpb 1/1 Running 1 18h<br />
<br />
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<br />
svc/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 7d<br />
svc/nginx-node LoadBalancer 10.0.0.68 <pending> 80:32033/TCP 7d</blockquote>
</div>
</div>
</span></div>
</div>
<div style="background: none; border: 0px; box-sizing: border-box; letter-spacing: 0.1px; line-height: 1.75em; text-align: left;">
<br /></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com7tag:blogger.com,1999:blog-763097243383122769.post-48910158800554768062018-03-31T13:52:00.000+05:302020-02-27T15:16:14.890+05:30How to Clean or Reset build numbers in Jenkins job ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
When you were working with some POC or R&D, you may have to do things a number of times until you come to final conclusion. In my recent POC, I was working with Jenkins build jobs for Azure container registry with Azure Managed Container services aka AKS.<br />
<br />
During this whole activity I have created 70 plus builds and during this process each build was creating one separate tag for docker image on ACR. When this whole POC gets completed, I thought that it will be really good idea to flush/clear out build history and start building from scratch.<br />
<br />
Situation after completing POC-<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-DiCkzs65JIw/Wr9BneRIUYI/AAAAAAAADuU/HtNFms0gUNszvPdSTXvqHcYu-1bC6roAACLcBGAs/s1600/2018-03-31%2B13_04_18-Cortana.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="674" data-original-width="446" height="640" src="https://3.bp.blogspot.com/-DiCkzs65JIw/Wr9BneRIUYI/AAAAAAAADuU/HtNFms0gUNszvPdSTXvqHcYu-1bC6roAACLcBGAs/s640/2018-03-31%2B13_04_18-Cortana.png" width="420" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
Below are the step by step instructions for the same-<br />
<br />
<ul style="text-align: left;">
<li>Login to Jenkins server, click on " Manage Jenkins" --> "Script Console". This will open below dialog box.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-qP8XBBXLGJU/Wr9BnlZ8VgI/AAAAAAAADu0/zxCkGkbpQ1EYKfNbFDRLBX3odJWYMe9owCEwYBhgL/s1600/2018-03-31%2B13_05_16-Settings.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="748" data-original-width="1592" height="300" src="https://3.bp.blogspot.com/-qP8XBBXLGJU/Wr9BnlZ8VgI/AAAAAAAADu0/zxCkGkbpQ1EYKfNbFDRLBX3odJWYMe9owCEwYBhgL/s640/2018-03-31%2B13_05_16-Settings.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: left;">
<ul style="text-align: left;">
<li>Once you click on "Script Console", then copy and paste below script there and run.</li>
</ul>
<div>
Note - Make sure to change the "Job Name"</div>
<div>
</div>
</div>
<br />
<blockquote class="tr_bq" style="background-color: #fefefe; color: #555555; font-size: 15px; padding: 0px;">
def jobName = "Enter Job Name"<br />
def job = Jenkins.instance.getItem(jobName)<br />
job.getBuilds().each { it.delete() }<br />
job.nextBuildNumber = 1<br />
job.save()</blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-rv3awE8i0lY/Wr9BnuboeTI/AAAAAAAADuw/lQ76C9zvsxs-DrKAwSTT-Hom0VLqbJzvwCEwYBhgL/s1600/2018-03-31%2B13_06_38-Settings.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="561" data-original-width="1273" height="281" src="https://4.bp.blogspot.com/-rv3awE8i0lY/Wr9BnuboeTI/AAAAAAAADuw/lQ76C9zvsxs-DrKAwSTT-Hom0VLqbJzvwCEwYBhgL/s640/2018-03-31%2B13_06_38-Settings.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul style="text-align: left;">
<li>Check again for build history. You'll notice that everything got flashed.</li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-gfLT74PzQZ8/Wr9BosKTWwI/AAAAAAAADu4/RyIloau7pd4oTxp3pKxgO7HUAz8lzoEVACEwYBhgL/s1600/2018-03-31%2B13_08_19-Start.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="657" data-original-width="850" height="492" src="https://3.bp.blogspot.com/-gfLT74PzQZ8/Wr9BosKTWwI/AAAAAAAADu4/RyIloau7pd4oTxp3pKxgO7HUAz8lzoEVACEwYBhgL/s640/2018-03-31%2B13_08_19-Start.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul style="text-align: left;">
<li>Try to build job again and notice the change in Build number.</li>
</ul>
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-NrNRUzinlXA/Wr9Bo9BB83I/AAAAAAAADu4/sTIw6fkL2NQVDeQTO3WWcFGGhExjgEcgACEwYBhgL/s1600/2018-03-31%2B13_08_54-Start.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="623" data-original-width="930" height="267" src="https://1.bp.blogspot.com/-NrNRUzinlXA/Wr9Bo9BB83I/AAAAAAAADu4/sTIw6fkL2NQVDeQTO3WWcFGGhExjgEcgACEwYBhgL/s400/2018-03-31%2B13_08_54-Start.png" width="400" /></a></div>
<div>
<br />
<ul style="text-align: left;">
<li>One more thing would like to highlight. Let's support you have stable version at build number 90 and then you did some poc. During your poc you created some more builds which are just trash and you want to remove those build and would like to start new stable build with build_number 91. Please use below snippet for this -</li>
</ul>
<br />
<blockquote class="tr_bq">
<i>def jobName = "JOB NAME"<br />def job = Jenkins.instance.getItem(jobName)<br />job.nextBuildNumber = 91<br />job.save()</i></blockquote>
</div>
<div>
<br />
<br />
Hope this will help !!</div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-64722143188836915942018-01-15T00:48:00.001+05:302018-01-15T00:48:43.877+05:30Dictionaries in Python<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Guys,<br />
<br />
In this particular post, I am going to discuss dictionaries in python. The example in this post is tested on Python-3.6.<br />
<br />
<span style="background-color: white; color: #222222; font-family: sans-serif; font-size: 14px;"> Python data structures include lists, dictionaries, tuples, and sets.</span> If you have worked with python, then you may have worked on "lists", "tuples", "sets" and "dictionary" in python.<br />
<br />
<b><u><i>Dictionary</i></u></b> - As the name suggests dictionary is the same as that ordinary dictionary where we will have index and then we'll use that index to search the specific entry. This is similar to book or phonebook index where we search things using names instead of values which we do in other python data structure. Dictionary worked in "key":"value" pair. The "word" is called <b style="font-style: italic;">key </b>and the definition of "word" is called a <b><i>value</i></b>.<br />
<div style="text-align: left;">
Usually, the "values" or "keys" of a dictionary are not in specific order. Another import thing is that we can't sort a dictionary in python, but can make use of the list to sort dictionaries. We will this in the example. Apart from this, we can do all add, remove and modify operations on python dictionary.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Let's go through below given example and see the basic usages in practical-</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
Code(you can see this on <a href="https://github.com/deepforu47/DevOps/blob/master/python/dictionary.py">github</a> as well)</h3>
<div>
<i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;">==========================================================================</span></i></div>
<div>
<i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;"><br /></span></i></div>
<div style="text-align: left;">
<span style="font-family: Times, Times New Roman, serif;"><i>print ("\n Lets Play with Dictionary: ")</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#Lets make a phone book:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#Define an empty dictionary</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>ages = {}</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#Add few names to the dictionary</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['Sam'] = 87</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['Vik'] = 28</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['Vishu'] = 54</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['ND'] = 45</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['Bunti'] = 37</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i># Display current Dictionary</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print("*** Current Dictionary is :\t", ages)</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#Use IN operator to check if specifid key is there in Dictionary. Syntax will be of this form:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#" if <value> in <dictionary> "</dictionary></value></i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#this will returns TRUE, if the dictionary has key-name in it</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#but returns FALSE if it doesn't. for key, value in ages.items():</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>if "Sam" in ages:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i> print ("\nSam is in the dictionary. He is", \</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages['Sam'], "years old")</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>else:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i> print ("\nSam is not in the dictionary")</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#Use the function keys() -</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#This function returns a list of all the names of the keys.</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#E.g.</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>print ("\nThe following guys are in the dictionary:\t", \</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages.keys())</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#You could use this "keys" function to put all the key names in a list:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>keys = ages.keys()</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#You can also get a list of all the values in a dictionary.</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#You use the values() function:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("People are aged the following:\t", \</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>ages.values())</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#Now put all values i.e. ages associated with each guy in a list:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>values = ages.values()</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#You can sort lists, with the sorted() function. </i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#It will sort all values in a list. alphabetically, numerically, etc...</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>#You can't sort dictionaries -they are in no particular order</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("\nUnsorted Keys:\t", keys)</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("Sorted Keys for Dictionary:\t", sorted(keys))</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("\nUnsorted Values:\t", values)</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("Sorted Values for Dictionary:\t", sorted(values))</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i><br /></i></span>
<span style="font-family: Times, Times New Roman, serif;"><i>#You can find the number of entries with the len() function:</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>print ("\nThe dictionary has", \</i></span><br />
<span style="font-family: Times, Times New Roman, serif;"><i>len(ages), "entries in it")</i></span><br />
<div style="text-align: left;">
<i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;">==========================================================================</span></i></div>
<div style="text-align: left;">
<i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;"><br /></span></i></div>
<div style="text-align: left;">
<span style="font-size: 12px;"><b><i>Output</i></b></span></div>
<div style="text-align: left;">
<span style="font-size: 12px;"><b><i>=====</i></b></span></div>
<i><b style="font-size: 12px;"> </b><span style="font-family: Times, Times New Roman, serif;">Lets Play with Dictionary:</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;">*** Current Dictionary is : {'Sam': 87, 'Vik': 28, 'Vishu': 54, 'ND': 45, 'Bunti': 37}</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;"><br /></span></i>
<i><span style="font-family: Times, Times New Roman, serif;">Sam is in the dictionary. He is 87 years old</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;"><br /></span></i>
<i><span style="font-family: Times, Times New Roman, serif;">The following guys are in the dictionary: dict_keys(['Sam', 'Vik', 'Vishu', 'ND', 'Bunti'])</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;">People are aged the following: dict_values([87, 28, 54, 45, 37])</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;"><br /></span></i>
<i><span style="font-family: Times, Times New Roman, serif;">Unsorted Keys: dict_keys(['Sam', 'Vik', 'Vishu', 'ND', 'Bunti'])</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;">Sorted Keys for Dictionary: ['Bunti', 'ND', 'Sam', 'Vik', 'Vishu']</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;"><br /></span></i>
<i><span style="font-family: Times, Times New Roman, serif;">Unsorted Values: dict_values([87, 28, 54, 45, 37])</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;">Sorted Values for Dictionary: [28, 37, 45, 54, 87]</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif;"><br /></span></i>
<br />
<i><span style="font-family: Times, Times New Roman, serif;">The dictionary has 5 entries in it</span></i><br />
<i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;"></span></i><br />
<a name='more'></a><i><span style="font-family: Times, Times New Roman, serif; font-size: x-small;">==========================================================================</span></i><br />
<div>
<br /></div>
</div>
<div>
<span style="color: navy;"><br /></span></div>
<div>
<span style="color: navy;"><br /></span></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com1tag:blogger.com,1999:blog-763097243383122769.post-34814671147893076562017-10-20T21:05:00.002+05:302017-12-15T22:21:33.428+05:30How to reset mongodb rootadmin password ??<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-FcTDufsjtG4/WeoL_vswuWI/AAAAAAAABDQ/tuX2EcTUHS0St9fPF_gt7cXocRcDnEMiACLcBGAs/s1600/MongoDB-Logo-5c3a7405a85675366beb3a5ec4c032348c390b3f142f5e6dddf1d78e2df5cb5c.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="435" data-original-width="1600" height="108" src="https://1.bp.blogspot.com/-FcTDufsjtG4/WeoL_vswuWI/AAAAAAAABDQ/tuX2EcTUHS0St9fPF_gt7cXocRcDnEMiACLcBGAs/s400/MongoDB-Logo-5c3a7405a85675366beb3a5ec4c032348c390b3f142f5e6dddf1d78e2df5cb5c.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-Hb4uB6ympLM/WeoLnIfp4uI/AAAAAAAABDI/VeCh7ThA-FMwwJNuSpA0AzgYqRn9gDVsACLcBGAs/s1600/forgot-password-button-png-md.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="64" data-original-width="291" height="43" src="https://4.bp.blogspot.com/-Hb4uB6ympLM/WeoLnIfp4uI/AAAAAAAABDI/VeCh7ThA-FMwwJNuSpA0AzgYqRn9gDVsACLcBGAs/s200/forgot-password-button-png-md.png" width="200" /></a></div>
<br />
Sometimes we have to manage credentials for lots of things and its obvious that we can forget one of them. Here I am going to explain that how we can reset "rootadmin" password for running mongodb replica set.<br />
<br />
I am not going in details about installation, configuration or functionality detail. Instead, I'll directly jump to actual technical hacking stuff. Along with with we'll also learn some sed tricks that can be handy on many occasions.<br />
<br />
<h4 style="text-align: left;">
Things responsible for Authentication/Permissions with in mongodb replica set-</h4>
<div>
<br /></div>
<blockquote class="tr_bq" style="text-align: left;">
security:<br />
keyFile: "/data/mongo3.2/node3/mongo_3.2-keyfile"<br />
authorization: "enabled"</blockquote>
keyFile - This is the path to file that stores the shared secret that all MongoDB instances use to authenticate to each other in a sharded cluster or replica set.<br />
authorization - This will Enable or disable Role-Based Access Control (RBAC) to govern each user’s access to database resources and operations. By default, this will be Disabled<br />
<br />
So, in working env when we forget rootadmin password. By the way "rootadmin" is the user who has all admin level access to perform anything on |admin| and other DBs.<br />
<br />
<blockquote class="tr_bq">
<div style="text-align: left;">
$ mongo -u rootadmin -p secret mongo-server:27017/admin<br />
MongoDB shell version: 3.2.15<br />
connecting to: mongo-server:27017/admin<br />
2017-10-20T13:44:29.431+0200 E QUERY [thread1] Error: Authentication failed. :<br />
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20<br />
@(auth):6:1<br />
@(auth):1:2<br />
exception: login failed</div>
<blockquote>
<br /></blockquote>
</blockquote>
<br />
So, first of all, stop all nodes in MongoDB replica set. Comment out the three line which will be there in your configuration files. Here I am running three instances on the same node so using |<b><i>sed</i></b>| trick to comment and uncomment the multiple config files.<br />
<br />
<h4 style="text-align: left;">
Before making changes -</h4>
<div>
<br /></div>
<div style="text-align: left;">
$ grep -ri -A 1 -B 1 key node?/conf/mongod.conf </div>
<div style="text-align: left;">
node1/conf/mongod.conf-security:</div>
node1/conf/mongod.conf: keyFile: "/data/mongo3.2/node1/mongo_3.2-keyfile"<br />
node1/conf/mongod.conf- authorization: "enabled"<br />
--<br />
node2/conf/mongod.conf-security:<br />
node2/conf/mongod.conf: keyFile: "/data/mongo3.2/node2/mongo_3.2-keyfile"<br />
node2/conf/mongod.conf- authorization: "enabled"<br />
--<br />
node3/conf/mongod.conf-security:<br />
node3/conf/mongod.conf: keyFile: "/data/mongo3.2/node3/mongo_3.2-keyfile"<br />
node3/conf/mongod.conf- authorization: "enabled"<br />
<br />
<blockquote class="tr_bq" style="text-align: left;">
<div style="text-align: left;">
<br /></div>
</blockquote>
<h4 style="text-align: left;">
Comment out the security config parameter(Here I am commenting line number 20-22)-</h4>
<div>
<br /></div>
<div style="text-align: left;">
$ sudo sed -i '20,22 s/^/#/' node?/conf/mongod.conf </div>
<br />
<h4 style="text-align: left;">
Check again after making changes(See the diference # ) -</h4>
<div>
<br /></div>
<div style="text-align: left;">
$ grep -ri -A 1 -B 1 key node?/conf/mongod.conf<br />
node1/conf/mongod.conf-#security:<br />
node1/conf/mongod.conf:# keyFile: "/data/mongo3.2/node1/mongo_3.2-keyfile"<br />
node1/conf/mongod.conf-# authorization: "enabled"<br />
--<br />
node2/conf/mongod.conf-#security:<br />
node2/conf/mongod.conf:# keyFile: "/data/mongo3.2/node2/mongo_3.2-keyfile"<br />
node2/conf/mongod.conf-# authorization: "enabled"<br />
--<br />
node3/conf/mongod.conf-#security:<br />
node3/conf/mongod.conf:# keyFile: "/data/mongo3.2/node3/mongo_3.2-keyfile"<br />
node3/conf/mongod.conf-# authorization: "enabled"</div>
<div style="text-align: left;">
<br /></div>
<h4 style="text-align: left;">
Start all the nodes, and login without the password. </h4>
<div>
<br /></div>
<div style="text-align: left;">
$ mongo mongo-server:27017/admin<br />
MongoDB shell version: 3.2.15<br />
connecting to: mongo-server:27017/admin<br />
Server has startup warnings:<br />
2017-10-20T13:40:19.999+0200 I CONTROL [initandlisten]<br />
MongoDB Enterprise rs0:PRIMARY> show dbs<br />
admin 0.078GB<br />
local 6.075GB<br />
MongoDB Enterprise rs0:PRIMARY> db<br />
admin<br />
MongoDB Enterprise rs0:PRIMARY> db.changeUserPassword("rootadmin","new-password")<br />
MongoDB Enterprise rs0:PRIMARY><br />
bye</div>
<div style="text-align: left;">
<br /></div>
<h4 style="text-align: left;">
Now, Uncomment security stuff again in config file and give restart to all nodes.</h4>
<div style="text-align: left;">
$ sudo sed -i '20,22 s/^#//' node?/conf/mongod.conf<br />
$ grep -ri -A 1 -B 1 key node?/conf/mongod.conf<br />
node1/conf/mongod.conf-security:<br />
node1/conf/mongod.conf: keyFile: "/data/mongo3.2/node1/mongo_3.2-keyfile"<br />
node1/conf/mongod.conf- authorization: "enabled"<br />
--<br />
node2/conf/mongod.conf-security:<br />
node2/conf/mongod.conf: keyFile: "/data/mongo3.2/node2/mongo_3.2-keyfile"<br />
node2/conf/mongod.conf- authorization: "enabled"<br />
--<br />
node3/conf/mongod.conf-security:<br />
node3/conf/mongod.conf: keyFile: "/data/mongo3.2/node3/mongo_3.2-keyfile"<br />
node3/conf/mongod.conf- authorization: "enabled" </div>
<div style="text-align: left;">
<br /></div>
<h4 style="text-align: left;">
After that try to login again using new credentials.</h4>
<blockquote class="tr_bq">
$ mongo -u rootadmin -p new-password mongo-server:27017/admin<br />
MongoDB shell version: 3.2.15<br />
connecting to: mongo-server:27017/admin<br />
Server has startup warnings:<br />
2017-10-20T13:47:30.262+0200 I CONTROL [initandlisten]<br />
MongoDB Enterprise rs0:PRIMARY> show dbs<br />
admin 0.078GB<br />
local 6.075GB<br />
MongoDB Enterprise rs0:PRIMARY> </blockquote>
Note: If you are not using the config file and just passing arguments, then you can stop and then start replica set nodes without these parameters.<br />
<div>
<br /></div>
<br /></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06311497329216665511noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-57701197319553265782016-08-09T16:43:00.003+05:302016-08-09T16:43:44.436+05:30Check dependencies of local RPM package<div dir="ltr" style="text-align: left;" trbidi="on">
We all know that for managing packages or softwares on any system, we need some kind of tool which can be used to manage the packages or softwares. Different distributions have its know tool for achieving the same.<br />
<br />
For example for RHEL/Centos/Fedora we use RPM(RPM Package Manager)<br />
for all rpm package management which take care of "installation, uninstallation, update, query etc.<br />
<a href="https://4.bp.blogspot.com/-c7am7JvKZzQ/V6m1Lg0DDWI/AAAAAAAABP0/MG8VqMXCvronul1khiOJSMv5CmxO6ae7QCLcB/s1600/rpmlogo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-c7am7JvKZzQ/V6m1Lg0DDWI/AAAAAAAABP0/MG8VqMXCvronul1khiOJSMv5CmxO6ae7QCLcB/s1600/rpmlogo.png" imageanchor="1" style="display: inline !important; margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="200" src="https://4.bp.blogspot.com/-c7am7JvKZzQ/V6m1Lg0DDWI/AAAAAAAABP0/MG8VqMXCvronul1khiOJSMv5CmxO6ae7QCLcB/s200/rpmlogo.png" width="200" /></a></div>
So, sometimes whenever we install any package we get lots of error regarding the dependencies. Here we are discussing that how we can list dependencies associated with particular rpm file.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-6tBnSXuWTTk/V6m14A6IXwI/AAAAAAAABP8/p3NC5MAlMvQew1C_3dUwfD3dI2HqJ8W5wCLcB/s1600/dependency.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="120" src="https://3.bp.blogspot.com/-6tBnSXuWTTk/V6m14A6IXwI/AAAAAAAABP8/p3NC5MAlMvQew1C_3dUwfD3dI2HqJ8W5wCLcB/s200/dependency.jpg" width="200" /></a></div>
<br />
1.) Check for file i,e, yet package is not installed:<br />
<strong style="background-color: white; color: #111111; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 16px; line-height: 27px; margin: 0px; padding: 0px; word-wrap: break-word;"> <i>rpm -qpR {rpm-file} </i></strong><br />
<strong style="background-color: white; color: #111111; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 16px; line-height: 27px; margin: 0px; padding: 0px; word-wrap: break-word;">e.g. </strong><a href="https://1.bp.blogspot.com/-00HjpBmUaGg/V6m4eIrIhdI/AAAAAAAABQI/jUJJ9shRbcAidCYZQMNOA1PmfSdFI9XIwCLcB/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img alt="test" border="0" height="193" src="https://1.bp.blogspot.com/-00HjpBmUaGg/V6m4eIrIhdI/AAAAAAAABQI/jUJJ9shRbcAidCYZQMNOA1PmfSdFI9XIwCLcB/s640/1.png" title="" width="640" /></a><br />
-----<br />
-----<br />
output truncated..<br />
2.) If packages is already installed:<br />
<strong style="background-color: white; color: #111111; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 16px; line-height: 27px; margin: 0px; padding: 0px; word-wrap: break-word;"> <i>rpm -qR {package-name}</i></strong><br />
<span style="color: #111111; font-family: Arial, Helvetica Neue, Helvetica, sans-serif;"><span style="background-color: white; line-height: 27px;"><b><i>e.g. :</i></b></span></span><a href="https://2.bp.blogspot.com/-kMob4txJRAI/V6m5Kd2LxGI/AAAAAAAABQQ/9vlhSA3LtZojz0gfBUPBMbclb3W29US8QCLcB/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="171" src="https://2.bp.blogspot.com/-kMob4txJRAI/V6m5Kd2LxGI/AAAAAAAABQQ/9vlhSA3LtZojz0gfBUPBMbclb3W29US8QCLcB/s640/2.png" width="640" /></a><br />
<br />
<span style="color: #111111; font-family: Arial, Helvetica Neue, Helvetica, sans-serif;"><span style="background-color: white; line-height: 27px;"> 3.) Dry run without installing the package:</span></span><br />
<strong style="background-color: white; color: #111111; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 16px; line-height: 27px; margin: 0px; padding: 0px; word-wrap: break-word;"> <i>rpm -Uvh --test {rpm-file}</i></strong><br />
<strong style="background-color: white; color: #111111; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 16px; line-height: 27px; margin: 0px; padding: 0px; word-wrap: break-word;"><i> e.g.:</i></strong><a href="https://4.bp.blogspot.com/-nQiLT7E8WCE/V6m6MXpCHbI/AAAAAAAABQY/Z2RClxvRLyAnJbx8pgAreYqAFMMVt3dHgCLcB/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="191" src="https://4.bp.blogspot.com/-nQiLT7E8WCE/V6m6MXpCHbI/AAAAAAAABQY/Z2RClxvRLyAnJbx8pgAreYqAFMMVt3dHgCLcB/s640/3.png" width="640" /></a><br />
<span style="color: #111111; font-family: Arial, Helvetica Neue, Helvetica, sans-serif;"><span style="background-color: white; line-height: 27px;"><br /></span></span>
<span style="color: #111111; font-family: Arial, Helvetica Neue, Helvetica, sans-serif;"><span style="background-color: white; line-height: 27px;">Finally, yes of course if you don't make these checks and just try to install then you will get list of missing dependencies as well.</span></span></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-49867329356281888242016-04-25T14:26:00.000+05:302016-04-25T14:26:24.782+05:30Remount multiple NFS mount points on Client in one go<div dir="ltr" style="text-align: left;" trbidi="on">
Sometimes we may have number of mount points available on NFS clients and after making changes for any one of parameters, we have to remount all partitions. Doing umount and mount on multiple partitions will really be hectic job and there may be chances of human errors.<br />
<br />
We can do this using single command to achieve the same. Sharing some other commands as well, before moving to exact one :).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-upK2c-nkQWE/Vx3a9mcu7dI/AAAAAAAABOY/hZUeTwQk97AehUQ6XATEjdM2KErHWfeBQCLcB/s1600/nfs-folder-icon.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="154" src="https://4.bp.blogspot.com/-upK2c-nkQWE/Vx3a9mcu7dI/AAAAAAAABOY/hZUeTwQk97AehUQ6XATEjdM2KErHWfeBQCLcB/s200/nfs-folder-icon.png" width="200" /></a></div>
<br />
<h4 style="text-align: left;">
<ul style="text-align: left;">
<li>Get the list of all NFS mount points available on System:</li>
</ul>
<div style="text-align: left;">
<span style="font-weight: normal;">Before moving ahead with changes, lets see how many partitions are their on system. Below command will do trick and give you all the nfs mount points without any header and headers.</span></div>
<ul style="text-align: left;"><ul>
<li>Without headers -</li>
</ul>
</ul>
#<i style="font-weight: normal;">df -PF nfs | awk '{if(NR>1)print}' </i> # This command will suppress header line </h4>
<br />
<ul style="text-align: left;"><ul>
<li><b>With headers-</b></li>
</ul>
</ul>
<b> </b>#<i>df -PF nfs </i><br />
<br />
<ul style="text-align: left;">
<li><i><b>Here goes the actual thing, where we need to mount and remount multiple nfs partitions after making changes to parameters.</b></i></li>
</ul>
<i><b> </b>#for M in $(mount | awk '/type nfs / {print $3;}'); do echo $M; sudo umount $M && sudo mount $M && echo "ok :)"; done</i><br />
<i><br /></i>
<i><br /></i>
<i>[Note: Execute at your own risk after doing testing on test environments ;) ]</i><br />
<i><br /></i></div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com0tag:blogger.com,1999:blog-763097243383122769.post-47750209481133927212016-03-21T20:57:00.003+05:302016-03-22T09:26:27.196+05:30"ERROR: Could not find cookbook in your cookbook path, skipping it" in Chef<div dir="ltr" style="text-align: left;" trbidi="on">
Chef is a automation framework tool which help us to deploy code or configuration across multiple systems which may be physical, virtual or cloud systems.<br />
<br />
Here I am just want to highlight one small issue which I got when I was trying to upload cookbook from my workstation. Everything was in place, but still it was throwing below error:<br />
<br />
<blockquote class="tr_bq">
<i>$ knife cookbook upload <b><u>cookbook_name</u></b>ERROR: Could not find cookbook <b><u>cookbook_name</u></b> in your cookbook path, skipping it<br />ERROR: Failed to upload 1 cookbook.</i></blockquote>
<br />
Usually, by default knife will use default location specified in <b><i>~/.chef/knife.rb</i></b> file for cookbook. In my everything was correctly configured as below :<br />
<br />
<blockquote class="tr_bq">
<i>$ cat ~/.chef/knife.rb | grep cookbook_path<br />cookbook_path [ '.', '..' ]</i></blockquote>
<div>
I was trying to upload as per directory name given to cookbook.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-O0G3aKcJ6xw/VvAQ7GaHWvI/AAAAAAAABNg/uxY6x3zibSkh81SF6dhBYx-feEBFwXQFA/s1600/chef1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://4.bp.blogspot.com/-O0G3aKcJ6xw/VvAQ7GaHWvI/AAAAAAAABNg/uxY6x3zibSkh81SF6dhBYx-feEBFwXQFA/s1600/chef1.png" /></a></div>
<div>
<br /></div>
<div>
After, doing lots of search finally got to know that knife command will compare the cookbook name from metadata.rb file in cookbook directory. Then I made the correction in metadata.rb file and it works like charm as below:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-4u61ruFibN0/VvAS1A8LsUI/AAAAAAAABNs/qFC8CloUOuUvsei0qUujgwqdfqmEEy8mA/s1600/chef2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://3.bp.blogspot.com/-4u61ruFibN0/VvAS1A8LsUI/AAAAAAAABNs/qFC8CloUOuUvsei0qUujgwqdfqmEEy8mA/s1600/chef2.png" /></a></div>
<div>
<br /></div>
</div>
Kuldeep Sharmahttp://www.blogger.com/profile/06750526214785849635noreply@blogger.com1