DevOpsshalaa
Welcome to DevOpsshalaa - a hub dedicated to exploring the ever-evolving world of DevOps ! We're passionate about sharing insights, practical tips, and real world experience in the realm where development meets operations. Whether you're a seasoned professional or just stepping into this dynamic field, here you'll find resources, tutorials, and discussions aimed at unravelling the complexities, fostering innovation, and navigating the challenges of DevOps. Join us on journey.
Friday, February 2, 2024
A Step-by-Step Guide to Creating Users in Kubernetes
Saturday, December 9, 2023
Introduction To VI Editor
VI Editor
VI Editor has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur.
Insertion mode begins upon entering an insertion or change command. return the editor to command mode (where you can quit, for example by typing :q!).
Most commands execute as soon as you type them except for "colon" commands which execute when you press the return key.
Input Commands (End with Esc)
a Append after cursor
i Insert Before cursor
o Open line belowO Open line above:r file Insert file after current line
All the above commands will make vi in input mode press Esc to come back to command mode.
Change Commands (Input Mode)
cw Change word (Esc)
cc Change line (Esc) - blanks line
c$ Change to end of line
rc Replace character with c
R Replace (Esc) - typeover
s Substitute (Esc) - 1 char with string
S Substitute (Esc) - Rest of line with text
. Repeat last change~ Toggle upper and lower case
Deletion Commands
dd or ndd Delete n lines to general buffer
dw Delete word to general buffer
dnw Delete n word
db Delete previous word
D Delete to end of linex Delete character
File Management Commands
:w name Write edit buffer to file name
:wq Write to file and quit
:q! Quite without saving changes
ZZ Same as :wq:sh Execute shell commands (<ctrl>d)
Window Motions
<ctrl>d Scroll down (Half a screen)
<ctrl>u Scroll up (Half a screen)
<ctrl>f page forward
<ctrl>b page backward
/string Search forward
?string Search backward
<ctrl>l Redraw screen
<ctrl>g Display current line number and file information
n Repeat search
N Repeat search reverse
G Go to last line
nG Go to last line n
:n Go to last line n
z<CR> Reposition window: curser at top
z . Reposition window: curser in middlez - Reposition window: curser at bottom
Cursor Motions
H Upper left corner (home)
M Middle line
L Lower left corner
h Back a character
j Down a line
k Up a line
^ Beginning of line
$ End of line
l Forward a character
w One word Forward
b back One word
fc find c; Repeat find (find next c)
Undo Commands
u Undo last change
U Return the last line which was modified to its original state (reverse all changes in last modified line)
:q! Quite vi without writting
:e! Re-edit a messed up fileCtrl-R: Redo changes which were undone (undo the undos)
Rearrangement commands
yy or y ank (copy) line to general buffer
nyy Yank n line to buffer
yw Yank word to general buffer
ndd Delete n lines to buffer
p Put general buffer after cursor
P Put general buffer before cursor
J Join linesnJ Join the next n lines together; omitting n joins the beginning of the next line to the end of the current line.
Playing with multiple files
:n:rew
Move text from file old to file new
vi oldfile.txt
10yy yank 10 lines to buffer a
:e newfile.txtp put text from a after cursor
#Write it to newfile.txt
:m,nw newfile.txt Write lines m to n in file newfile.txt
:m,nw>> file Saves lines m through n to the end of file
Regular Expressions (Search Strings)
^ Matches beginning of line
$ Matches end of line
. Matches any single character
* Matches any previous character
.* Matches any character
Search and replace commands
:[address]s/old_test/new_test/gic
Address components:
. Current line
n Line number n
.+m Current line plus m lines
$ Last line
/string/ A line that contains "string"
% Entire file
[addr1],[addr2] Specifies a range
Example:
Remove last character
:%s/.$//
^M
Change some vi Parameters
:set list Show invisible character
:set nolist Don't show invisible character
:set number Show line number
:set nonumber Dont Show line number
:set autoindent Indent after carriage return
:set noautoindent Turn off auto indent
:set showmatch Show matching sets of parentheses as they are typed
:set noshowmatch Turn off showmatch
:set showmode Display mode on last line of screen
:set noshowmode Turn off showmode
:set ignorecase Ignore case on searches
:set ic Ignore case on searches
:set noignorecase Turn off ignore case
:set noic Turn off ignore case:set all Show values of all passible parameters
Pravin Ade | Sr. DevOps Engineer | Infosys
Thursday, March 24, 2022
Useful Linux commands
Q 1. How to remove everything except for a list of files?
rm -rf !(file1 | file2 | file3 |...)
Q 2. How to remove all hidden files in current directory?
rm -f .??* .[^.]
Q 3. How to save file in vim when forgetting to use sudo?
:w !sudo tee %
Q 4. How to edit multiple file simultaneously with vim?
vim -o file1 file2 file3
Q 5. How to find and remove broken symbolic links/
fins -L . -type l -delete
Note: If you simply want to find broken symbolic links but without removing them:
find -L -type l
find . xtype l
Q 6. How to monitor top 10 processes using the most CPU?
watch -n1 "ps aux --sort -pcpu | head -n10"
Q 7. How to check battery of your wireless mouse?
upower --dump
Q 8. How to find date and time when your linux was installed?
tune2fs -l /dev/sda1 | grep "Filesystem created"
Q 9. How to combine multiple PDF files into one PDF file
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
Q. 10 How to SSH to a remote server via a jump server in the middle?
open ssh connection through a jump server
ssh -J user@jump_server user@remote_server
Sunday, March 13, 2022
What is user data in AWS?
How to use User Data? and Advantages of User Data?
Vault installations and integration with GitLab CICD pipeline
What is vault?
Vault is an identity-based secrets and encryption management system. vault is used for store sensitive data it can be API encryption keys like tokens, access key, secret key, passwords, or certificates etc.
Ref Links: for integration vault with GitLab CICD
1. https://docs.gitlab.com/ee/ci/examples/authenticating-with-hashicorp-vault/
2. https://holdmybeersecurity.com/2021/03/04/gitlab-ci-cd-pipeline-with-vault-secrets/
3. https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/ci/secrets/index.md
4. https://gitlab.com/edmond-demo/sandbox/hashicorp/vault_via_api/-/blob/master/.gitlab-ci.yml
Cheat sheets:
https://medium.com/@jagunathan22/hashicorp-vault-cheatsheet-8f13dc6a95a9
https://sites.google.com/site/mrxpalmeiras/vault-cheat-sheet
Unseal
the Vault-(Need to at least put 3 unseal key)
CMD- #vault operator unseal <unseal-key>
Vault Login:-
Initial Root Token: <paste token here>
CMD- #vault login
Enable outer access of Vault
Server by its IP address:-
To make it available to the other
nodes of the network need to change the configuration in the vault HCL file, It
may be at a home directory or /etc/vault.d/vault.hcl.
Example:
storage
"raft" {
path
= "./vault/data"
node_id = "node1"
}
listener
"tcp" {
address
= "ip:port"
tls_disable = "true"
}
mlock = "false"
api_addr =
"http://ip:port"
cluster_addr =
"https://ip:port"
ui = true
GitLab Integration with Vault:
Step 1:- Create a Gitlab project Repository.
Step 2:- Next step is to configure the vault:
A.
List, enable and disable vault
secret engine as per requirement :
a. vault secrets list
b. vault secrets enable -path=secret kv
c. vault secrets disable kv/
d. Ref. https://www.vaultproject.io/docs/secrets
e. Ref. https://learn.hashicorp.com/tutorials/vault/static-secrets
B.
Create, list and read Secret :
a. vault kv put secret/hello target=world
b. vault kv list secret/
c. vault kv get secret/hello
C.
To create policies and role first
need to enable authentication method for this case we are using JWT
authentication method :
a. CMD # vault auth enable jwt
b. Ref. https://www.vaultproject.io/api-docs/auth/jwt
D.
Create, list and read policy to
provide read, write access to secret:
a. vault policy write admin admin-policy.hcl (using hcl file)
b. $ vault policy write myproject-production - <<EOF
# Policy name:
myproject-production
#
# Read-only
permission on 'secret/data/myproject/production/*' path
path
"secret/data/myproject/production/*" {
capabilities = [ "read" ]
}
EOF
c. vault policy list
d. vault policy read admin
e. Ref. https://learn.hashicorp.com/tutorials/vault/getting-started-policies?in=vault/getting-started
E.
Create, list, read and delete role
to provide RBACK for the secret using policies:
a. $ vault write auth/jwt/role/myproject-production - <<EOF
{
"role_type": "jwt",
"policies":
["myproject-production"],
"token_explicit_max_ttl": 60,
"user_claim":
"user_email",
"bound_claims_type":
"glob",
"bound_claims": {
"project_id": "22",
"ref_protected":
"true",
"ref_type": "branch",
"ref": "auto-deploy-*"
}
}
EOF
b. $ vault list auth/role
c. $ vault read auth/role/myproject-production
d. $ vault delete auth/role/myproject-production
e. Ref. https://learn.hashicorp.com/tutorials/vault/getting-started-policies?in=vault/getting-started
F.
Access secrets from .gitlab-ci.yml
file
a. Ref. https://gitlab.com/edmond-demo/sandbox/hashicorp/vault_via_api/-/blob/master/.gitlab-ci.yml
stages:
- test
read_secrets:
stage: test
# image:
# name: alpine:latest
script:
# - apk add
--update curl jq
# Vault's address
can be provided here or as CI/CD variable
- export
VAULT_ADDR=http://<IP-Address:Port>
tags:
- ubuntu20
- awslightsail
Saturday, February 27, 2021
Python Features
Features of python
- When we read python program, we can feel like reading English statements.
- Simple syntaxes.
- Very less number of lines as compared with other languages.
- More readability and simplicity.
- We can reduce development cost of the project.
- We can use python without any license and it's freeware.
- no need to pay single paisa for using software.
- It is programmer friendly language.
- Being a programmer we are not required to concentrate low level activities like memory management and security etc.
- Data type is does not matter. whenever we are assigning the value, based on value type will be allocate automatically.
- Being a programmer not required to compile python program. internally python interpreter will take care that compilation.
- An interpreter is a program that reads and execute code line by line.
Identifiers:
- Alphabet symbols it may be UPPER CASE or lower case.
- Identifier should not start with Digits.
- Identifiers are case sensitive.
>>> a = 10>>> A = 20>>> print(a)10>>> print(A)20
4. We can not use reserved word as identifiers.
DATA TYPES IN PYTHON
Fundamental Data Types:
- int
- float
- complex
- bool
- str
Collection Data Types:
- bytes
- bytesarray
- range
- list
- tuple
- set
- frozonset
- dict
- None
Python for beginners
Python!
Now day everyone talks about Python Python.....
The question is why Python suddenly came in picture?
The answer is Python quite easy to learn as compare other languages.
Python is recommended as first programming language for beginners.
DOB of python Officially: 20th February 1991. means Python was made available to public in 1991.
Python is a widely used high-level programming language
It has a large and comprehensive standard library
It is general purpose means we can use for developing web application, for desktop application, database application, Network programming, for developing games, data analysis applications, ML- Machine learning, Data science , AI , IOT almost everywhere Python most popular now days.
Getting started with Download and install python.
Download from official web site: https://www.python.org/
windows user : https://www.python.org/downloads/windows/
Mac user : https://www.python.org/downloads/mac-osx/
Verify if python is installed
If you have Python 3 installed, and it is your default version you should see something like this:
Hello World! in python using IDLE
C:
Python:
Example 2:
Print the sum of two numbers
Python was developed by almost all programming language features from different languages.
1. Functional Programming feature from C.
2. Object Oriented Programming feature from CPP.
3. Scripting Language Features from Perl and Shell.
4. Modular Programming features from Modula-3
Everything is okay! yeah! okay but where we can use?
1. For developing Desktop applications.
2. For developing Desktop applications.
3. Games, Data Analysis , ML, DL, AI and IOT.
A Step-by-Step Guide to Creating Users in Kubernetes
1. Create a User Account openssl req -new -newkey rsa:4096 -nodes -keyout pravin.key -out pravin.csr -subj "/CN=pravin/O=Infosys" ...
-
1. Create a User Account openssl req -new -newkey rsa:4096 -nodes -keyout pravin.key -out pravin.csr -subj "/CN=pravin/O=Infosys" ...