tag:blogger.com,1999:blog-8956914277423442852024-03-18T13:13:30.657+05:30My Technical WorksLet's Work Along With Technologyజగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.comBlogger685125tag:blogger.com,1999:blog-895691427742344285.post-25018206357253949462022-06-13T08:52:00.003+05:302022-06-13T08:52:58.649+05:30Shell Linting<p><br /></p><div class="separator" style="clear: both; text-align: center;"><img border="0" data-original-height="256" data-original-width="256" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxiHaIafBCxik2EXqTzD25TQlQwiSGy7jUVyA-z0jfP8pwJ3jdEMoaR7kVbQvr_9aYgkLMLmHTkif3ZLDRy4oaMxz6ueeezOt4fEojm52tT9X_05r0BfESAHdr1ePncoqFcl2aQ_37XW9eRoicJl_peeBuzB6aDjGKLCefzAH8axJoGpAss7DXhkLnXw/w320-h320/communityIcon_xagsn9nsaih61.png" width="320" /></div><p></p><span id="docs-internal-guid-14a42ac0-7fff-5ab3-0183-abb3dd5e53f8"><ol style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Always start with a Shebang</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> :The first rule of scripting is to always start with a Shebang. The shebang is a special character sequence in a script file that specifies which program or interpreter should be called to run the script. It is always the first line in the script. Without the shebang line, the system doesn’t know what language to use to process the script.</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">The sha-bang (#!) at the top of the Script created or to be created is a script that tells our Operating System that our file is a set of commands that will be fed (will be interpreted) by the command interpreter indicated after it. The character pair #! actually, it's a magic number two-byte, a special marker that designate a file type, and in our case, an executable shell script. Immediately after the sha-bang comes the name of the path where the interpreter to be executed is located plus the name of said interpreter. In other words, this is the path to the program that interprets the commands in the script, whether it be an interpreter, a programming language, or a utility. </span></p><br /><ol start="2" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Variables and Naming Conventions</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">1. variables should always have the form name=value</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">2. Ideally a Variable name is best identified if it consists Upper case letters, digits and '-' ( underscore )</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">3. </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Variable annotations</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Bash allows for a limited form of variable annotations. The most important ones are:</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local (for local variables inside a function)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> readonly (for read-only variables)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Strive to annotate almost all variables in a bash script with either local or readonly.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 4. Prefer local variables within functions over global variables</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 5. If you need global variables, make them read only</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 6. Make sure Variables are capitalized for better understanding</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> of code.if we want to use capitals, use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Environment (exported) variables: ${ALL_CAPS}</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Local variables: ${lower_case}</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Constants : CONSTANT_NAME</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">7. </span><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Variables names for loops should be similarly named for any variable you’re looping through. Check variable zone in the below loop</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">for zone in "${zones[@]}"; do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> something_with "${zone}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Done</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">8. Constants and Environment Variable Names : All caps, separated with underscores, declared at the top of the file.Constants and anything exported to the environment should be capitalized.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Constant</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">readonly PATH_TO_FILES='/some/path'</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Both constant and environment</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare -xr USER_SID='PROD'</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">9. Define Default variables when required</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">VARIABLE="${1:-$DEFAULTVALUE}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">which assigns to VARIABLE the value of the 1st argument passed to the script or the value of DEFAULT VALUE if no such argument was passed. Quoting prevents globbing and word splitting.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Default values</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: "${S3_HOST:="https://minio.superevil.io:9000"}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: "${S3_BUCKET_NAME:="foo/bar"}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: "${S3_ACCESS_KEY:-""}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: "${S3_SECRET_KEY:-""}"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">10. </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Declare all Variables</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Bash doesn’t have a strong type system. To allow type-like behavior, it uses attributes that can be set by a command. ‘declare’ is a bash built-in command that allows you to update attributes applied to variables within the scope of your shell. In addition, it can be used to declare a variable in longhand. a simple use case looks as ,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ declare var</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ declare -i int</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ var="1+1"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ int="1+1"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ echo "$var"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 1+1 ## The literal "1+1"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> $ echo "$int"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 2 ## The result of the evaluation of 1+1</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">11. </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Don’t start Variable Name with special characters or Numbers</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> -one="java"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 123one="java"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo $-one</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo $123one</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@ip-172-31-19-247 ~]# sh simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> simple.sh: line 4: -one=java: command not found</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> simple.sh: line 5: 123one=java: command not found</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> hBone</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 23one</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">12. Surround your variables with {}. Otherwise bash will try to access the $ENVIRONMENT_app variable in /srv/$ENVIRONMENT_app, whereas you probably intended /srv/${ENVIRONMENT}_app.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">13. Surround your variable with " in if [ "${NAME}" = "java" ], because if $NAME isn't declared, bash will throw a syntax error (also see nounset).</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">14. Use :- if you want to test variables that could be undeclared. For instance: if [ "${NAME:-}" = "java" ] will set $NAME to be empty if it's not declared. You can also set it to noname like so if [ "${NAME:-noname}" = "java" ]</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">15. Set magic variables for current file, basename, and directory at the top of your script for convenience.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Set magic variables for current file & dir</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">__base="$(basename ${__file} .sh)"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">16. Variable substitution :</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "${var}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "Substitute the value of var."</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "${var:-word}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "If var is null or unset, word is substituted for var. The value of var does not change."</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "${var:=word}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "If var is null or unset, var is set to the value of word."</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "${var:?message}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "If var is null or unset, message is printed to standard error. This checks that variables are set correctly."</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "${var:+word}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo "If var is set, word is substituted for var. The value of var does not change."</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 17. Global Script Variables</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">A number of predefined global variables are used and available to all scripts:</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Global Directory Declaration:</span></p><br /><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">BASE_DIR This is the base directory of the project that can be used to reference other files</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">SCRIPT_DIR This is the /scripts project directory</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">CNF_DIR This is the /etc project directory</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">LOG_DIR This is the /log project directory</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">TMP_DIR This is a temporary working directory, currently this defaults to /tmp </span></p></li></ul><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">When creating global variables for important paths, allow for override of these by the controlling shell environment. For example.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[ ! -z “${TMP_DIR}” ] && TMP_DIR=”/tmp” # Correct definition</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">TMP_DIR=”/tmp” # Incorrect defintion</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Global File Name Declaration :</span></p><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">TMP_FILE A pre-defined unique temporary file that is auto removed on completion</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">STOP_FILE A pre-defined file to stop script processing in loops (only if used in functions)</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">DEFAULT_CNF_FILE A pre-defined standard /etc config file name</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">DEFAULT_LOG_FILE A predefined standard /log log file name</span></p></li></ul><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Variables:</span></p><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">DATE_TIME – The date/time of the script execution</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">DATE_TIME_TZ – The date/time/timezone of the script execution</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">USER_ID – The running user id</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">FULL_HOSTNAME – The full and qualified hostname</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">SHORT_HOSTNAME – The short hostname</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">LOG_DATE_FORMAT – The Date Format used for all log files</span></p></li></ul><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Other Variables</span></p><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">QUIET – Quiet Logging, ERROR and WARN only</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">USE_DEBUG – Enable Debugging</span></p></li></ul><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">18. Variable Usages</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 58.5pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">When using variables, they are always to be enclosed in curly brackets.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 58.5pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">${TMP_FILE} is acceptable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 58.5pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">$TMP_FILE is NOT acceptable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 58.5pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">When displaying variables in stdout, they should always be included in single quotes (‘) to ensure actual value can be determined. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 58.5pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">info “Exiting with status code of ‘${EXIT_CODE}'”</span></p><br /><ol start="3" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">No space before or after the equal sign. </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;">Make sure no space is given when defining variables. Check the below codes language variable for reference</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> language = java</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo $language</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@ip-172-31-19-247 ~]# sh simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> simple.sh: line 1: !#/bin/bash: No such file or directory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> simple.sh: line 3: language: command not found</span></p><br /><ol start="4" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Double quotes around every parameter expansion : </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;">Word Splitting is the demon inside Bash that is out to get unsuspecting newcomers or even veterans who let down their guard.It's not just spaces you need to protect. Word Splitting occurs on all whitespace, including tabs, newlines, and any other characters in the IFS variable. Always double quote the variables in script as below,</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# touch "java is lang"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> language="java is lang"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm $language</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@ip-172-31-19-247 ~]# sh simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm: cannot remove 'java': No such file or directory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm: cannot remove 'is': No such file or directory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm: cannot remove 'lang': No such file or directory</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> modified code looks as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> language="java is lang"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm "$language"</span></p><br /><ol start="5" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use Good Indentation</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : it is very important to make code more readable thus making it more maintainable. Where we write code with more than 1 level of logic, make sure it is always indented. It doesn't matter much whether how many spaces you indent, though most people seem to use 4 spaces or 8. Just make sure that your do's and don'ts line up and you'll be fine.</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> a simple indentation looks as,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ $# -ge 1 ] && [ -d $1 ]; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> for file in `ls $1`</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ $debug == "on" ]; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo working on $file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> wc -l $1/$file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> done</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> else</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "USAGE: $0 directory"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><br /><ol start="6" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Always provide usage of the script.</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> It is important to let executors of the script understand how to execute the code. what parameters need to be passed and how to. a simple example below, if we run the script without passing a filename, it throws a usage error </span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ $# == 0 ]; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "Usage: $0 filename"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Fi</span></p><ol start="7" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Sensible commenting</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : provide comments as much as you can while writing the code. explaining what the part of code does helps a lot when you revisit the code after some time. Don't explain the obvious lines, but explain every command that you're using or the important ones get lost in the mix. </span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">user=$1</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # The below logic is to check if account exists on the system or not</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> grep ^$user: /etc/passwd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ $? != 0 ]; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "No such user: $username"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Fi</span></p><br /><ol start="8" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Long Notation</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Always use long parameter notation when available. This makes the script more readable, especially for lesser known/used commands that you don’t remember all the options for.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Avoid:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm -rf -- "${dir}"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # Good:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm --recursive --force -- "${dir}"</span></p><br /><ol start="9" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Return an Exit Code </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: Always return an exit code when something goes wrong. Many of the times, we don't even care of what is returned when something exits but returning a non-zero code when something goes is not a bad idea. At some point we might need this return code when we are executing the shell script from other languages.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> #!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> cat file.txt</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ $? -eq 0 ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "The script ran ok"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> else</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "The script failed" >&2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@ip-172-31-19-247 ~]# sh simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> cat: file.txt: No such file or directory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt; padding: 0pt 0pt 0pt 18pt; text-indent: -18pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> The script failed</span></p><br /><ol start="10" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Check Argument Types</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : We can save a lot of our time when we make sure the arguments provided to your script are of the type expected before you start to use them. a simple check looks like below,</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">if ! [ "$1" -eq "$1" 2> /dev/null ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "ERROR: $1 is not a number!"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Fi</span></p><br /><br /><ol start="11" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use Arrays wherever Possible</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Most of the times we write code where we store a collection of items or elements in a string. always use a array when there are collection of items as below,</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare -r hosts="host1 host2 host3"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">for host in $hosts # not quoting $hosts here, we want word splitting</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "$host"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> done</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use an array instead!</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> declare -r -a host_array=( host1 host2 host3 )</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> for host in "${host_array[@]}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "$host"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> done</span></p><br /><ol start="12" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Avoid Unnecessary Pipelines</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Most of the code that we write are dependent on the piping. Avoid unnecessary piping and use the shell builtin as below,</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> cat file | command</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command < file</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo text | command</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command <<< text</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> grep pattern file | awk '{print $1}'</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> awk '/pattern/{print $1}'</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> grep pattern file | sed 's/foo/bar/g'</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> sed -n '/pattern/{s/foo/bar/p}' file</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command | sort | uniq</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command | sort -u</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command | grep pattern | wc -l</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command | grep -c pattern</span></p><br /><ol start="13" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use Process|Command Substitution wherever possible</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : process substitution is a form of inter-process communication that allows the input or output of a command to appear as a file. The command is substituted in-line, where a file name would normally occur, by the command shell. This allows programs that normally only accept files to directly read from or write to another program.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> A simple example is the creation of temporary files </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # using temp files</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command1 > file1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command2 > file2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> diff file1 file2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> rm file1 file2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # using process substitution</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> diff <(command1) <(command2)</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # dont use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo 'echo “hello world”'</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo $(echo “hello world)</span></p><br /><ol start="14" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Activate Bash Debug Mode</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : In many situations, bash will continue executing the script even when a specific part fails, impacting the rest of the script badly. To ensure that the script exists upon facing some fatal error, it’s recommended to have the following lines at the start.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -o errexit</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -e : This tells the shell to exit the script as soon as any statement returns a non-zero exit code.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -u : By default, bash will ignore any variables that don’t exist. adding "set -u" will not ignore the variables that does not exist</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -a : Using set -a, you can cause any variable or function that you create to be automatically exported so that subshells and scripts can use them.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -x : shows each command as it’s being run as well as the output. enable xtrace option</span></p><br /><ol start="15" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Write error messages to stderr</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Always write Error messages belonging to stderr not stdout.</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "An error message" >&2</span></p><br /><ol start="16" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Comparisons</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Use = instead of == for String Comparisons. Note that == is a synonym for =, therefore only use a single = for string comparisons, for instance:</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">value1=java.com”</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> value2=shell.com”</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ "$value1" = "$value2" ]</span></p><br /><ol start="17" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">printf over echo</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : For various reasons, printf is preferable to echo. printf gives more control over the output, it’s more portable and its behavior is defined better. Print error messages on stderr. E.g., I use the following function:</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">error() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> printf "${red}!!! %s${reset}\\n" "${*}" 1>&2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><br /><ol start="18" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Trap forced exit of script</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Don’t let your script exit unexpectedly, trap when someone updates press ctrl+c and exit from your script gracefully.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># trap ctrl-c and call ctrl_c()</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> trap ctrl_c INT</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> function ctrl_c() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "** Trapped CTRL-C"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> for i in `seq 1 5`; do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> sleep 1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo -n "."</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> done</span></p><br /><ol start="19" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use $() over backticks : </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Avoid using backticks ““”, they are hard to read and in some fonts easily confused with single quotes. A lot of quoting needed in nesting. Use $(command) instead of `command` because it is easier to nest multiple commands and makes your code more readable.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># dont use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">$ echo "one-`echo two-\`echo three-\`\`echo four\`\`\``"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">one-two-three-four </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">$ echo "one-$(echo two-$(echo three-$(echo four)))"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">one-two-three-four</span></p><br /><ol start="20" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Logging : </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Logging is the most critical thing for everyone whether he is a developer, sysadmin or DevOps. Debugging seems to be impossible without logs. As we know most applications generate logs for understanding what is happening with the application, the same practice can be implemented for shell script as well. For generating logs we have a bash utility called logger.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# cat simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#!/bin/bash</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">DATE=$(date)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare DATE</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">check_file() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local FILENAME="$1"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if ! ls "${FILENAME}" > /dev/null 2>&1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> logger -s "${DATE}: ${FILENAME} doesn't exists"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> else</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> logger -s "${DATE}: ${FILENAME} found successfully"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">check_file "/etc/passwd"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-19-247 ~]# sh simple.sh </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><13>Feb 26 12:48:19 ec2-user: Sat Feb 26 12:48:19 UTC 2022: /etc/passwd found successfully</span></p><br /><ol start="21" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Builtin Commands vs. External Commands : </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Given the choice between invoking a shell builtin and invoking a separate process, choose the builtin.. We prefer the use of builtins such as the Parameter Expansion functions in bash(1) as it’s more robust and portable (especially when compared to things like sed).</span></p></li></ol><br /><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Dont use </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">addition="$(expr "${X}" + "${Y}")"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">substitution="$(echo "${string}" | sed -e 's/^foo/bar/')"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Use this</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">addition=$(( X + Y ))</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">substitution="${string/#foo/bar}"</span></p><br /><ol start="22" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Minimize Bash Spawn Usage: </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Try to use bash builtins for any sort of work unless not available. If we use external commands to perform work, bash can spawn sub shell to get the work done. This can lead to other issues. For Instance a simple seq count as below,</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">for number in $(seq 1 10); do</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Bash is able enough to do the counting for you. You do not need to spawn an external application (especially a single-platform one) to do some counting and then pass that application's output to Bash for word splitting. The above can be written as,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">C-style for loops are the best method for implementing a counter for ((i=1; i<=10; i++)). For instance</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of dirname, use:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare -r file_dir="{my_file%/*}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of basename, use:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare -r file_base="{my_file##*/}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of sed 's/blah/hello', use:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">declare -r new_file="${my_file/blah/hello}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of bc <<< "2+2", use:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">echo $(( 2+2 ))</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of grepping a pattern in a string, use:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[[ $line =~ .*blah$ ]]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of cut -d:, use an array:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">IFS=: read -a arr <<< "one:two:three"</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><br /><br /></span></p><ol start="23" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use [ … ]] vs. [ … ]</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Unless a script must run in a POSIX-compatible environment, use [[ ... ]] rather than [ ... ] when performing conditional tests. Unlike the [ and test bash builtins, [[ ... ]] is part of shell syntax, not a command. This means it can handle its internal elements (test conditions) in a more robust fashion, as pathname expansion and word splitting do not occur. Also, [[ ... ]] adds some additional capabilities such as =~ to perform regular expression tests.</span></p></li></ol><br /><ol start="24" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use shift to read function arguments</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Instead of using $1, $2 etc to pick up function arguments, use shift as shown below. This makes it easier to reorder arguments, if you change your mind later.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Processes a file.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># $1 - the name of the input file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># $2 - the name of the output file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">process_file(){</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local -r input_file="$1"; shift</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local -r output_file="$1"; shift</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">shift is a bash built-in which kind of removes arguments from the beginning of the argument list. Given that the 3 arguments provided to the script are available in $1, $2, $3, then a call to shift will make $2 the new $1. A shift 2 will shift by two making new $1 the old $3</span></p><br /><ol start="25" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Use null delimited output where possible : </span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In order to correctly handle filenames containing whitespace and newline characters, you should use null delimited output, which results in each line being terminated by a NUL (00) character instead of a newline. Most programs support this. For example, find -print0 outputs file names followed by a null character and xargs -0 reads arguments separated by null characters.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># instead of</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">find . -type f -mtime +5 | xargs rm -f</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># use</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">find . -type f -mtime +5 -print0 | xargs -0 rm -f</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># looping over files</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">find . -type f -print0 | while IFS= read -r -d $'' filename; do</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> echo "$filename"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">done</span></p><br /><ol start="26" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Functions</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Bash can be hard to read and interpret. Using functions can greatly improve readability. Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" command</span></p></li></ol><br /><ol style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Apply the Single Responsibility Principle: a function does one thing.</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">function name has an underscore as a prefix. It seems like a good idea to always have a special naming convention for your bash functions to avoid any potential clashes with built-in operators or functions you might include from other files</span></p></li><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Function Location : </span><span style="color: #24292e; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Put all functions together in the</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">file just below constants. Don’t hide executable code between functions. Doing so makes the code difficult to follow and results in nasty surprises when debugging. If you’ve got functions, put them all together near the top of the file. Only includes, </span><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set</span><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> statements and setting constants may be done before declaring functions.</span></p><ol start="4" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Document all functions that we write</span><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;"> : it is very important to document all functions that we write. Giving meaning full explanation of the functions is very important for a better code</span></p></li></ol><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # Processes a file.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # $1 - the name of the input file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # $2 - the name of the output file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> process_file(){</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><ol start="5" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Function Comments</span><span style="color: #24292e; font-family: Arial; font-size: 16.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;"> : </span><span style="color: #24292e; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Any function that is not both obvious and short must be commented. Any function in a library must be commented regardless of length or complexity. It should be possible for someone else to learn how to use your program or to use a function in your library by reading the comments (and self-help, if provided) without reading the code.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">All function comments should describe the intended API behavior using:</span></p><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 54pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Description of the function.</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 54pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Globals: List of global variables used and modified.</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 54pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Arguments: Arguments taken.</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 54pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Outputs: Output to STDOUT or STDERR.</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; margin-left: 54pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Returns: Returned values other than the default exit status of the last command run.</span></p></li></ul><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Example:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#######################################</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Cleanup files from the backup directory.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Globals:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># BACKUP_DIR</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># ORACLE_SID</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Arguments:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># None</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Outputs : stdout</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">$ Returns : None</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #999988; font-family: Consolas, sans-serif; font-size: 10pt; font-style: italic; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#######################################</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">function </span><span style="background-color: #f6f8fa; color: #24292e; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">cleanup</span><span style="background-color: #f6f8fa; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">()</span><span style="background-color: #f6f8fa; color: #24292e; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="background-color: #f6f8fa; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">{</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #24292e; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> …</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 67.5pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">}</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><br /><br /></span></p><ol start="6" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; margin-left: 36pt; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Function Variable Declaration : Declare variables with a meaningful name for positional parameters of functions</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">happy() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local first_arg="${1}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> local second_arg="${2}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [...]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 7. Create functions with a meaningful name for complex tests</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Don't do this</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if [ "$#" -ge "1" ] && [ "$1" = '-h' ] || [ "$1" = '--help' ] || [ "$1" = "-?" ]; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> usage</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # Do this</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">help_wanted() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [ "$#" -ge "1" ] && [ "$1" = '-h' ] || [ "$1" = '--help' ] || [ "$1" = "-?" ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> if help_wanted "$@"; then</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> usage</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> fi</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 8.</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;"> Cleanup code</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : An idiom for tasks that need to be done before the script ends (e.g. removing temporary files, etc.). The exit status of the script is the status of the last statement before the finish function.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">finish() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> result=$?</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # Your cleanup code here</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> exit ${result}</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> 9. Mandatory Script Functions :All scripts are to have the following default functions:</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">bootstrap</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : The bootstrap function is to be identical in all scripts, this is used to source necessary common functions used by all scripts</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">help</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> Or </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Usage</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">: The help function is to display the usage of the function and then exit. The usage needs to specify all command line arguments, and the client identifies mandatory and optional arguments. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">process_args</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : This function is used to process the command line arguments for scripts. The getopt function is used for processing arguments however this only support single character options (e.g. -v -h -p etc). Scripts should be written for only single character options.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">To improve the namespace, as well as provide a difference between operational parameters and information parameters the following two word options are used.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">–help Display script help and exit</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">–version Display single line script version and exit</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">main</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : The main function where all the things start. the code should be minimal.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Finish</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Clean up code</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">10 . </span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Standard Body Template</span><span style="color: #232629; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Unless we are writing a small script, we need to use functions to modularise your code and make it more readable, reusable and maintainable. The template for the script with longer code is show below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#! /usr/bin/env bash</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># Author: Jagadish manchala <</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ Usage: SCRIPTNAME [OPTIONS]... [ARGUMENTS]...</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ OPTIONS</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ -h, --help</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ Print this help message</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ EXAMPLES</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#/ </span></p><br /><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#{{{ Bash settings</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># abort on nonzero exitstatus</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -o errexit</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># abort on unbound variable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -o nounset</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># don't hide errors within pipes</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">set -o pipefail</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#}}}</span></p><br /><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#{{{ Variables</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">readonly script_name=$(basename "${0}")</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">IFS=$'\t\n' # Split on newlines and tabs (but not on spaces)</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#}}}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">main() {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # check_args "${@}"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> :</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#{{{ Helper functions</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">usage() { }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">bootstrap() { }</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">my_function() { }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> finish(){ }</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#}}}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">main "${@}"</span></p><div><span style="color: red; font-family: Consolas, sans-serif; font-size: 11.5pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-75979722898569243032022-01-10T14:56:00.003+05:302022-01-10T20:07:19.557+05:30Kubernetes - Ephemeral Container : Copy Of Pod By Changing Image<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both;"><span style="font-family: verdana;">Most of the time, developers deploy their application in small sized images which does not contain any debugging utilities. As a practice, they deploy the code in distroless images. But when that application is misbehaving, kubernetes provides us a way to change that container image to another image which contain debugging utilities.</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Create a Image using the Image BusyBox as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@ec2-3-138-100-101 ec2-user]# kubectl run myapp --image=busybox --restart=Never -- sleep 1d</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">pod/myapp created</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@ec2-3-138-100-101 ec2-user]# kubectl describe pod myapp | grep Image</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Image: busybox</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Image ID: docker-pullable://busybox@sha256:5acba83a746c7608ed544</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">We can see that the pod is created with the busybox image. Now create another debugging pod for the above one but with ubuntu image as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@ec2-3-138-100-101 ec2-user]# kubectl debug myapp --copy-to=myapp-debug --set-image=*=ubuntu</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">We can check the debugging image as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@ec2-3-138-100-101 ec2-user]# kubectl describe pod myapp-debug | grep Image</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Image: ubuntu</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Image ID: docker-pullable://ubuntu@sha256:b5a61709a9a44284d882342</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">We can see that we can create another pod with our application pod but with different image so that we can troubleshoot the code</span></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-57083367570531972842022-01-10T14:53:00.001+05:302022-01-10T14:53:38.462+05:30Docker - Running Container in privileged mode<p><br /></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi6qDhURYrfldUQA9un3v2tmVcRFQ6SImFn0rbXvmdCZOjoeM3P-CBsARFdXbM3ZoHOLZenpvT7IRKk-39gzLbgNaBGF5TYZ-xT3aq7QSLq8QZ5iwa6Mu49fxaPFVWTPoUacX2-6Vyyr48rO1ybpeC2aje08ihZc6NFOY-qREagVc3LctpVf7QcZPqt2g=s405" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" height="195" src="https://blogger.googleusercontent.com/img/a/AVvXsEi6qDhURYrfldUQA9un3v2tmVcRFQ6SImFn0rbXvmdCZOjoeM3P-CBsARFdXbM3ZoHOLZenpvT7IRKk-39gzLbgNaBGF5TYZ-xT3aq7QSLq8QZ5iwa6Mu49fxaPFVWTPoUacX2-6Vyyr48rO1ybpeC2aje08ihZc6NFOY-qREagVc3LctpVf7QcZPqt2g=s320" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">With new security restrictions, developers are running their code in a more secured area. They are running their code in containers with less privileges, non root and secure images. But there are times where we need to provide additional privileges to things running inside.</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">Docker provides us with a privileged mode which grants a docker container root capabilities to all devices on the host machine. Running a container in a privileged mode gives all the capabilities of the host machine. This gives access to Host kernel and device access even.</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">Lets create a container with the privileged mode as below,</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">[root]# docker run -it --privileged ubuntu</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">We can check the privileged mode as below,</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">[root]# docker inspect --format='{{.HostConfig.Privileged}}' d2973c618caf</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">true</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">Now from inside the container we can perform multiple root level operations like mounting a new file system as below,</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">[root]# mount -t tmpfs none /mnt</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">[root]# df -h</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">Filesystem Size Used Avail Use% Mounted on</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">overlay 20G 4.3G 16G 22% /</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">tmpfs 64M 0 64M 0% /dev</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">shm 64M 0 64M 0% /dev/shm</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">/dev/xvda1 20G 4.3G 16G 22% /etc/hosts</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">none 3.9G 0 3.9G 0% /mnt</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">Allowing a Container root access makes a system open to attacks. A malicious code running inside the privileged container can gain access completely to the host machine and cause serious damage to not just the system but the whole Infrastructure. Hope this helps in understanding Privileged Mode in Containers</span></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-83655012559370948912022-01-10T14:48:00.004+05:302022-01-10T14:48:50.175+05:30Kubernetes - Static pods<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; text-align: justify; white-space: pre-wrap;">We know that the pods are created and managed by the Api-server. Though the pods are created in the worker nodes by the kubelet running on those nodes, the details are first managed by the api-server and will ask this kubelet to create the pod. This means the management of this pod will be taken care of by the api-server. These pods are continuously managed and observed by the api-server</span><p></p><span id="docs-internal-guid-60b06cc1-7fff-9e74-a8e9-757051dede54"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">But there is another type of pod that is managed directly by the kubelet rather than the api-server. This means the pod created by the kubelet is managed by the kubelet by itself. Control plane is not involved in the lifecycle of the static pod. In addition to this, kubelet also tries to create a mirror pod on the kubernetes api-server for each static pod so that the static pods are visible when we list the pods.Static pods are usually used by software bootstrapping kubernetes itself. For example, kubeadm uses static pods to bring up kubernetes control plane components like api-server, controller-manager as static pods. Since the static pods are managed by the Kubelet itself, we need to create these static pods on any of the worker nodes.</span></p><br /><p dir="ltr" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">kubelet can watch a directory on the host file system (configured using --pod-manifest-path argument to kubelet) or sync pod manifests from a web url periodically (configured using --manifest-url argument to kubelet). When kubeadm is bringing up the kubernetes control plane, it generates pod manifests for api-server, controller-manager in a directory which kubelet is monitoring. Then kubelet brings up these control plane components as static pods. In this article, we will see how we can create a Static pod, </span></p><p dir="ltr" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"> </p><p dir="ltr" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Create a Simple pod definition file as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-18-217-122-218 kubelet]# cat /root/staticPod/static-pod.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> name: static-pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> labels:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> role: app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> image: busybox:1.28</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> ports:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> containerPort: 443</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> protocol: TCP</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Now once the pod definition file is available, we need to identify the kubelet watch directory. Now check the static pod location where kubelet tries to read. To find this go to,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-18-217-122-218 kubelet]# cd /var/lib/kubelet/</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-18-217-122-218 kubelet]# cat config.yaml | grep static</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">staticPodPath: /etc/kubernetes/manifests</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We can see the location where kubelet reads for static pod is /etc/kubernetes/manifests</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Copy your static pod file over this location and restart the kubelet as below</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-18-217-122-218 manifests]# systemctl restart kubelet</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Now after a few seconds, if we do a kubectl get pods from the master node, we can see the mirror pod details as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 44px; overflow: hidden; width: 624px;"><img height="44" src="https://lh6.googleusercontent.com/bddPbO5iOh0_v2rfrleFM0rptxwBJL_0ydtdCeJKuMEkGofjGBmFkd6oxI_O3WpFKauW5MwIa2RpdWpIBftYKmM101YSpPC8NA1oHdtjejy_pRYfOsuCFM3eYWFD21cx3-iYTimW" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We can see that the static nignx pod, is running.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">If we try to delete the pod from the master node, it deletes but the kubelet again starts the pod as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 100px; overflow: hidden; width: 624px;"><img height="100" src="https://lh5.googleusercontent.com/tC2Z2rX7lH5qPK2rQS2DbgttqejwcidrJWQXZeR6Jq6RNL9ggoMXzbG3Fu0Ve2P2x3WeO-AVQhlv9e-htHbzKRsPV9jLCY8vamebXBQPoK2sxeZUsj5qCWwqHj4_YWNxNADH8Agq" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: #fcfcfc; color: #404040; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">kubelet periodically scans the configured directory for static pods and if there are any changes, the kubelet performs them accordingly.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Identify status pod</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since static pods are not controlled by an api-server, the controlled by Element in the pod description shows a different value. </span><span style="background-color: white; color: #232629; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Checking the owner reference of a static pod using kubectl describe command should indicate that such a pod is not controlled by a ReplicaSet but rather from Node/controlplane</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #232629; font-family: Consolas, sans-serif; font-size: 10pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 24px; overflow: hidden; width: 624px;"><img height="24" src="https://lh6.googleusercontent.com/EVkA0mqPdai0-Z1HZ68p9WRko9Jac2knjhapOXV0ozuM1BThgK8JqUH3nOwj_zsL-6DTkpPAZqHEKe69l1C3kMPsIpXN8LV2wDarCEAbwbo0F_1ePQ55HzNNsg13PMnSVTLeEtN_" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #232629; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">So Static pods are introduced for running pods across all or a subset of chosen nodes. This was useful for system service components like log forwarders like fluentd , networking components like kube-proxy. Because of the limitation with the static pods like no health check ets, kubernetes came up with Daemon Sets. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #232629; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this helps in understanding Static Pods</span></p></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-26705437628249292702022-01-09T10:29:00.001+05:302022-01-09T10:29:21.866+05:30Kubernetes - Labels, Selector and matchLabels<p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; text-align: justify;"></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><p></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; text-align: justify;"><span style="font-family: verdana;">Labels are a mechanism that we use to organize objects in kubernetes.a K8s object can be anything from containers, pods to services and deployments. Labels are key-value pairs that we can attach to a resource for identification. The labels contain information and are used by kubernetes to query objects based on these labels.</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">A label can be applied to a pods as shown below,</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] cat simple-label.yml<span class="Apple-converted-space"> </span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">apiVersion: v1</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">kind: Pod</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">metadata:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>name: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>labels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>env: dev</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">spec:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>containers:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>- name: test-ser</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>image: docker.io/jagadesh1982/testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>ports:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>- containerPort: 9876</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">From the above config we are actually creating a pod with the label “env=dev”.<span class="Apple-converted-space"> </span></span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">To see the label available for a pod we can use the command,</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span id="docs-internal-guid-81fe1ea7-7fff-47cc-e8bb-15783d9dd717"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 63px; overflow: hidden; width: 624px;"><img height="63" src="https://lh5.googleusercontent.com/Cyy-1bBwfVz-bDDMG3qtQrXj45RwsTPKJ1bSUHyaM6EapKpBBy1Hyqu24eyLXv1yTFNYSRZHHHfxJD2Oc1CDzPaf1sy_ACjOKWh-3EBUQJ54h1s-_lDYcYP-_LN5iCd-0bUyDgbY" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">If we want to assign a label while a pod is running, we can use</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span id="docs-internal-guid-832984a2-7fff-8a13-d160-091123a6c19f"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 40px; overflow: hidden; width: 624px;"><img height="40" src="https://lh5.googleusercontent.com/zoJZ3QGC1pRzYhffCOHWpCRl3ZNeOTJjTLVEo-lpK6x2dHkU0a21Pqta1mf2kDVM4kb2l-LeeITKUVH6mTJ-ndfYR1FThaAcA8g_lwhxeWIk2LuF74p3X0XBpZ5AzI_Pn8zQ8wHH" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">Now we can see the labels attached to the pod using,</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span id="docs-internal-guid-b29e0251-7fff-b203-deb0-361fe5c93304"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 59px; overflow: hidden; width: 624px;"><img height="59" src="https://lh3.googleusercontent.com/ayqHQkY6MOT8XhZ0VJ3HBX3MTf2YuYEYjJqpResZlLXPoq2MUS2a_faw42_Yk-qWc_jCkswdQUvMosJsCe8ooGVyvZut692t87Q3WtnGH7HH3rlRIOchQw0s0n_nXZHVOxhgYfvW" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">Consider the below deployment,<span class="Apple-converted-space"> </span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] cat simple-label.yml<span class="Apple-converted-space"> </span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">apiVersion: apps/v1</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">kind: Deployment</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">metadata:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>name: testing-service-v1</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>labels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">spec:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>replicas: 3</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>selector:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>matchLabels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>version: "1.0"</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>template:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>metadata:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>labels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>version: "1.0"</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>spec:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>containers:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>- name: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>image: docker.io/jagadesh1982/testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>ports:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>- name: http</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>containerPort: 9876</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>env:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>- name: VERSION</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>value: "1.0"</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">In the above config, we can see that there are labels defined in multiple places as<span class="Apple-converted-space"> </span></span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">************</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">metadata:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>name: testing-service-v1</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>labels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>tier: backend</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">spec:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>replicas: 3</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>selector:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>matchLabels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>template:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>metadata:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>labels:</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>app: testing-service</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"> </span>tier: backend</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">************</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">In the above config, we can see metadata.labels, selector.matchLabels and template.metadata.labels. What are these and in this article we will see what these do exactly?</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">The first metadata talks about the deployment itself. This means we are assigning a label “app: testing-service” and “tier: backed” to the deployment itself. This means we can delete the deployment using the </span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">“kubectl delete deploy -l app=testing-service</span><span style="font-family: verdana;">,tier=backend”. This label is used to identify the kind that we are creating which is deployment here.</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">Now the selector is used for a whole different purpose. Once we create a deployment,replica set or replication controller, pods also get created along. Now we need to tell the deployment how to find the pods that are created.For instance, in future if we want to scale a pod from 1 to 3, the deployment needs to find first what pods are currently running. For this it needs a way to identify the specific pods that are created as a part of deployment. The labels defined in the selector field helps deployment to identify the pods that are created as a part of that deployment. Now from the above configuration it will find all pods that have labels “app: testing-service” and will manage the pods. We call this a selector label.<span class="Apple-converted-space"> </span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><span class="Apple-converted-space"><br /></span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span id="docs-internal-guid-f495de65-7fff-5710-802c-36929beb2043"><span style="background-color: white; color: #707070; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 72px; overflow: hidden; width: 624px;"><img height="72" src="https://lh5.googleusercontent.com/mstRNirDoZLQOhk_gJpqWVskPrI2tesbmMGlOzQA4me7lwhJL24zfAgvaxQAJi7N9Gl_8pyyZojfA-BIHy9ReRgSWKihMKTTcLKPQ1SWQjyT1q2EPNWQeVo91LOYbsKInooOFrm5" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">To say exactly , to find out what pods are running or if we need to manage a group of pods we need to find them. The labels defined in the selector fields will help us to find the pods to manage them</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">But in order to manage or find pods running with a specific selector label, we need to assign them the labels. Once we assign the labels, then only we can find them using the selector. The labels that need to be assigned to the pods are defined in the<span class="Apple-converted-space"> </span>template.metadata.labels.</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">So</span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">.metadata.labels is for labeling the kind that we are creating. In the above case, the kind is deployment. If we want to find the deployment, we can use the labels defined in the metadata.labels</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">.spec.selector tells the deployment or replica set or replication controller how to find pods to manage , scale or delete.</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">.spec.template.metadata.labels are used to create the pods with labels so that deployment or replica set or replication controller can find or manage the pods.</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">In the above case, labels defined in .spec.selector and .spec.template.metadata.labels should be same</span></p><p class="p2" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 12px;"><span style="font-family: verdana;"><br /></span></p><p class="p1" style="font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span style="font-family: verdana;">Hope this helps in understanding the labels, selectors and podTemplate labels.</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-72139076923667951222022-01-09T10:07:00.002+05:302022-01-09T10:07:29.716+05:30Kubernetes - Ephemeral Container : Copy Of Pod<p></p><div class="separator" style="clear: both;"><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><span style="font-family: verdana;"><div style="text-align: justify;">Sometimes pod configurations do not allow connection for troubleshooting in certain cases. For instance, we can't run the “kubectl exec” command to connect to a container to troubleshoot. For instance, if your container image does not include a shell or if your application crashes on startup. In these situations we can use “kubectl debug” to create a copy of the pod with tools that aid in debugging.</div><br />Run the command to create a application container as below,<br />[root@ec2-3-138-100-101 ~]# <span style="color: #2b00fe;">kubectl run myapp --image=busybox --restart=Never -- sleep 1d</span><br />pod/myapp created<br /><br />Once the pod is created, create the debug pod and attach to the myapp pod above. In this case we are running this command to create a copy of myapp named myapp-debug that adds a new Ubuntu container for debugging:<br /><br />[root@ec2-3-138-100-101 ~]#<span style="color: #2b00fe;"> kubectl debug myapp -it --image=ubuntu --share-processes --copy-to=myapp-debug </span></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Defaulting debug container name to debugger-m897h. If you don't see a command prompt, try pressing enter. </span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">root@myapp-debug:/# <br /><br /><div style="text-align: justify;">After a few seconds, the debug pod gets connected to the original myapp pod and we can start the troubleshooting.Process namespace sharing can not be applied to an existing pod, so a copy of the target pod must be created. --share-processes flag enables process namespace sharing when used with --copy-to. These flags copy the existing pod spec definition into a new one with process namespace sharing enabled in the spec.</div></span></div><p></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-8804083627060998942022-01-09T09:56:00.002+05:302022-01-09T09:56:19.847+05:30Kubernetes - Ephemeral containers<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; white-space: pre-wrap;">Pods are fundamental units in kubernetes. All applications that we run inside a container run inside a Pod. Many times developers build containers with small base images, most of the times with distroless images based on slimmed versions of distributions. These images will not have a package manager or shell. Only the application and its dependencies are packed and run as containers.</span><p></p><span id="docs-internal-guid-7ade0eb4-7fff-b6b7-de6b-00deeba38139"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Things go well with the above packed containers until issues come. These issues can be application issues and troubleshooting them can be hard as we don’t have any tools to troubleshoot or package manager to install these tools. The only way is to rebuild the image with troubleshooting tools and re-run the application to troubleshoot the issue. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Another option provided by Docker is to attach a container to the existing application container on the same network and use the tools available. For instance, we can attach a container which has troubleshooting tools to an application container on the same network space and use tools to troubleshoot things. This is the same concept for Ephemeral containers.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We create a container image with all troubleshooting tools and when needed for debugging, we can deploy this ephemeral container into a running pod and troubleshoot things. Ephemeral containers are an alpha feature in Kubernetes 1.22, so the official recommendation is not to use it in production environments.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In this article, we will see how to use ephemeral containers for debugging things in a running container of pod. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">A simple pod with a ubuntu container looks as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-3-138-100-101 ~]# cat ephemeral-example.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> name: single-pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> labels:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> env: dev</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: testing-service</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> image: ubuntu</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> command: [ "/bin/bash", "-c", "--" ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> args: [ "while true; do sleep 30; done;" ]</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Run the “kubectl create -f ephemeral-example.yml” to create the pod. Now consider for instance we want to test the internet from this container in the pod as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 71px; overflow: hidden; width: 624px;"><img height="71" src="https://lh5.googleusercontent.com/aqCHU9SG1t0oH04mNws0v3DMEYVjq3xl36L7ZYThPTc0GNSvM3C0Hh6x1bk8m40-YxZ3YDUXgb8kpMPy1-yIoQaqpq_0ckyEXjdqsclEiV_jciLRarl7_TtZzR7BCnozAjbl1TQE=w655-h71" style="margin-left: 0px; margin-top: 0px;" width="655" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We can see that the ping command is not available to troubleshoot our network issues. Now lets create a ephemeral container and attach to this running pod single-pod as below,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ec2-3-138-100-101 ~]# kubectl debug -it single-pod --image=alpine:latest --target=testing-service</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In the above command, iam running a ephemeral container with image alpine:latest and attaching to the pod single-pod and to container testing-service running inside the single-pod. Once the ephemeral container is added to the running testing-service container, we can use the ping tool to perform our troubleshooting as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #707070; font-family: Arial; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 184px; overflow: hidden; width: 624px;"><img height="184" src="https://lh6.googleusercontent.com/Iti_SDrG_19BVeFRv7YP4quUReP5C1S_GkqAxAqe7HOLzreeuifCyEDUNbeVrvGH_ZqqHGr8n1OiUNGCXINYmB216vBeAMSYxZ-eqooIAEiflyPMi211IMr46qZ7bdjTF_GuUVpd" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Now if come out the command prompt by pressing CTRL P+Q , and describe the pod we can see new entries as Ephemeral container as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #707070; font-family: Arial; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 325px; overflow: hidden; width: 624px;"><img height="325" src="https://lh6.googleusercontent.com/ASCqRaJu-4IxEV9vn2AgQmXjGC-OxwldYm1x96byImHh51uzBfAHoDeSaUHZw_wYHP8Nj-qoJzow5QDAjRNSFWJsDhZDSu9weHS2E_d4UNGO9b2wUCG9ATjCfSRBNTtf7ZwrSx7n" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">This is how Ephemeral containers work. We Can create a container image which contains all troubleshooting tools and use when we need to troubleshoot the application containers as above.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: #0f161e; font-family: Consolas, sans-serif; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this helps you in understanding Ephemeral Containers.</span></p></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-80867381635996059532022-01-09T09:32:00.005+05:302022-01-09T09:32:31.665+05:30Kubernetes - Probes<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both;"><span style="font-family: verdana;">Multiple parts of an application running in multiple containers are hard to manage. A big reason is that there are many moving parts of that application that all need to work for an application to function. If a small part breaks, the system has to detect, route it and fix it. All this needs to be done automatically.</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Kubernetes provides us Health Checks to let a system know if the app is working or not. It should also make sure that if the app is not working, the requests should be routed and also the system should bring the application back to a healthy state.</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Kubernetes provides us with 3 types of probes</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Liveness Probe</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Readiness Probe</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Startup probe</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><b>Liveness probe</b> : This indicates whether the container is running or not. This means to check if the application is up and running inside the container. If this probe fails, the kubelet will kill the pod as defined by its restart policy. If the pod is not defined with the liveness probe, the default is success.</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Imagine a case where the application running inside the container has a deadlock. The app is hung at this moment but since the process is running, the requests are sent to this pod. This is where liveness probe comes into picture. K8s will hit the application as a part of liveness probe and based on the response the requests are sent. If the liveness probe fails the pod is restarted based on the restart policy that we define.the liveness probe looks as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@manja17-I13330 kubenetes-config]# cat liveness-pod.yml</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">apiVersion: v1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">kind: Pod</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">metadata:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> name: testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">spec:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> containers:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - name: test-ser</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> image: docker.io/jagadesh1982/testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> ports:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - containerPort: 9876</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> livenessProbe:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> initialDelaySeconds: 2</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> periodSeconds: 5</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> httpGet:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> path: /info</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> port: 9876</span></div><div class="separator" style="clear: both;"><b><span style="font-family: verdana;"><br /></span></b></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><b>Readiness Probe</b> : This probe indicates if the container is ready to accept the request are not. This probe is designed to let kubernetes know whether the app is ready to serve the traffic or not. If the readiness probe fails, the endpoint controller removes the pods IP address from the endpoint of all services that match the pod. Kubernetes makes sure the readiness probe passes before allowing a service to send traffic to the pod. The default state of the readiness probe before the initial delay is Failure. If the container does not specify any readiness probe, the default statue is Success. A simple readiness probe looks as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@manja17-I13330 kubenetes-config]# cat readiness-pod.yml</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">apiVersion: v1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">kind: Pod</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">metadata:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> name: testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">spec:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> containers:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - name: test-ser</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> image: docker.io/jagadesh1982/testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> ports:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - containerPort: 9876</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> readinessProbe:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> initialDelaySeconds: 1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> periodSeconds: 5</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> timeoutSeconds: 1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> successThreshold: 1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> failureThreshold: 1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> exec:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> command:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - cat</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - /etc/nginx/nginx.conf</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><b>Startup probe</b> : This indicates whether the application in the container is started or not. If the Startup probe is defined , all other probes are disabled until the startup probe is successful. If the probe fails, the kubelet will kill the container based on the restart policy. Consider legacy applications where they require some time to startup which means the boot time is more or it may be a case where the first time initialization is more. In these cases setting up the live probe can be hard based on the time. This is where startup probe helps. A simple startup probe looks as below,</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">[root@manja17-I13330 kubenetes-config]# cat startup-pod.yml</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">apiVersion: v1</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">kind: Pod</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">metadata:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> name: testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">spec:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> containers:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - name: test-ser</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> image: docker.io/jagadesh1982/testing-service</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> ports:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> - containerPort: 9876</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> startupProbe:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> httpGet:</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> path: /info</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> port: 9876</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> failureThreshold: 30</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"> periodSeconds: 10</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">In the above code, the startup time is with failureThreshold * periodSeconds which means in the above case it is 30 * 10 = 300ms.</span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;"><br /></span></div><div class="separator" style="clear: both;"><span style="font-family: verdana;">Hope this helps in understanding the Probes available in kubernetes.</span></div></div><p></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-76292039639887479392022-01-09T09:07:00.000+05:302022-01-09T09:07:05.109+05:30Kubernetes - Restart Pods<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><p></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">There are many times where a developer needs to restart his application. When the application is deployed in a container/pod implementation like in kubernetes, the restart works in a different way. </span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">There are multiple ways to restart an application pod.</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">1.<b>Use the deployment rollout restart command as below</b></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl get deploy</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">NAME READY UP-TO-DATE AVAILABLE AGE</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">test-service-deploy 2/2 2 2 23m</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">Restart the deployment using below command,</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl rollout restart deployment test-service-deploy</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">deployment.apps/test-service-deploy restarted</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">Now we can see that the deployment is restarted </span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl get deploy</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">NAME READY UP-TO-DATE AVAILABLE AGE</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">test-service-deploy 2/2 2 2 1m</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><br /></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">2. <b>Modify the Env Variables of a deployment as below,</b></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl set env deployment test-service-deploy DEPLOY_DATE="$(date)"</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">deployment.apps/test-service-deploy env updated</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">Set env sets up a change in env variables , and set the env variable DEPLOY_DATE to the latest timestamp for the deployment and causes the pod to restart</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">3. <b>Scale Down or Up for the deployment</b></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl scale deployment test-service-deploy --replicas=0</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">deployment.apps/test-service-deploy scaled</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl scale deployment test-service-deploy --replicas=1</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">deployment.apps/test-service-deploy scaled</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #101820; font-family: Consolas, sans-serif;"><span style="background-color: white; font-size: 17.3333px; white-space: pre-wrap;">Note - We can’t just restart the pods alone, pods that are created as a part of deployment or replica set or replication controller can have the option to restart. </span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-46712357187470350772022-01-09T08:57:00.001+05:302022-01-09T08:57:07.966+05:30Kubernetes - Mounting a Host Path On To Pod<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw=s320" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="320" data-original-width="320" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3Jarqa_MvfK_7CP-PTmATz7rSjYEVIeNeOI0ZetcyxH7WP7EBSkrnhWYMAEnmtB42ZGyBhGzb65kWk024hbL7zCIewojtnj3nv2es6GHJzcXLqwZY5N8brNcdEX2cQHPTsIeV0nyraBot9iji48xH78nydXYjQtj9kA9Ry8EowOcKoZZvaOqjqEvCFw" width="320" /></a></div><p><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; white-space: pre-wrap;">We already know kubernetes provides us with multiple ways of saving data on the disk. We have seen volume types using emptyDir and memory. The other and most used volume type is the Hostpath. In this article we will see how we can use a host path on disk to mount on to the pod and save data from the pod to the host machine.</span></p><span id="docs-internal-guid-e36e28b3-7fff-325a-9da8-4b17de114fe2"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">The Host path details are defined in the volumes and attached to the pod using the VolumeMounts. Check the below example,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] cat hostpath-volume.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> name: myapp</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: my-app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> image: nginx</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> ports:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - containerPort: 8080</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> volumeMounts:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: my-volume</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> mountPath: /app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> volumes:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: my-volume</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> hostPath:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> path: /Volumes/Working/k8s/test</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In the above code, we are using the hostpath /Volumes/Working/k8s/test directory on the host machine to be mounted to the container on /app location. The name of the mount is my-volume</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Run the code to see if the pod is running as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl get pods</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">NAME READY STATUS RESTARTS AGE</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">myapp 1/1 Running 0 30s</span></p><div><span><br /></span></div><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Login to the pod and create few files for testing as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl exec myapp -c my-app -it -- bash</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">root@myapp:/# df -hT</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Filesystem Type Size Used Avail Use% Mounted on</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">overlay overlay 59G 4.5G 51G 8% /</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">tmpfs tmpfs 64M 0 64M 0% /dev</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">tmpfs tmpfs 987M 0 987M 0% /sys/fs/cgroup</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">grpcfuse fuse.grpcfuse 47G 33G 14G 71% /app</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">/dev/vda1 ext4 59G 4.5G 51G 8% /etc/hosts</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">shm tmpfs 64M 0 64M 0% /dev/shm</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">tmpfs tmpfs 987M 12K 987M 1% /run/secrets/kubernetes.io/serviceaccount</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">tmpfs tmpfs 987M 0 987M 0% /sys/firmware</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">root@myapp:/# cd /app/</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">root@myapp:/app# touch hai hello</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">root@myapp:/app# exit</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">exit</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Now check on the host path to confirm as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[jagadishmanchala@Jagadish-theOne:k8s] ll test/</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">total 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">-rw-r--r-- 1 jagadishmanchala staff 0 Dec 28 12:30 hai</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">-rw-r--r-- 1 jagadishmanchala staff 0 Dec 28 12:30 hello</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this helps in understanding the hostpath Volume.</span></p><div><span style="background-color: white; color: #101820; font-family: Consolas, sans-serif; font-size: 13pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></span>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-895691427742344285.post-23870693857311911272022-01-07T15:12:00.000+05:302022-01-07T15:12:00.939+05:30Kubernetes Quality of Service ( Qos classes )<p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgBHQ0_UPRxtz2VrrYi1b4l8iHF2WsIRjwZjd2u8IrzKpWP8pSUYL6vMOYs4rdoP9Cnrzxitn0F_q2YMW3w38OT4Y57gQbTdCg79X6Kaj49HKHVd_isdGm8Ok_hBpurotdH_3s0pW0v2WEVL2IY_aAt_ncVsvk4iHCbPWhoFTi5w_wgF-mtUvuYiYKl=s1600" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1600" height="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEgBHQ0_UPRxtz2VrrYi1b4l8iHF2WsIRjwZjd2u8IrzKpWP8pSUYL6vMOYs4rdoP9Cnrzxitn0F_q2YMW3w38OT4Y57gQbTdCg79X6Kaj49HKHVd_isdGm8Ok_hBpurotdH_3s0pW0v2WEVL2IY_aAt_ncVsvk4iHCbPWhoFTi5w_wgF-mtUvuYiYKl=s320" width="320" /></a></div><p></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Quality of service (Qos) class is a concept which determines the scheduling and eviction priority of pods. We all know that if the underlying worker node has issues, the pods running on them are moved to other nodes.This means if there is any issue with the underlying nodes, the pods are evicted. The priority of this eviction is defined by the Qos. Also this class talks about the decisions taken by the scheduler to schedule the pods on nodes.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">There are 3 QoS Classes in k8s, </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Guaranteed</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Burstable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">BestEffort</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">All types of kinds ( deployments, stateful sets, jobs and daemonsets ) in kubernetes accept a request and limit for 3 types of compute resources: cpu, memory and ephemeral-storage. When the pod is being scheduled on a node, it first checks for the node which has the compute resources to fulfill the “request” of that pod. During the scheduling of pods, the limits will be ignored. The limits and requests are set as in below image</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span id="docs-internal-guid-3bdbb6b8-7fff-ec9b-8741-b7a56cefb06e" style="text-align: start;"><span style="background-color: white; color: #707070; font-family: Arial; font-size: 12pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 288px; overflow: hidden; width: 624px;"><img height="288" src="https://lh5.googleusercontent.com/oQHTq_NSHYz4jxAWK_ouNG1LXNQ0bI13NhUWIY04MZAjkyGWVpSnIoOuAsp9cpaOW-uivaNCGvoBIQE3w1AevHPijNSoSGPdmPy4sIv7Bpdh1rdhhNCWf5mC7gYJ9Gbv6UCDuLrb" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Pods are scheduled as one of the Quality of Class based on following characteristics</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><br /></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Guaranteed Pods</b>:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Pod is guaranteed if every container in the pod has</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Explicit requests and limits for both memory and cpu</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Both requests and limits defined for a container are same</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] cat guaranteed-pod.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> name: guaranteed</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> - name: container</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> image: busybox</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> command: [ /bin/sleep, 1d ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> resources:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> limits:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 100m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 10Mi</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> requests:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 100m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 10Mi</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl describe pod guaranteed | grep QoS</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">QoS Class: Guaranteed</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Guaranteed pods are scheduled only to nodes where they have enough resources to fulfil the CPU and memory requests. This is ensured by the scheduler by ensuring the sum of both memory and cpu requests for all containers is lower than the total capacity of the node</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Though there are cpu and memory available, there are cases where guaranteed pods are not scheduled to nodes if that node has a DiskPressure Condition. This condition comes if the available disk space or inodes on either the root file system or image storage hit the threshold. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Burstable Pod</b> :</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Pod is Burstable when:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Pod is burstable if every container in the pod has</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Explicit requests and limits for both memory and cpu</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Limits are greater than the requested amount for at least one container in pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] cat burstable-pod.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> name: burstable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> - name: container</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> image: busybox</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> command: [ /bin/sleep, 1d ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> resources:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> limits:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 100m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 10Mi</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> requests:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 100m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl describe pod burstable | grep QoS</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">QoS Class: Burstable</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">During Scheduling , k8s will not take memory into consideration when placing this pod as there simply is no memory reservation. The k8s scheduler cannot ensure that this Class pods are deployed to nodes that have enough resources for them.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">If there is no BestEffort class pod on a node, these pods are killed before Guaranteed Class pods when they reach their limit.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Best Effort Pod</b>:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">A pod is best effort if any container in that pod does not have any explicit memory or cpu requests</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] cat besteffort.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">apiVersion: v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">kind: Pod</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">metadata:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> name: besteffort</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">spec:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> containers:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> - name: container</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> image: busybox</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> command: [ /bin/sleep, 1d ]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> resources:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> limits:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> requests:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> cpu: 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> memory: 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">[jagadishmanchala@Jagadish-theOne:k8s] kubectl describe pod besteffort | grep QoS</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">QoS Class: BestEffort</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">These Class pods are not guaranteed to be managed on to nodes that have enough resources for them. They are able to use any amount of free resources on the node. This can sometimes cause resource issues as these class pods use unlimited resources.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">These classes of pods are the lowest priority and will be killed first if there are resource constraints.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Hope this helps in understanding the Kubernetes Quality of Class.</span></p><div><br /></div>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-49236453942445769682022-01-07T14:59:00.001+05:302022-01-07T14:59:09.196+05:30Docker Networking - Macvlan<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhBGg8zOB3XnPvIrjxGsNQgX5ehkGedg7N43YOV1_B_8eo2j9HWmZw5os-OLe9My923PQykc2oq7wLCp1ac9xSFWddgKG9lyflcYe7B5W7LiM_cihtPzXF8sOM_XQnz7QmuPWPtb1OZSyIhi4LiNj_pqigzVoUQv_PTfUbxle7Wv-fbKHDO0AtjHvEr=s405" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" height="195" src="https://blogger.googleusercontent.com/img/a/AVvXsEhBGg8zOB3XnPvIrjxGsNQgX5ehkGedg7N43YOV1_B_8eo2j9HWmZw5os-OLe9My923PQykc2oq7wLCp1ac9xSFWddgKG9lyflcYe7B5W7LiM_cihtPzXF8sOM_XQnz7QmuPWPtb1OZSyIhi4LiNj_pqigzVoUQv_PTfUbxle7Wv-fbKHDO0AtjHvEr=s320" width="320" /></a></div><span id="docs-internal-guid-4dc73739-7fff-75cc-6929-771cedcf7576"><span style="font-family: verdana;"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">While working with Docker Containers, we have seen how we can use network types provided by Docker from NONE to BRIDGE. But did we ever try to configure a Docker container or run a container connected directly to the underlying physical network?</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Why do we need to connect an application or Container directly to the Underlying network?. There can be legacy applications where they have to connect to the underlying physical network for faster routing of requests. If we want the same legacy application to be moved to a container, we need a way to let the container connect to the physical network rather than a Vlan provided by Docker dockerO bridge network.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Docker provides a macvlan network type which satisfies the need. When we use the macvlan network driver it assigns a MAC address to each container virtual network interface making it appear to be a physical network interface directly connected to the physical network. The advantage is that the latency in macvlan networks is low since packets are routed directly from the docker host network interface to containers. In this article we will have how we can use a Macvlan network driver and attach to a container.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Check if Macvlan is available on the host machine or not?</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# lsmod | grep macv</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Check the existing docker networks available</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# docker network ls</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">NETWORK ID NAME DRIVER SCOPE</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">48909e557f1d bridge bridge local</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">fdf372ca609e host host local</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">09e36b50cb20 none null local</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">There is no macvlan network interface available. Check the network interfaces available using the ifconfig command,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# ifconfig</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet6 fe80::42:ccff:fe5d:434a prefixlen 64 scopeid 0x20<link></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> ether 02:42:cc:5d:43:4a txqueuelen 0 (Ethernet)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX packets 3727 bytes 201737 (197.0 KiB)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX errors 0 dropped 0 overruns 0 frame 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX packets 4947 bytes 39337043 (37.5 MiB)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet 172.31.35.163 netmask 255.255.240.0 broadcast 172.31.47.255</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet6 fe80::894:27ff:fe0e:7f73 prefixlen 64 scopeid 0x20<link></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> ether 0a:94:27:0e:7f:73 txqueuelen 1000 (Ethernet)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX packets 442113 bytes 446230278 (425.5 MiB)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX errors 0 dropped 0 overruns 0 frame 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX packets 191497 bytes 25180642 (24.0 MiB)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Create a macvlan network driver using the docker network command as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# docker network create -d macvlan --subnet=172.31.35.163/24 --gateway=172.31.35.1 -o parent=eth0 mac_net</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">7baebe9803f4a8ccd87f1a5dfeb783305e5247eaa811865a245bb7f953eb93fc</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Check the docker network available now?</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 169px; overflow: hidden; width: 624px;"><img height="169" src="https://lh6.googleusercontent.com/C9sqYgzcN72BNQehvJQSTRP5XTWJq-l3SmKIHlr-NZ_nk3HZdBlFOkZUQIRVfmcCyKLUktbWa3hcuzVIOa-RCFLcD7NpcZZs7SwvXgRhdYH1pYo2qLeOmWIT_iiS63ot3rpzbwDs" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">One important thing about this network mode is that we will be able to connect to other systems on the local network without any issues but the container will not be able to connect to the host and vice versa. This is a limitation of the macvlan interface and without any special support from the network switch the host will not be able to send packets to the macvlan interfaces. The workaround is to create another macvlan interface on your host and use that to communicate with containers.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Run the below commands to provide special support for the macvlan driver we created on the physical network switch ( basically creating a copy of the physical network interface )</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# ip link add mac0 link eth0 type macvlan mode bridge</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# ip addr add 172.31.35.163/24 dev mac0</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# ifconfig mac0 up</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Now check the ifconfig command to see a new physical interface as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# ifconfig</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">mac0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet 172.31.35.163 netmask 255.255.255.0 broadcast 0.0.0.0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> inet6 fe80::60a2:39ff:fe53:d37e prefixlen 64 scopeid 0x20<link></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> ether 62:a2:39:53:d3:7e txqueuelen 1000 (Ethernet)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX packets 0 bytes 0 (0.0 B)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> RX errors 0 dropped 0 overruns 0 frame 0</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX packets 5 bytes 430 (430.0 B)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</span></p><div><span><span style="font-family: verdana;"><br /></span></span></div>Note : </span><span style="font-family: verdana;"></span><span style="font-family: verdana; font-size: 13pt; white-space: pre-wrap;">To Delete the new network interface : ip link delete mac0</span></span><div><span style="font-family: verdana;"><span style="font-size: 17.33333396911621px; white-space: pre-wrap;"><br /></span></span><span><span style="font-family: verdana;"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Now lets run a container with the macvlan driver created as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# docker run --net=mac_net -d --ip=172.31.35.49 -p 81:80 nginx</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Unable to find image 'nginx:latest' locally</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">latest: Pulling from library/nginx</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">eff15d958d66: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">1e5351450a59: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">2df63e6ce2be: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">9171c7ae368c: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">020f975acd28: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">266f639b35ad: Pull complete</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Status: Downloaded newer image for nginx:latest</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">c75b50c4370c013be1ffa8ebc97175dee7c06fa0e49d499ad3e306e555e76b7c</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">We have created a container with the macvlan driver created above (mac_net) with ip address 172.31.35.49. Now once the container is up and running, we can run the curl command directly on the ip address to see the nginx page as below</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-35-163 foo]# curl 172.31.35.49</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><!DOCTYPE html></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><html></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><head></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><title>Welcome to nginx!</title></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><style></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">html { color-scheme: light dark; }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">body { width: 35em; margin: 0 auto;</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">font-family: Tahoma, Verdana, Arial, sans-serif; }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"></style></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"></head></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><body></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><h1>Welcome to nginx!</h1></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><p>If you see this page, the nginx web server is successfully installed and</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">working. Further configuration is required.</p></span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><p>For online documentation and support please refer to</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><a href="http://nginx.org/">nginx.org</a>.<br/></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Commercial support is available at</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><a href="http://nginx.com/">nginx.com</a>.</p></span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><p><em>Thank you for using nginx.</em></p></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"></body></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"></html></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 13pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this Helps in Understanding the Macvlan Driver in Docker. More to Come</span></p></span></span><p></p></div>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-44802079729545375982021-05-27T10:29:00.001+05:302021-05-27T10:29:11.062+05:30Understanding Docker Resource Management<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s405/docker.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s320/docker.PNG" width="320" /></a></div><span style="caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">Docker allows you to set the limit of memory, CPU and disk on the container.</span><span style="caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">On a linux machine lets run a container by setting the memory to 50MB as below,</span><span id="docs-internal-guid-2ced4bd8-7fff-be0c-f455-cb40f058d25e" style="caret-color: rgb(0, 0, 0); text-size-adjust: auto;"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 centos]#docker run --rm --memory 50mb alpine free -m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">total </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">used </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">free </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">shared buff/cache available</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Mem: </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">989 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">565 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">141 0 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">281 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">296</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Swap: </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Now when we run the “free -m” on the host machine, we can see the same output as above,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 centos]# free -m</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">total </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">used </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">free </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">shared buff/cache available</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Mem: </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">989 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">499 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">175 19 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">314 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">329</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Swap: </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0 </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">0</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">If we observe, the container memory is set with 50mb but still we see a different memory value. This is a very important thing to understand, docker shows all available memory as container memory. The default memory for a container in Mac OSX is 2gb and it will show all available memory of the host as container memory in linux. If we want to see the amount of memory allocated to the container , we need to check the allowed memory of the container from /sys/fs/cgroup/memory/memory.limit_in_bytes file from inside the container as below,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 centos]# <span style="color: #2b00fe;">docker run --rm --memory 50mb alpine cat /sys/fs/cgroup/memory/memory.limit_in_bytes</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">52428800</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">The important thing we need to understand is that a container has no resource constraints and can use as much of a given resource as the host kernel scheduler allows. It is the responsibility of the developer to control how much memory, or CPU a container can use. This can be set using the runtime configuration flags for the docker run command. In this article, we will see how resources like memory and CPU are managed. Docker allocates resources from Host with 3 resources,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">RAM</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CPU</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">I/O Bandwidth</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Docker Memory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">Docker provides us various ways in setting memory and swap to the container using the run command. The memory flags available for setting in the Docker run command are,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--memory : Hard limit of memory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--memory-reservation : soft limit of memory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--memory-swap : Swap setting </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--oom-kill-disable : OOM kill disable</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Soft and Hard limits - Docker memory can be set in either soft and hard settings. The hard and soft limits can be set using the “--memory-reservation” and “--memory” flags to the run command. For example, if we set the hard limit as 250mb and the soft limit as 230mb, this means the memory consumption of the process running inside the container can use upto 250mb of memory and can rise from that. This limit can be considered as a warning limit. If we set a soft limit as 230mb and hard limit as 250mb , the process inside the container can upto 230mb and cross that but it cannot cross 250mb.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">An example to set hard limit and soft limit looks as,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: blue; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker run -d -p 8081:80 --memory-reservation="256m" --memory="256m" nginx</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Now if we run the above command, </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-11-133]# </span><span style="color: blue; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker run --memory 50m --rm -it progrium/stress --vm 1 --vm-bytes 62914560 --timeout 2s</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] using backoff sleep of 3000us</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] setting timeout to 55s</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] --> hogvm worker 1 [6] forked</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] allocating 62914560 bytes ...</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] touching bytes in strides of 4096 bytes ...</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] freed 62914560 bytes</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] touching bytes in strides of 4096 bytes</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] (416) <-- worker 6 signalled normally</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: info: [1] successfully run completed in 2s</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">We can see the through the container is allocated with 50mb, the stress command still is able to use 62mb of memory. This should not be the case, if the container is set with 50mb and once the 50mb is allocated, it should throw a OOM error. But it did not happen, this is where swap comes into picture.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">If we run a container with a memory limitation and no swap definition, then the container uses a hard limit of 50mb and swap of 100mb which means the container has 150mb of memory. The swap is set to the container using the “--memory-swap” flag to container run command. The swap will always be set with the double the amount of memory set. If we set the memory as 10mb , the swap will automatically set to 20mb.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Now lets run the same above container run by adding the swap command as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-11-133]# </span><span style="color: blue; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker run --memory 50m --memory-swap 50m --rm -it progrium/stress --vm 1 --vm-bytes 62914560 --timeout 2s</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] using backoff sleep of 3000us</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] setting timeout to 2s</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [1] --> hogvm worker 1 [6] forked</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] allocating 62914560 bytes ...</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: dbug: [6] touching bytes in strides of 4096 bytes ...</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: FAIL: [1] (416) <-- worker 6 got signal 9</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: WARN: [1] (418) now reaping child worker processes</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: FAIL: [1] (422) kill error: No such process</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">stress: FAIL: [1] (452) failed run completed in 0s</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Now though the memory and swap is set, the container should not be killed but should run until 150mb ( 50mb hard limit and 100mb swap, since the swap will be set with double of the memory). So the container has 150mb, but still the container exits. There are few limitations with how docker allocates memory and swap to a container,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Note : If both memory and memory-swap are set to the same value, the hard limit is the amount set for memory but swap will never be used. In the above case, the hard limit is set to 50mb and swap is set to 50mb but when the container runs the hard limit of 50mb is set and swap is ignored.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Note : If memory and memory-swap are given different values then only swap will be used.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>For example</b>, </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">memory=20mb & memory-swap=20mb : swap will never be used since the hard limit is set to 20mb and swap will be ignored in this case.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">memory=20mb & memory-swap=30mb : in this case, the hard limit for memory is 20mb and swap is 10mb. </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">If --memory-swap is explicitly set to -1, the container is allowed to use unlimited swap, up to the amount available on the host system.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">OOM Errors - By default, if an out-of-memory (OOM) error occurs, the kernel kills processes in a container. We can use the flag “--oom-kill-disable” to change this behavior. If we set the memory and memory-swap, and when the OOM error occurs the kernel kills the processes inside the container.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">If we set the parameter “--oom-kill-disable” along with container run, if the hard limit is reached, the process running inside the container will be killed and also the container will get hung. Care full in using the --oom-kill-disable as it can hang the containers and also our host linux prompts.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">CPU Shares</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CPU is also another important resource that needs to be used effectively with containers. By default each container can have unlimited CPU cycles from the host machine. We need to set various constraints to limit a given container access to the host machines CPU cycles. The default CFS ( Completely fair processing ) scheduler is the default scheduler in linux now and will be used in setting and assigning CPU to the containers. The flags available for setting the CPU for the docker run command is,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--cpus : how much of the available cpu resources can a container use. if the host machine has 2 cpus and if we set the --cpus = "1.5", it means the container can use one and half of the cpus available on host.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--cpu-period and --cpu-quota : these 2 flags need to be used alongside. These values define the CPU CFS scheduler period. if we are using docker version > 1.13, the --cpus is used.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--cpusets-cpus : limits the CPU cores that a container can use. if we set the value as [0-3], which means the container can use first,second, third and fourth CPU. The first CPU starts with Zero(0). If we set the value as 0,1 this means the container can use CPUs 0 and 1.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--cpu-shares : the value specifies the container weight to use the CPU. the default value if 1024, so a greater value than this gives greater priority and lesser values gives less priority.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CPU limits are based on shares. These shares are a weight between how much processing time one process should get compared to another. If a CPU is idle, then the process will use all the available resources. If a second process requires the CPU then the available CPU time will be shared based on the weighting.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Below is an example of starting a container with different shares. The --cpu-shares parameter defines a share between 0-768.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">If a container defines a share of 768, while another defines a share of 256, the first container will have 75% share with the other having 25% of the available share total. These numbers are due to the weighting approach for CPU sharing instead of a fixed capacity.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #2b00fe;">docker run -d --name c768 --cpuset-cpus 0 --cpu-shares 768 benhall/stress</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #2b00fe;">docker run -d --name c256 --cpuset-cpus 0 --cpu-shares 256 benhall/stress</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">sleep 5</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker stats --no-stream</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker rm -f c768 c256</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">It's important to note that a process can have 100% of the share, no matter defined weight, if no other processes are running.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --cpu-shares</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --cpuset-cpus</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --memory-reservation</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --kernel-memory</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --blkio-weight (block IO)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --device-read-iops</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> --device-write-iops</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><b><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Disk I/O</span><span style="font-family: Verdana; font-size: 16pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></b></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Disk Read/Write is another resource that can be handled by the Container.By default Running container will have no restrictions on how many disk read/writes can be onde.We need to set various constraints to limit a given container access to the host machine Disk.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Docker provides us with the following parameters that we can pass with the run command to control the way Disk read/write and Disk IOPS can be handled.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--blkio-weight (block IO)</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--device-read-iops </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--device-write-iops</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--device-write-bps</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">--device-read-bps</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Lets run a container with disk read/write limitation set. First grab the disk available on your machine using the,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 centos]# <span style="color: #2b00fe;">lsblk</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">xvda 202:0 0 30G 0 disk</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">└─xvda1 202:1 0 30G 0 part /</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Now run a container as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 centos]# <span style="color: #2b00fe;">docker run -it --device-write-bps /dev/xvda:1mb centos</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@c5a5a6651ca2 /]#</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">In the above container run command we specified a device-read-bps option to limit the read rate to 1mb per second for </span><span style="background-color: #d1d1d1; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">/dev/xvda1</span><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> device.</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> Now run a dd command to create a file from inside the container as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">dd if=/dev/zero of=afile bs=1M count=100</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 centos]# <span style="color: #2b00fe;">docker ps</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">f165ae292cfe centos "/bin/bash" 9 minutes ago Up 9 minutes charming_davinci</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 centos]# <span style="color: #2b00fe;">docker exec f165ae292cfe dd if=/afile of=/dev/null</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">20480+0 records in</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">20480+0 records out</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">10485760 bytes (10 MB, 10 MiB) copied, 0.0429057 s, 244 MB/s</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Limiting CPU</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CPU is a very important resource other than memory and Disk. Allowing one container to use more CPU or container using less cpu can lead to changing performance behavior of the application running. Lets see how we can manage out docker container by using CPU efficiently</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Limit Cores : Docker provides us a way to limit the number of cores available to containers by using the --cpus flag</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Lock Container to Specific Core : Docker provides us a way to limit the number of cores available to the container. By default a docker container will use all the available cores for its use if available but if we want to lock our containers to a specific core , docker provides us the way.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Limit CPU time : Docker provides a way to limit the cpu time to ensure how often a process is able to interrupt the processor or a set of cores</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Shares and Weights : Rather than assigning or limiting cpus and cores, we can apply shares to the containers. This allows more critical containers to have priority over the cpu when needed.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">For example, if our host has 2 CPUs and wants to give a container access to one of them, we can run the container setting the --cpus=”1.0”. A container can run using</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #2b00fe;">Docker run -it --cpus=”1.0” centos /bin/bash</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">As we already discussed, rather than giving a whole CPU to the container we can assign a share to increase or reduce the container weight. Using the “--cpu-shares” flag we can assign a value to a container greater or lesser than 1024 (default) to increase or decrease the container weight. This will give the container access to greater or lesser proportion of the host machine CPU cycles. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #2b00fe;">docker run -d --cpu-shares=1024 centos</span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Similar to the memory reservation, CPU shares play the main role when computing power is scarce and needs to be divided between competing processes.</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this helps you in understanding the basic concepts of Docker resource utilization and management.</span></p></span>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com2tag:blogger.com,1999:blog-895691427742344285.post-14509799052158107962021-05-19T18:33:00.001+05:302021-05-19T18:33:04.042+05:30Grabbing Pid’s for Docker Container from Docker Host<p> </p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO2jzImdv-9MJXVNoqvQn3t9_S76w39mcy8kwRbAtXvztsSBgFdMrmKjMbULXn4brBI2OzpD17jZ5VUg7n5383AY68xM5ZoUYJMrvw6UZNDxq_tdUjBMlzzbM9aSpM4LkrjafSXpAodaU/s405/docker.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO2jzImdv-9MJXVNoqvQn3t9_S76w39mcy8kwRbAtXvztsSBgFdMrmKjMbULXn4brBI2OzpD17jZ5VUg7n5383AY68xM5ZoUYJMrvw6UZNDxq_tdUjBMlzzbM9aSpM4LkrjafSXpAodaU/s320/docker.PNG" width="320" /></a></div><p></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">It is known that in the Linux world, Every system has just one root process with PID 1 and PID 0 which is the root of the complete process tree of that system. Docker Cleverly uses the Namespaces to spin a new process tree, causing the process running inside the container to have no access to the parent process of the Docker Host. But the Host where Docker is running has a complete view of the Child PID namespace started by the Docker Engine.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Namespace allow us to create restricted view of system like the process tree, network interface, mount etc. So chroot restricts file system, namespace restricts other important system resources like network, process tree etc. So, a kernel namespace call wraps a global system resource in abstraction and isolation so that processes within that namespace think they have their own isolated instance of the global resource. Modifications done to that resource inside the namespace are not visible to the original resource being used by host machine or other namespaces.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The PID Namespace provides a consistent and unique resource name in place of host dependent resource name. This way pids inside the container are assigned a unique naming manner that are localised to the container. The naming can be the same as the way a traditional host machine provides its pids but the ones that are provided by containers are unique to processes running inside the container. This way the resource naming conflicts are removed.As a result, processes are created inside of a container and spend their entire lifetimes in the context of that container; they are not allowed to leave one container and join another.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Lets see how docker uses some sort of translation hash table between the pids of container and how they are viewed by the host</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ansible tmp]# </span><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>docker run -d alpine sleep 200</b></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">6ffcbdba3fab640b0fb8f71626f558382ddb6816fd974c2153f18b2dcede3c08</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ansible tmp]# </span><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>docker ps</b></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ID IMAGE COMMAND CREATED STATUS PORTS NAMES</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">6ffcb** alpine "sleep 200" 2 minutes Up kind_mestorf</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>Check the PID of the Running Docker Container using,</b></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ansible tmp]# docker inspect --format "{{ .State.Pid }}" 6ffcbdba3fab</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10522</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>Check the Pid details on the Host machine using</b></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ansible tmp]# ps -fp 10522</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">UID PID PPID C STIME TTY TIME CMD</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">root 10522 10503 0 14:39 ? 00:00:00 sleep 200</span></p><p style="text-align: justify;"><span style="font-family: Verdana;"><span style="font-size: 14.6667px; white-space: pre-wrap;"><b>Get the environ details of the PID from the /proc using</b>
[root@ansible tmp]# cat /proc/10522/environ
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOSTNAME=6ffcbdba3fabHOME=/root</span></span></p><p style="text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">This way we can grab details regarding the Running Process details in a container on the Host machine where this container is running. More to come. Happy Learning</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-82717450918555663142021-05-19T18:26:00.003+05:302021-05-19T18:26:49.387+05:30Understanding Container Runtime : CRI-O<p> <span style="caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">With different Container Runtimes available in the market, many tech giants came together to form a group called OCI. With this, there are standards defined on how container runtimes should work. Now there are many runtimes available of which CRI-O is one of them. This is an OCI based Implementation of Kubernetes Container Runtime Interface. This provides an Integration between the OCI Container Runtime and the Kubernetes Kubelet. </span></p><span id="docs-internal-guid-da996e47-7fff-a7ae-52c9-f0d9dde5ec86" style="caret-color: rgb(0, 0, 0); text-size-adjust: auto;"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">In this article, we will see how we can install and configure the CRI-O and perform the basic steps. Below are some of the following functionalities that the CRI-O provides us</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Support multiple image formats including the existing Docker image format</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Support for multiple means to download images including trust & image verification</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Container image management (managing image layers, overlay filesystems, etc)</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Container process lifecycle management</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Monitoring and logging required to satisfy the CRI</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Resource isolation as required by the CRI</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"> </p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #222222; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">We can call CRI-O as a best breed libraries as below,</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Runtime</b>: </span><a href="https://github.com/opencontainers/runc" style="text-decoration-line: none;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">runc</span></a><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> (or any OCI runtime-spec implementation) and </span><a href="https://github.com/opencontainers/runtime-tools" style="text-decoration-line: none;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">oci runtime tools</span></a></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Images</b>: Image management using </span><a href="https://github.com/containers/image" style="text-decoration-line: none;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">containers/image</span></a></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Storage</b>: Storage and management of image layers using </span><a href="https://github.com/containers/storage" style="text-decoration-line: none;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">containers/storage</span></a></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Networking</b>: Networking support through use of </span><a href="https://github.com/containernetworking/cni" style="text-decoration-line: none;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">CNI</span></a></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Install the crictl tool</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121]: VERSION=</span><span style="background-color: #f6f8fa; color: #032f62; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">"v1.17.0"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121]: wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121]: sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin</span></p><p dir="ltr" style="line-height: 1.74; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: #f6f8fa; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121]: rm -f crictl-$VERSION-linux-amd64.tar.gz</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Run the image list</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-89-64]: /usr/local/bin/crictl images</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">FATA[0002] failed to connect: failed to connect, make sure you are running as root and the runtime has been started: context deadline exceeded </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">crictl by default connects to Unix: unix:///var/run/dockershim.sock or Windows: tcp://localhost:3735. For other runtimes, use:</span></p><ul style="margin-bottom: 0px; margin-top: 0px; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><a href="https://containerd.io/" style="text-decoration-line: none;"><span style="background-color: transparent; color: #0366d6; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">containerd</span></a><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">: unix:///run/containerd/containerd.sock</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><a href="https://cri-o.io/" style="text-decoration-line: none;"><span style="background-color: transparent; color: #0366d6; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">cri-o</span></a><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">: unix:///var/run/crio/crio.sock</span></p></li><li aria-level="1" dir="ltr" style="color: #24292e; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="background-color: white; line-height: 1.38; margin-bottom: 12pt; margin-top: 0pt;"><a href="https://github.com/kubernetes/frakti" style="text-decoration-line: none;"><span style="background-color: transparent; color: #0366d6; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">frakti</span></a><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">: unix:///var/run/frakti.sock</span></p></li></ul><p dir="ltr" style="background-color: white; line-height: 1.38; margin-bottom: 0pt; margin-top: 3pt; padding: 0pt 0pt 12pt;"><span style="background-color: transparent; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">I just started the Docker service here, and things started working fine for me. </span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Create a Container Image Spec</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-89-64]: cat pod.json</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">{</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "metadata": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "name": "nginx-sandbox",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "namespace": "default",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "attempt": 1,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "uid": "hdishd83djaidwnduwk28bcsb"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> },</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "log_directory": "/tmp",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "linux": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Run the json File</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-89-64]: crictl runp pod.json</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">e4cdd5cfd7daf91e4f6c136f7f9d704ba6c3e587ed6e4a8f354cf4a37ec58076</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Check the Running Pods using</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-42-175 centos]# crictl pods</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">POD ID CREATED STATE NAME NAMESPACE ATTEMPT</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">e4cdd5cf* 2 minutes Ready nginx-sandbox default 1</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Inspect the Running Pod as below</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-42-175 centos]# crictl inspectp e4cdd5cfd7daf</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">{</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "status": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "id": "e4cdd5cfd7daf91e4f6c136f7f9d704ba6c3e587ed6e4a8f354cf4a37ec58076",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "metadata": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "attempt": 1,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "name": "nginx-sandbox",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "namespace": "default",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "uid": "hdishd83djaidwnduwk28bcsb"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> },</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "state": "SANDBOX_READY",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "createdAt": "2020-09-02T04:16:42.627919195Z",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "network": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "ip": "10.88.0.2"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> },</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "linux": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "namespaces": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "options": {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "ipc": "POD",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "network": "POD",</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "pid": "POD"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> },</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "labels": {},</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> "annotations": {}</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> }</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>Pull an Image using</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-42-175 centos]# crictl pull busybox</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Image is up to date for docker.io/library/busybox@sha256:c2d41d2ba6d8b7b4a3ffec621578eb4d9a0909df29dfa2f6fd8a2e5fd0836aed</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><b>List the Existing Images using</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-42-175 centos]# crictl images</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">IMAGE TAG IMAGE ID SIZE</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">docker.io/library/busybox latest edabd795951a0 1.45MB</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">More to Come, happy learning :-)</span></p></span><br class="Apple-interchange-newline" style="caret-color: rgb(0, 0, 0); text-size-adjust: auto;" />జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-85089269880238526672021-05-07T10:34:00.006+05:302021-05-07T10:34:56.287+05:30Ansible With Windows<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSYIeWy01Fi6e-Sz8Iy3xypFPWQM5vLwcBDS2u8ehFSIy-MKC5Qx2xSYBfiAlxqVS53gK-Lzs1pSD-IhZ4-vACuy1ks0bpfg0gGdmIfsZru022EeIUsJf3yiut_qp6zqJZfDqJRckCko/s1125/ansible.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="152" data-original-width="1125" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSYIeWy01Fi6e-Sz8Iy3xypFPWQM5vLwcBDS2u8ehFSIy-MKC5Qx2xSYBfiAlxqVS53gK-Lzs1pSD-IhZ4-vACuy1ks0bpfg0gGdmIfsZru022EeIUsJf3yiut_qp6zqJZfDqJRckCko/s320/ansible.png" width="320" /></a></div><span id="docs-internal-guid-03f39430-7fff-657b-0b9a-642c71106b51"><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ansible as we know is an excellent automation tool for *nix based machines. But with recent implementations of ansible, it starts supporting windows based systems too. Using the Linux system as our Ansible Control machine and having windows machines as our remote machine, we can manage the systems. In this document we will see how we can manage a windows machine from a Linux Based Ansible control machine.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">As we know that python is a mandatory requirement for ansible to work in linux machines but in windows, we need to have windows modules installed on the windows machine. There are certain requirements that windows machines to satisfy if we need to get ansible to work,</span></p><br /><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ansible Can generally manage windows versions under current and extended support from Microsoft. </span><span style="color: #404040; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ansible can manage desktop OSs including Windows 7, 8.1, and 10, and server OSs including Windows Server 2008, 2008 R2, 2012, 2012 R2, 2016, and 2019.</span></p></li></ul><br /><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ansible requires Powershell 3.0 or newer and at least .NET 4.0 to be installed on the windows Host.</span></p></li></ul><br /><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">A WinRM listener should be created and activated on the remote window machines.</span></p></li></ul><br /><ul style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: disc; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">A Python package Pywinrm should be installed on the Linux Ansible Control machine.</span></p></li></ul><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Configuration on the Window Remote Machine</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Check Powershell version</span><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> : Get the Powershell Version by running the command in the powershell prompt,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Windows\system32> (Get-Host).Version</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Major Minor Build Revision</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">----- ----- ----- --------</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">5 1 14393 4350</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Ensure WinRM ports are open</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We also need to make sure both ports 5985 and 5986 are open in the firewall On Both Operating system and also on the network side. That is, now in order to access our windows machine over winRM and ansible will be able to execute playbook and tasks on your windows machine, we need to have these ports open. Check if ports are open are not using the below command on Powershell command line,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Windows\system32> Get-Process -Id (Get-NetTCPConnection -LocalPort 5985).OwningProcess</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Run the Powershell Script for configuring the Remoting For ansible</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Run the below powershell script provided by ansible to configure Remoting for ansible as below,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Users\Administrator> $url = "</span><a href="https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/Confi" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; text-decoration-line: underline; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;">https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/Confi</span></a></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">gureRemotingForAnsible.ps1"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Users\Administrator> $file = "$env:temp\ConfigureRemotingForAnsible.ps1"</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Users\Administrator> (New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PS C:\Users\Administrator> powershell.exe -ExecutionPolicy ByPass -File $file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Self-signed SSL certificate generated; thumbprint: DD2BFCC45E7503BC9C05BA9174326B593614C733</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">wxf : http://schemas.xmlsoap.org/ws/2004/09/transfer</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">a : http://schemas.xmlsoap.org/ws/2004/08/addressing</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">w : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">lang : en-US</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Address : http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ReferenceParameters : ReferenceParameters</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #24292e; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ok.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">The script is available at the location </span><a href="https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; text-decoration-line: underline; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;">here</span></a><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; text-decoration-line: underline; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;">.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Configuration on the Ansible Control machine</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">The only one thing other than installing and configuring ansible, we also need to install the pywinrm python module. To install the package we need to run the command,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121 ansible]# pip install pywinrm</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Configure the ansible.cfg and Hosts file</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Once all the necessary configurations are done, we can now configure the ansible.cfg and hosts file as below,</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Hosts file looks as,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121 ansible]# cat hosts </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[test]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">172.31.23.13</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[test:vars]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_user="Administrator"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_password="P@wDt3tLDAdUcV6UKx(.fw(Z7X35(@=Z"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_port="5986"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_connection="winrm"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_winrm_transport="basic"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ansible_winrm_server_cert_validation=ignore</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In the above hosts file, we can see the ip address of the machine under the label test. We also defined variables for all machines under the label test. We have the ansible user, password, port , connection and transport. When we are running ansible will use the variables defined in the hosts file.</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ansible.cfg looks as,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[defaults]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">inventory=hosts</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Execute our first ansible command to ping the windows machine as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121 ansible]# ansible test -m win_ping</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">172.31.23.13 | SUCCESS => {</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> "changed": false, </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> "ping": "pong"</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #404040; font-family: Verdana; font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Write a simple playbook for creating a new user by the name of John in the windows remote machine</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121 ansible]# cat win_play.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">---</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - hosts: test</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> tasks:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - name: Create a new User </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> win_user:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> name: john</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> password: MyP4ssw0rd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> state: present </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> groups:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> - Users</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> when: ansible_os_family == 'Windows'</span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Run the playbook and see the output as below,</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-30-121 ansible]# ansible-playbook win_play.yml </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PLAY [test] ***************************************************************** </span></p><br /><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">TASK [Gathering Facts] *****************************************************************ok: [172.31.23.13]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">TASK [Create a new User] *****************************************************************changed: [172.31.23.13]</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">PLAY RECAP *****************************************************************172.31.23.13 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Hope this article helps in managing windows hosts using ansible. More to Come. Happy learning :-)</span></p></span><p></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-17037205859467911422021-05-07T10:32:00.003+05:302021-05-07T10:41:34.042+05:30Jenkins - Container Model vs Traditional Model<p><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; text-align: justify; white-space: pre-wrap;"></span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvQ5xdsnDJuUjniuaqygL4ZrNsQkoH0igz_8YmaaSNf2idL-rjvlXcYK3lkZgS8an4XIMNTl7CtAd143rLOrs6WHiQ3pt3M_fTrH0GYLqY-2bVOcTtzBxwQcpreXqvwuPD3avN5EfB1Xg/s605/jen1.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="184" data-original-width="605" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvQ5xdsnDJuUjniuaqygL4ZrNsQkoH0igz_8YmaaSNf2idL-rjvlXcYK3lkZgS8an4XIMNTl7CtAd143rLOrs6WHiQ3pt3M_fTrH0GYLqY-2bVOcTtzBxwQcpreXqvwuPD3avN5EfB1Xg/s320/jen1.PNG" width="320" /></a></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: verdana;">As a part of onboarding Jenkins as our Automation Server, we did a analysis on how to run the Jenkins. We did research on whether Jenkins should run in a container or as a traditional deployment model. Below are the few points we identified.</span></div><p></p><span id="docs-internal-guid-d7a06431-7fff-ada9-84f0-314205edab6b"><div align="left" dir="ltr" style="margin-left: 2.25pt;"><table style="border-collapse: collapse; border: none;"><colgroup><col width="205"></col><col width="208"></col><col width="208"></col></colgroup><tbody><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><br /></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Containers deployment</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Traditional Deployment</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Installation Or Provisioning</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Fast</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Package is already available as a Container Image which helps in Installing Jenkins faster</span></p><br /></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Slow</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Package needs to be installed manually or by automation </span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Cluster Implementation</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Available</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Multiple Jenkins Master Containers can be combined by mounting a Single EBS volume to all Jenkins Containers. The EBS volume will have all the details of the Jenkins including jobs, Credentials etc. </span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Not Available</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">On a Traditional deployment, Multiple Jenkins masters cannot be combined. Multiple Ec2 Instances with Jenkins Servers can be connected with a single EBS volume but will have latency.</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Jenkins is a File Based Server which means for all operations jenkins will talk to the underlying disk for jenkins files.</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Resource Utilization</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High</span></p><br /><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Jenkins in Docker utilizes resources of the Host machine based on what we provide to the jenkins container. </span><span style="color: #333f50; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Better utilization of resources is achieved on a per Host basis as multiple builds are running via containers or jenkins slaves.</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Average</span></p><br /><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">The resource utilization is average since Jenkins master will be running on a Machine and slaves will be the one running the builds and test cases.</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Network</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Good</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since Jenkins is running in the standalone instance, the network performance will be very good. The communication happens directly </span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Average</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">In the case of Jenkins containers, the network performance is average because we have a docker bridge network in between which will take the request first before moving it to the Jenkins container. </span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">I/O </span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Average</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since the Jenkins container uses a shared storage mechanism like Efs and Ebs, I/O operations can be slow. Throughput issues might occur</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Good</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since the Host contains the jenkins files, access to them will be straightforward and the performance will be high</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High Availability</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Good</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">HA is by default provided with containers. Using various metrics, we can tell the container runtime to start another similar container to share load.</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since the Containers share the same Volume for data, the volume will be mounted to the ner containers that are started </span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Bad</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since the Jenkins servers will be running on Ec2 instances with their own disk, creating a new jenkins server in a different Ec2 instance and attaching to the existing jenkins Cluster is not possible.</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Attaching a single Volume for multiple Jenkins servers in separate Ec2 instances does not provide better performance</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #333f50; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Portability</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since Jenkins run on a Docker container, the containers are portable to run on other instances</span></p><br /></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Less</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since Jenkins is running inside a Ec2 instance, the portability requires a lot of work with downtime</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Cost</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Less</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since we are running containers on lesser number of Ec2 instances, the cost will be very lesser</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since the Jenkins server will be running on a Separate Ec2 instance, the price will be more when compared with Containers.</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Configuration</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since Jenkins will be installed in container, a Custom docker image need to be created , configured will all necessary plugins and then managed for every jenkins version</span></p><br /><br /></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Less</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Jenkins server on a Ec2 Instance can be upgraded from the console itself. We don't need any pre-configured packages. We just need to download the war file and deploy</span></p></td></tr><tr style="height: 235.873pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Load Sharing</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">High</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since we are running Jenkins inside a container, we can have multiple jenkins containers that are shared with load using a load balancer configured. The request goes to the load balancer first and from there it can share the request to the jenkins servers at the backend. Since the Jenkins servers in container share the same Disk volume, all details will be available by default</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Less</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Since Jenkins cannot be combined as a cluster, we have to run multiple Jenkins servers in separate ec2 instances which a load balancer cannot be attached to.</span></p></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #333f50; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Access Controls</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Same</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Access Control will be same for both container model and traditional models</span></p></td><td style="border-bottom: solid #000000 1pt; border-color: rgb(0, 0, 0); border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-style: solid; border-top: solid #000000 1pt; border-width: 1pt; overflow-wrap: break-word; overflow: hidden; padding: 5pt; vertical-align: top;"><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Same</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Access Control will be same for both container model and traditional models</span></p></td></tr></tbody></table></div></span>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-32659889768371257522021-05-07T10:30:00.002+05:302021-05-07T10:30:32.988+05:30JIRA Cluster Replication Issue - Solved<p> <span style="color: #1f497d; font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">As a part of onboarding Jira to our organization, we used JIRA Data Center edition with 4 nodes. Once the Cluster is configured and after attaching load balancer to the cluster, we observed a warning on the console. We can see the Warning “Cluster Cache Replication Health” check failed.</span></p><span id="docs-internal-guid-e817ab0f-7fff-ffa9-194d-a33f416e1c12"><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Upon researching and doing a lot of trials, we were able to solve this issues. Here are few things to do if missing,</span></p><ol style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 12pt;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Jira requires communication between the cluster nodes to communicate and replicate cache data. The cluster nodes talk to each other using TCP/IP communication on the Port 5071. So we have to open the 5701 port on all nodes by either opening the iptables or firewalld.</span></p></li><li aria-level="1" dir="ltr" style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 0pt;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Jira uses Ehcache as the cache technology. We have to open the ports by which the Ehcache cache replication happens. The ports include</span></p></li></ol><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ehcache - 40001 - For inter node communication in Data Center</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Ehcache - 40011 - set by default in JIRA 7.13 or higher</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">All these 3 ports need to be open in all nodes of the cluster.</span></p><br /><ol start="3" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Opening these 3 ports does not work. We have to tell Jira to use these ports for the cluster communication and cache replication. For this we have to modify the cluster.properties files in all nodes with below content.</span></p></li></ol><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> [root@GLGBLN-ST931512 jira]# cat cluster.properties</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # This ID must be unique across the cluster</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> jira.node.id = node-3</span></p><br /><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> # The location of the shared home directory for all Jira nodes</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> jira.shared.home = /app/atlassian/application-data/shared</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> ehcache.listener.port = 40001</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> ehcache.object.port = 40011</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: #1f497d; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><ol start="4" style="margin-bottom: 0; margin-top: 0; padding-inline-start: 48px;"><li aria-level="1" dir="ltr" style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; list-style-type: decimal; vertical-align: baseline; white-space: pre;"><p dir="ltr" role="presentation" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 0pt;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Even though the Ports are opened, we need to provide JIRA a reachable address of the nodes through which it can replicate Cache data. This is done by adding the ehcache.listner.hostname element to the cluster.properties as below</span></p></li></ol><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> ehcache.listener.hostName = 10.186.45.110</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #1f497d; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">So now the whole contents of the cluster.properties look as below</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@GLGBLN-ST931512 jira]# cat cluster.properties</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># This ID must be unique across the cluster</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">jira.node.id = node-3</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># The location of the shared home directory for all Jira nodes</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">jira.shared.home = /app/atlassian/application-data/shared </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.listener.hostName = 10.186.45.110</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.listener.port = 40001</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.object.port = 40011</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Upon adding everything it did not went well, still we are seeing the Cache Replication Exception and also UnknownHost Exception. Then i made 2 more changes as below,Added the hostname to /etc/hosts file </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@GLGBLN-ST931512 log]# cat /etc/hosts</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">#::1 </span><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">localhost localhost.localdomain localhost6 localhost6.localdomain6</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">10.186.45.110 localhost localhost.localdomain GLGBLN-ST931512.eu.novartis.net </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">We added the local machine IP address along with FQDN. </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Next made changes to the cluster.properties as below,</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">[root@GLGBLN-ST931512 jira]# cat cluster.properties</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># This ID must be unique across the cluster</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">jira.node.id = node-3</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"># The location of the shared home directory for all Jira nodes</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">jira.shared.home = /app/atlassian/application-data/shared</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.listener.hostName = </span><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">GLGBLN-ST931512.eu.novartis.net</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.listener.port = 40001</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="color: red; font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">ehcache.object.port = 40011</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;">Made sure the FQDN is added to the cluster.properties file. By this the Cluster Cache replication issue solved,</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt;"><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 409px; overflow: hidden; width: 624px;"><img height="409" src="https://lh6.googleusercontent.com/o6FQbVybL3lGIgpiJXB_YJiS7wm4PcArdRkBdtRUlBhXz7WXTFWlodrXjtWJ8vNv8r2Ah3Bd249bezZHjE9mEDbs_v99lQB3LpLs-gLnR0AMLhjUYAvMDG-9E068VllEMZ_v4HlQ" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p></span>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-58077601724430920722021-05-07T10:29:00.000+05:302021-05-07T10:29:03.421+05:30Understanding Container Runtimes - RunC<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s405/docker.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: black;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s320/docker.PNG" width="320" /></span></a></div><p></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Container Runtimes are softwares that facilitate the containers to run. The Implementation for Containers started some time back and led to many container runtimes having their own formats. This approach has proven to be difficult and users find it hard to adopt to new container runtimes or port to the newer ones from current ones.</span></p><p style="text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">OCI ( Open Container Initiative ) : Keeping the problem in mind, a bunch of tech giants came together and formed OCI. The job of this is to define standards for the container ecosystem that help users to work on different runtimes with simplicity since they follow a Standard OCI format.</span></p><p style="text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">As we already know we have 2 levels in container runtime: High level and low level. ContainerD is a high level runtime and RunC is a low level runtime.RunC is a lightweight, portable container runtime which provides full support for linux namespaces and all other security features.The security features include SeLinux, AppArmor, Seccomp and Cgroups. This is used for spawning and running containers according to OCI ( Open Container Initiative ).</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">RunC is a low level implementation of a container runtime and containerD is builds on top of that. This includes providing higher level features like image transfer, storage, container execution and supervision. It also includes network, storage attachments etc basically manages the complete life cycle of containers.</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">In this article we will see how to work with RunC,</span></p><p style="text-align: left;"><span style="font-family: Verdana; font-size: 14.6667px; white-space: pre-wrap;"><b>Download the RunC Source Code using the below github link </b></span><span style="font-family: Verdana; font-size: 14.6667px; white-space: pre-wrap;">[root@ip-172-31-9-137 runc]# git clone https://github.com/opencontainers/runc.git</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>Configure and Make the runC tool using the Source Code</b></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 runc]# cd runc</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 runc]# make BUILDTAGS=' '</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 runc]# make install</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 runc]# </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">install -D -m0755 runc /usr/local/sbin/runc</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Create a Container </span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 ~]# mkdir mycontainer</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 ~]# cd mycontainer/</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# mkdir rootfs</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# docker export $(docker create busybox) | tar -C rootfs -xvf -</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">After a root filesystem is populated you just generate a spec in the format of a </span><span style="background-color: transparent; font-family: Verdana; font-size: 10pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">config.json</span><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> file inside your bundle. </span><span style="background-color: transparent; font-family: Verdana; font-size: 10pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">runc</span><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> provides a </span><span style="background-color: transparent; font-family: Verdana; font-size: 10pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">spec</span><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> command to generate a base template spec that you are then able to edit. To find features and documentation for fields in the spec please refer to the </span><a href="https://github.com/opencontainers/runtime-spec" style="text-decoration: none;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">specs</span></a><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> repository.</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# runc spec</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# ll</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">total 4</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rw-r--r--. 1 root root 2652 Mar 18 10:00 config.json</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">drwxr-xr-x. 12 root root 137 Mar 18 09:59 rootfs</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 12pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><h3 dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Running Containers</span></h3><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Assuming you have an OCI bundle from the previous step you can execute the container in two different ways.If you used the unmodified runc spec template this should give you a sh session inside the container.</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"> </p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# cd /mycontainer</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# runc run mycontainer</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/ #</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"> </p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# runc create mycontainer</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# runc list</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ID PID STATUS BUNDLE CREATED OWNER</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">mycontainer 4796 created /root/mycontainer 2021-03-18 root</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"> </p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># </span><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>after 5 seconds view that the container has exited and is now in the stopped state by running the command </b></span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]#runc list</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"> </p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># </span><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>now delete the container</b></span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 mycontainer]# runc delete mycontainer</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: white; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Hope this helps in understanding the Usage of RunC in Running Container. More to Come, Happy learning.</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-22098693969257521382021-05-07T10:04:00.003+05:302021-05-07T10:04:49.699+05:30Understanding Container Runtimes - ContainerD<p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s405/docker.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: black;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s320/docker.PNG" width="320" /></span></a></div><p></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Container Runtimes are softwares that facilitate the containers to run. The Implementation for Containers started some time back and led to many container runtimes having their own formats. This approach has proven to be difficult and users find it hard to adopt to new container runtimes or port to the newer ones from current ones.</span></p><p><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">OCI ( Open Container Initiative ) : Keeping the problem in mind, a bunch of tech giants came together and formed OCI. The job of this is to define standards for the container ecosystem that help users to work on different runtimes with simplicity since they follow a Standard OCI format.</span></p><p><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">As we already know we have 2 levels in container runtime: High level and low level. ContainerD is a high level runtime and RunC is a low level runtime.RunC is a lightweight, portable container runtime which provides full support for linux namespaces and all other security features.The security features include SeLinux, AppArmor, Seccomp and Cgroups. This is used for spawning and running containers according to OCI ( Open Container Initiative ).</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">RunC is a low level implementation of a container runtime and containerD is builds on top of that. This includes providing higher level features like image transfer, storage, container execution and supervision. It also includes network, storage attachments etc basically manages the complete life cycle of containers.</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">In this article we will see how to work with ContainerD,</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;"><b>Install ContainerD:</b></span></p><p><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">wget https://github.com/containerd/containerd/releases/download/v1.3.4/containerd-1.3.4.linux-amd64.tar.gz</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Extract the Package </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">tar xvf containerd-1.3.4.linux-amd64.tar.gz</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Check the files in the extracted package</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ll</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">total 127024</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 53258624 Apr 16 01:18 containerd</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 7172096 Apr 16 01:18 containerd-shim</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 8790016 Apr 16 01:18 containerd-shim-runc-v1</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 8798208 Apr 16 01:18 containerd-shim-runc-v2</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 25063104 Apr 16 01:18 containerd-stress</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-rwxr-xr-x. 1 2000 2000 26987552 Apr 16 01:18 ctr</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>Run the ContainerD in background as,</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">./containerd &</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Pull a Container Image</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ./ctr image pull centos</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ctr: failed to resolve reference "centos": object required</span></p><p><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">This would give you an error saying you missed an object, because Containerd requires you to specify the object like the command below:
</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]#</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> ./ctr image pull docker.io/library/hello-world:latest</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 89px; overflow: hidden; width: 624px;"><img height="89" src="https://lh3.googleusercontent.com/97gksvSFvPtVKDiPCM_WHdJbSmdrqO9xNRkFMfihWa2wfezFe5Af_kiU0ArfaMYhEcqnzOM-PqDYKW5f_pJUOhjf5hZbAN4dAtIO9bJwCFYB7C4ijX6-L4_6FZFa4X4GPPVtZigl" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Check the Existing Images</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ./ctr image ls -q</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">docker.io/library/hello-world:latest</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;">Create a Container with the Existing Image</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ./ctr container create docker.io/library/hello-world:latest demo</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;">List the Running Containers</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ./ctr container list</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CONTAINER </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">IMAGE </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> RUNTIME </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">demo </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> docker.io/library/hello-world:latest. </span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">io.containerd.runc.v2</span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;">Delete the Image</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-32-147 bin]# ./</span><span style="background-color: transparent; font-family: Verdana; font-size: 11pt; font-style: italic; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ctr image remove docker.io/library/hello-world:latest</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">The output is not redirected to the CLI by default. Unlike Docker, we need to use the full path with the object every time we use a container image. Also, the image needs to be pulled before being able to run a container. Hope this helps in Understanding the basics of using ContainerD. More to Come, Happy Learning</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-18394920269150189232021-05-07T09:57:00.000+05:302021-05-07T09:57:15.351+05:30Container Plumbing<p> </p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s405/docker.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s320/docker.PNG" width="320" /></a></div><p></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Docker has increased the usage of Containers because of its simplest implementation. We know that the basement on which docker engine is built are two components - runc and containerd. Sometime back docker was built in a monolithic way and it created complexities. Later Docker started breaking the functionality into parts which we now call them as runC and containerd</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 12pt; margin-top: 12pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RunC : </span><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RunC is a lightweight, portable container runtime which provides full support for linux namespaces and all other security features. The security features include SeLinux, AppArmor, Seccomp and Cgroups. This is used for spawning and running containers according to OCI ( Open Container Initiative ). Learn How to use RunC Here</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ContainerD </span><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">: RunC is a low level implementation of a container runtime and containerD is builds on top of that. This includes providing higher level features like image transfer, storage, container execution and supervision. It also includes network, storage attachments etc basically manages the complete life cycle of containers. This is considered to be one of the best implementations as of now. Docker has donated the containerD to CNCF. There other implementations include along with containerD are rkt by CoreOS, CRI-O by Redhat and LXD by Linux Containers. Learn how to use ContainerD Here</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><br /></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The Docker Architecture would look some thing like below,</span></p><p dir="ltr" style="line-height: 1.3679999999999999; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 497px; overflow: hidden; width: 624px;"><img height="497" src="https://lh3.googleusercontent.com/rGoduuk5pYYwh05gnLrEwrJKgOF5cpUhJrdzfTfdUMIuVbdzdMCFESqgA0CKqLExQVm6DS0iCvdvKGU91IKT_ahYAfPUnjIrSx4pRo0ClgYsPm9ULjLLWhYlcDT_tCTMxWrk6x1t" style="margin-left: 0px; margin-top: 0px;" width="624" /></span></span></p><p><span style="caret-color: rgb(0, 0, 0); text-size-adjust: auto;"><br /></span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-67716243492435602462021-05-07T09:54:00.001+05:302021-05-07T09:54:28.962+05:30Understanding Docker ONBUILD Instruction<p> </p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s405/docker.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="247" data-original-width="405" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2BFs1paztdAQlx4p8HbTXDWdyjYLk8_N-V3v66n_vWQq5GKeZ94TPUGSkqpJRJDW_g9GCVGgJNyZGpcDbu29tjYbhRRZ8wscSTCqXn3mh3X2dmkUMg38LlDbsrwPaXagvardOfEW7D6w/s320/docker.PNG" width="320" /></a></div><p></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">While Dockerfiles are executed in order from top to bottom, you can trigger an instruction to be executed at a later time when the image is used as the base for another image. The result is you can delay your execution to be dependent on the application which you're building</span></p><p><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; font-weight: 700; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">ONBUILD</span><span style="font-family: Verdana; font-size: 11pt; font-variant-east-asian: normal; text-align: justify; vertical-align: baseline; white-space: pre-wrap;"> instruction works in a different way. This instruction will not run in this image but will set a trigger instruction to be executed at a later point. The Onbuild instruction in our example is “ONBUILD RUN mkdir /tmp/hello”. This instruction will not be executed in the current image but will be executed in the next image if the current build is used as Base image. Lets understand with an example,</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">In the First Dockerfile we have,</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-31-127 onbuild]# cat hello1/Dockerfile</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">FROM busybox</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RUN echo "hello world" >> /tmp/hello</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ONBUILD RUN mkdir /tmp/onbuild-hello</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">Now when i build the docker image hello1 with the above dockerfile as below,</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-31-127 hello1]# docker build -t hello1 .</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Sending build context to Docker daemon 2.048kB</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Step 1/3 : FROM busybox</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">latest: Pulling from library/busybox</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">53071b97a884: Already exists</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Digest: sha256:4b6ad3a68d34da29bf7c8ccb5d355ba8b4babcad1f99798204e7abb43e54ee3d</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Status: Downloaded newer image for busybox:latest</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">---> 64f5d945efcc</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Step 2/3 : RUN echo "hello world" >> /tmp/hello</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">---> Running in cadcbc51c329</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Removing intermediate container cadcbc51c329</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">---> c24d27271dee</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Step 3/3 : ONBUILD RUN mkdir /tmp/onbuild-hello</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">---> Running in 827b86347475</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Removing intermediate container 827b86347475</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">---> 1eae88c4a42d</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Successfully built 1eae88c4a42d</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Successfully tagged hello1:latest</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">Now if i run the image and see the contents of the container, we don’t see any directories created as defined in ONBUILD instruction</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-31-127 hello1]# docker run -it hello1 /bin/sh</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/ # ll /tmp</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/bin/sh: ll: not found</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/ # ls /tmp</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">hello</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/ # exit</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Now lets see the second Dockerfile,</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-31-127 hello2]# cat Dockerfile</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">FROM hello1</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RUN echo "second Build" >> /tmp/second</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Now in the second dockerfile, iam using the hello1 ( created above ) as base image. Now if we create the image and run a container from it, we can see things as below,</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-31-127 hello2]# docker run -it hello2 /bin/sh</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/ # ls /tmp</span></p><p dir="ltr" style="background-color: #151617; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">hello </span><span style="background-color: transparent; color: #5366ff; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">onbuild-hello</span><span style="background-color: transparent; color: #f6f6f6; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> second</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We can see that the onbuild-hello directory is created in the container created from the image whose base image is hello1. Now in order for the ONBUILD instruction to execute, we need to create a container whose base image has this ONBUILD instruction.</span></p><p dir="ltr" style="background-color: white; line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"> </p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In a production application, a nodejs application Dockerfile would look like below,</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[root@ip-172-31-9-137 tmp]# cat Dockerfile</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">FROM node:7</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RUN mkdir -p /usr/src/app</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">WORKDIR /usr/src/app</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ONBUILD COPY package.json /usr/src/app/</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ONBUILD RUN npm install</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ONBUILD COPY . /usr/src/app</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CMD [ "npm", "start" ]</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: #4a86e8; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Build the image and name the image as node:7-build. The result is that we can build this image but the application specific commands won't be executed until the built image is used as a base image. They'll then be executed as part of the base image's build. In the above Dockerfile, the instructions that start with ONBUILD will not be executed in the node:7-build but when this image is used as base, they will be executed.</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">With all of the logic to copy the code, install our dependencies and launch our application the only aspect which needs to be defined on the application level is which port(s) to expose. The advantage of creating OnBuild images is that our Dockerfile is now much simpler and can be easily reused across multiple projects without having to re-run the same steps improving build times.</span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;"><br /></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="color: #6fa8dc; font-family: Verdana;"><span style="font-size: 14.6667px; white-space: pre-wrap;">FROM node:7-onbuild
EXPOSE 3000</span></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana;"><span style="font-size: 14.6667px; white-space: pre-wrap;"><br /></span></span></p><p dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: Verdana; font-size: 11pt; white-space: pre-wrap;">Build the application as node-app and run the application,</span></p><p><span style="color: #4a86e8; font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">docker run -d --name node-app -p 3000:3000 my-nodejs-app</span></p><p><span style="font-family: Verdana; font-size: 11pt; text-align: justify; white-space: pre-wrap;">The ONBUILD instruction is very useful for automating the build of your chosen software stack.</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-64908785483862277592021-04-30T21:42:00.001+05:302021-05-07T10:36:35.070+05:30Life Before VPC<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" id="docs-internal-guid-636358ac-7fff-8427-d87d-8dd4fa96e253" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In this article we will understand what a VPC is, Components of VPC etc but before we will see what a life before VPC. it is advisable to read the basics of networking over <a href="https://jagadesh4java.blogspot.com/2020/01/introduction-to-network.html">here</a> before going through this.</span></div>
<span id="docs-internal-guid-550f83cb-7fff-ac85-cd0e-5eea10739a19" style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In the initial days of Cloud, there is a single network associated with every resource that we create. If we create multiple instances, all of these are configured in the same, single network. In order to restrict access to the instances, we have to configure access controls. Managing , configuring them with controls is a nightmare for admins.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Here comes VPC ( Virtual Private Cloud ), So What VPC does is it allocates part of the Cloud as private network, ie a separate,dedicated network for people to create their resources. Since we have our own network, we have control over IP addressing, who has access to network and when we are connecting to instance, we can connect to network first and then connect to them using private ips assigned to our instances.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We will not get a part of the aws physical network rather we get a virtualized network on the physical network. The VPC can be shared or dedicated. We have an option called “dedicated tenancy,'' by which we can ask aws to provide dedicated hardware that manages our network. Instead of using routers, we can ask aws to give router access that handle network. This is not that we get a physical router instead this is virtual one.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">VPC are created in a regions which means they stretch all the AZ’s and there Subnets are created. </span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A VPC is always in a region and it cannot stretch a region. If you want 2 vpc from different regions to connect we have to use VPC peering.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Subnets in a VPC can be created either public or private.Public Subnet have internet access, web facing application web servers etc and private subnet have no internet access or not allowing access to instances from internet, we keep them in private subnet</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">When we create a subnet , there is no public or private. We make them public or private by defining rules to access.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">IP CIDR</span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : IP CIDR talks about the number of ips that can be allocated in that ip range. Let's say we have an IP address 192.168.100.124. Now we know that the IP address is a 32 bit each part containing 8bits and represented in octal format.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Now if i define a CIDR range as : 10.0.0.0/16, this means the 8 bits starting from left up to 16 bits will not change which means, in the above ip adding first and second 8bits will be 16 hence these 2 will not change. The rest 2 part of 8 bits will change. The number of ip that can be configured is from 10.0.0.0 to 10.0.255.255. Since the 2 power 8 is 256. For example, 192.168.0.0/24 which mean we 192.168.0.0 to 192.168.0.255</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We need to make sure we define the correct CIDR range for our network based on our requirements in VPC, else we may go out of the ip address to assign. More than that we need to create subnets in a VPC , so we need to have correct and more CIDR range assigned to VPC based on our requirements.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A CIDR notation does not mean to be a multiple of 8 like it can have</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.0/26. If we have 10.0.0.0/26, the first 3 8bits are not changing. But in the last 8 bit, the first 2 bits will not change and set to 11. The rest 6 bits will keep on changing giving 10.0.0.1 to 10.0.0.62 ip range</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A VPC should be in range between /16 and /28. We can't have /29 or /30 vpc configured which means, </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/16 means it can have 256x256 = 65535 ips</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/24 means it can have 256 ips</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">/31 means 1 ip</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Recently aws provided an option of adding additional CIDR ranges added to existing VPC which is not possible earlier and also we cannot edit existing vpc once created and being used.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">WHen specifying IP for VPC, we need to assign then based on the RFC1918 standards , ie </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.0/8</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">172.16.0.0/12</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">192.168.0.0/16</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">If we have a Public IP already bought we can configure aws router configured with the public IP</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Some ip are not allowed by aws are,</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.0 : network address</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.1: Reserved for VPC Counter</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.2: Reserved for DNS server</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.3: Reserved for Future Usage</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">10.0.0.255: Broadcast address but not available in Aws VPC. So reserved for future</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Router & Route Table</span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : Router works by looking at the route table. Route table holds information about how to transfer a request to a particular network. It defines routes as to where connections should go etc.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Route tables are associated to subnets</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Elastic IP</span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : elastic IP is a static public IP. dynamically an ip is assigned when we start a new Ec2 instance. That dynamic ip is not permanent , it goes when we restart the instance. For this we can create an elastic ip and assign it to the instance which lasts until we release that elastic ip.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Elastic Network interface ( ENI )</span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : a Network card. Virtual network card. When ever we are assigning ips, they will be assigned to the network interface rather than instance. Then this interface assigned to instance. This interface can be moved to other instances when we need. One Ip address goes to 1 ENI. No Multiple Static IPs address can be assigned to the 1 ENI.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">For example, let's say we are running an application inside a ec2 which has elastic ip set. Since this ip is set to interface and interface is assigned to ec2 instance, whenever there is a problem with the instance, we can just shift the interface from the old one to the new one and using the same elastic ip assigned earlier.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Internet Gateway</span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : </span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Now lets say we have our VPC and subnets are created. We want to provide internet access to the instances in one of the subnets and no to the other subnet.This is where Internet Gateway ( IGW ) comes into the picture. </span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">An Internet gateway is a logical connection between an Aws VPC and the internet. It is not a physical device and only one igw is associated with each VPC. this will not limit the bandwidth of internet connectivity. </span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">An IGW rule needs to be added to route table for forwarding requests.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">NAT gateways </span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">: </span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Let's say we 2 subnets, public and private. The public subnet connects to an internet gateway ( IGW ) which provide internet access to the instances in the public subnet. Private subnet as the name says private and no internet access.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Now we have an Instance running a DB server in the private subnet. How can we allow this DB to update patches from the internet since we don't have the internet connection. This is where NAT gateway comes into.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A NAT gateway sits on the public subnet, the DB instance is allowed to talk to the NAT gateway that sits on the public network. The public network then using IGW will get the patches for the DB instance. The advantage here is the connection is outbound only which means from DB to NAT to IGW and Internet. No inbound connections will be allowed. This works only for the IPV4. For IPV6 use the egress-only internet gateway. A NAT gateway is used to simulate DMZ where inbound public access is restricted and outbound is allowed</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Virtual Private Network & Direct connect</span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : </span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Most of the companies have well established network in their data centers and when they are coming to cloud network, how can they connect their Data center network with aws Vpc. this is where VPN and Direct connect comes into picture.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We can use these to connect our existing data center or network to the aws vpc. This lets our existing network router to connect to aws vpc. Then it becomes a virtual single network. We can easily communicate between existing DC to aws VPC using private IP address. </span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">VPN Connection & Customer gateway & Virtual Private Gateway</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Since VPN is used to connect customer network with aws network, there should be an anchor holding these connection on both side. </span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A customer gateway is the anchor on your side of that connection. It can be a physical or software appliance. The anchor on the AWS side of the VPN connection is called a virtual private gateway. Ie is</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Customer gateway on customer side</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="font-family: Verdana; white-space: pre-wrap;">VPG gateway on the aws side</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In between these 2, we have the VPN connection created. An IPSEC connection is created in between customer gateway and VPG. </span><span style="background-color: white; font-family: Verdana; white-space: pre-wrap;">The only limitation is that a VPG has 1.5g/per second bandwidth. This can lead to problems by bandwidth exceeding.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">VPC endPoints</span><span style="background-color: transparent; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : VPC End Points are basically connectivity that allows to talk to certain aws resources privately like Ec2 to s3. S3 is a service that have only public endpoints, so if we want to connect to s3 from ec2, the connection goes to internet and then connects to the public interface. The connection is not secured. Vpc endpoints allows ec2 instances to talk to end point and from there the request goes to the s3 instance. This way the connection is secured.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">VPC peering</span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> : </span><span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">VPC peering is a way where we can use to connect 2 Vpc allowing instances inside them talk to each other.</span></div>
<span style="-webkit-text-stroke-width: 0px; text-align: start; text-indent: 0px;"><div style="text-align: justify;"><br /></div></span>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: white; font-family: Verdana; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A representation of the components that are available in VPC are,</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: white; color: #222222; font-family: Verdana; font-size: 10.5pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 436px; overflow: hidden; width: 624px;"><img src="https://lh3.googleusercontent.com/B3zi5LJWxaiwb5hWULNkk7h4i-v_qRYuGig9ZpeOFnTF8UtUhfALwgB5QtV_hnRPwCcvriyQX0MQmUAfEMRQn7XJ7rxVDne3Iwc4owSxEYxZnrkOOOmfC_vD9ZwWlcdphd-0p7qt=s16000" style="margin-left: 0px; margin-top: 0px;" /></span></span></div>
</div>
</div>
జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-25201229535180906172021-03-13T09:16:00.003+05:302021-03-13T09:16:43.841+05:30Storage Basics - Object, File and Block<p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">In Simple terms, Object storage is a computer data storage mechanism that manages data as units called objects, as opposed to other storage mechanisms like file storage where data is stored as file hierarchy and block storage which manages data as blockers within sectors and tracks. In this article, we will discuss more details about the storage mechanisms and see how they work.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Object Storage</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Object Storage is a collection of data with one unique identifier and amount of metadata that is stored as Objects. Data is managed as units called blocks.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Data : The data can be anything that makes up the object. It can be anything from audio file to photo album.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Identifier : Data that is added to the object storage will get a UUID ( Universally unique identifier )and GUID ( Globally unique identifier ). These 2 identities are unique and 128bit long. These identifiers are very useful when accessing the data from a large set of object storage.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Metadata : this is data about the data or we can call them as labels to data. Metadata is data attached to the original data. This data can be any information that is used to classify or identify the data. Metadata can be taught as labels for the data.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><b style="font-family: verdana;">Advantages & disadvantages</b><span style="font-family: verdana;"> : The primary advantage using this object storage is the huge amount of data that can be stored. Since the data is unstructured, there is lots of data that can be stored but yet provides an easy way of accessing the data. So though we have large unstructured data stored, we can still access that quite easily. Huge amount of data storage is achieved due to its flat structure - by using GUIDs instead of hierarchies structure like file and block.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The Data is easily accessible with also using the metadata that we attach to the data. This metadata is quite customizable and expanded thus allowing more easier access to the data being stored in object storage.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Backup and Archiving : Since data is quite unstructured, performing backup and archiving the data is quite easy and fast. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Advantages for object storage include:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Greater data analytics : Since data is driven by metadata and deep level of classification attached to that, analysis or accessing of data is Very good</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Infinite scalability : Add as much as data and there is no limit</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Faster data retrieval :Since lot of label and metadata attached to data and no specific structuring way , data can be accessed very fast </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Reduction in cost : Cost is very low for storing data</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Optimization of resources : Since lot of data is being stored with no limits, resources can be efficiently utilized</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Data that benefits the most from object storage includes:</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Unstructured data such as music, images, and videos</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Backup and log files</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Large sets of historical data</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Archived files</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"> </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Tools available</b> : Amazon S3 bucket, Microsoft Azure Blob</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>File Storage</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">File storage is the simplest storage available to us. In file storage, the data is stored in files. These files in turn are organized in folders or directories in a hierarchical fashion. To access a file, users or machines only need the path from directory to subdirectory to folder to file.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Advantages & disadvantages : </b>Since data is being stored in files and folders, it's quite easy to organise and access the data. The major advantage of using this file storage is sharing and security. The file storage can be shared with multiple people and anyone can set permissions on the files and folders in file storage. This helps in sharing, securing, collaborating and accessing files and folders.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The primary disadvantage with this file storage is, however we plan to increase the data in files and folders at some point it will be very complex to handle the sharing, permissions and security. Things will get more complex with more and more file storage. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">In contrast to block storage, a system with file storage does not take the data of the file apart. The file is stored as a whole and called up again in this form. File level storage other than built in harddrives, we have 2 other types </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Network attached Storage ( NAS ) : Storage system connected to a network and available to all participants of the network. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Direct Attached Storage ( DAS ) : Storage system directly connected to the Computer in the form of a External System</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The other major advantage is the inexpensive storage drives. If you want more storage we can attach the external drive or network drives as file systems to the current machine. The pricing of these drives is very low when compared. </span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The major disadvantage is the rising complexity with growing file systems. When the file system grows, managing it will be complex. File storage can be when we need</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Local file sharing</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Centralized file collaboration</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">archiving/storing</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Backup/disaster recovery</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Tools Available</b> : Amazon Elastic File System, Azure Files</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Block Storage</b></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The final storage type is the block storage and currently favorite for many cloud based applications. In this type, data is broken into pieces called blocks and then stored across a system that can be physically distributed to maximize efficiency. Each block will have a unique identifier which allows the storage system to put these blocks together when data is needed. Data is stored in fixed sized blocks and a unique address serves as a metadata identifying each block</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><b style="font-family: verdana;">Advantages & disadvantages</b></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The major advantage with this type of storage is the ability to quickly retrieve and modify data that is spanned across locations. Block storage divides the data into blocks and span them across different environments thus creating multiple paths to data. This helps in retrieving the data faster when required. When a user requests for data, the underlying Operating system gathers the blocks and reassembles them into one data block and provides that to the application. The Server operating system will be responsible for separating storage by fixed sized blocks, spanning them to different environments, reassembling them when needed. This reassembling will be done by using the Server address of blocks. Protocols like Fiber Channel over ethernet(FCoE) , Internet Small Computer System Interface ( iSCSi) etc used to access the block storage data. These are commonly used in a storage area network (SAN) where high performance is required with High I/O and low latency</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">The primary disadvantages are the ability to add more metadata to the blocks. The other challenge is that this block storage cannot be accessed by multiple participants at the same time unlike File storage.</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><b>Tools Available</b> : Azure Managed Disk, Aws Elastic Block Storage</span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;"><br /></span></p><p dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: verdana;">Hope this helps you to understand the basics storage mechanisms</span></p>జగదేశ్http://www.blogger.com/profile/10868056059340001156noreply@blogger.com0tag:blogger.com,1999:blog-895691427742344285.post-38510522846333761432020-09-13T19:23:00.001+05:302020-09-13T19:23:57.684+05:30Elastic Container Service - Running Tasks and Services<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjjI6Fvrsrb8UwQFYN9icttTJN366kt62hdHcgxfHmuIKATWMOYTbaL9ZxChl1ppTVznt3koy-G19uOZb0f90wSL0fTE0z5BsY7CaQbUV7r3l660mJSaTgH7dLkX-__0yylwMs-APdy-sD/s1600/Screenshot+2020-09-13+at+6.41.27+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="357" data-original-width="344" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjjI6Fvrsrb8UwQFYN9icttTJN366kt62hdHcgxfHmuIKATWMOYTbaL9ZxChl1ppTVznt3koy-G19uOZb0f90wSL0fTE0z5BsY7CaQbUV7r3l660mJSaTgH7dLkX-__0yylwMs-APdy-sD/s200/Screenshot+2020-09-13+at+6.41.27+PM.png" width="192" /></a></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Once the task definition is created along with the Container definition we now can create the task. Go to the Task Definition and click on the Actions. Click the “Run Task” in the Actions. Now it will create a task in the Ecs Cluster. The task will be run in either of the Cluster Instances in the Ecs Cluster. </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 204px; overflow: hidden; width: 373px;"><img height="204" src="https://lh5.googleusercontent.com/PQjZIM6pxmvrIKeMw3zdNUMhB4DqoemyITO7GxxpJ-oZG8ltOwQVG4nWN6uDI3FXWF4cMKe4z0AJDmYib9JS7lXfLReTU63zL0OQD8i3pDvMQ85742qpFFmv0nBxvqqurPpwtUu0" style="margin-left: 0px; margin-top: 0px;" width="373" /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Once you click on the “Run Task”,it opens a new Wizard that allows one to choose a cluster and other details to run the task.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 425px; overflow: hidden; width: 463px;"><img height="425" src="https://lh4.googleusercontent.com/2HEXOK0a_vKinDmhkIhcCspSS4dlYK-8BKDcb171KjboNSHaAppyxEE-nfeHVUdZkLgHwAUlCC-ytQUrk8hydv7EaaROzF-lq41KMSLss2Zj6cAeajtdqUgl85_dQsxpPf5AxUYo" style="margin-left: 0px; margin-top: 0px;" width="463" /></span></span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">I will not be choosing any more values and I will keep them default. Click on the Run task button. It will take a few minutes to download the image and then run the container from that image. We can see the running tasks inside the Tasks tab in the Cluster.</span></div>
<span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;"><br /></span>
<span style="font-family: Verdana; font-size: 11pt; font-weight: 700; white-space: pre-wrap;">Check if the Container is Running</span><br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Lets see if the container is running. Click on the tasks tab where we see the running tasks details. The details include the tasks running, the instance where the task is running etc. Click on the Task to see more details regarding the task. Check the instance where it is running and login to that instance.</span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Run the “docker ps” command to see if the container is running or not. We can see the container is up and running.</span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Running a Service</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Once the task definition is created along with the Container definition we now can create the service. Go to the Task Definition and click on the Actions. Click the “Create Service” in the Actions. </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 204px; overflow: hidden; width: 373px;"><img height="204" src="https://lh5.googleusercontent.com/PQjZIM6pxmvrIKeMw3zdNUMhB4DqoemyITO7GxxpJ-oZG8ltOwQVG4nWN6uDI3FXWF4cMKe4z0AJDmYib9JS7lXfLReTU63zL0OQD8i3pDvMQ85742qpFFmv0nBxvqqurPpwtUu0" style="margin-left: 0px; margin-top: 0px;" width="373" /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Once you click on the “create Service”,it opens a new Wizard that allows one to choose a cluster and other details to run the task.</span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="border: none; display: inline-block; height: 547px; overflow: hidden; width: 578px;"><img height="547" src="https://lh3.googleusercontent.com/YiPzPM_YE81A350XgZOnCuqJ6njnQM_ksvXOBLJGFVSm7GHCWCiKs9HdVk0d27CTLtJnSNL2OkDMvKX1FWLrHGotqeMUcrDn5wxZRvwqeHYNu5LKUdLIO_oGyLNfttplAReC850p" style="margin-left: 0px; margin-top: 0px;" width="578" /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">I filled in the details as above for my application. The important thing is the Service type and number of tasks. As we discussed earlier about the service type, I have chosen the Replica type. The Number of tasks is also 1 which means at least 1 instance of the container is running all time.</span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The service type also includes the “Deployments” option which will provide us a way to deploy the service. The default is the “rolling Update”. We can also choose the “blue/green deployment”. Choose the option necessary for the application.</span></div>
<b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Click Next and choose the default options and create the Service.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Verdana; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In the next article, we will see how we can configure a load balancer to route the requests to the Containers running in the Elastic Container service.</span></div>
</div>
Unknownnoreply@blogger.com1