re
UNFINISHED-UNTESTED-STILL ONGOING(there might be mistakes)
תוכן
תקשורת
פורטים מול DATABASE או API
קונפיגורציות
לחיבור בין שרתים
באותה רשת
הליך
CI (continuous Integration)
TROUBLE SHOOTINg stuff in Kubernetes:
Scenario-How Ingress/Ingress-controller deploys a
public app into the LB
EKS- Elastic Kubernetes Service
To add: ** what is devops?? ** what is a CI process? What is a CD process? Difference of fast forward and non-ff(git)?
DRY(don’t repeat yourself)- scenario where Devops are mostly on maintaince and not implementing automation. Meaning there’s a problem in the pipeline. Which should be addressed and automated.
To prevent too much focus on maintaince rather than smooth development pipeline.
Finding problems BEFORE clients – proper monitoring with devs.
Common Practices:
Shift left: the practice of testing in staging/CI before releasing to prod. Emphasizing code analysis and error detection prior to release.
Shift Right: the practice of observability(Prometheus for ex), monitoring after deployment to production. To improve resilience(stress/chaos engineering)
Windows services and Event viewer/logs:
Services:
apps that run for the OS or additional, some of it connects to other servers. it manages
events and logs
Event
Log/viewer: logs events of errors and other properties. Also shows what
user did what.
Issues:
anyone can access it/security issue, volume too big, too partial info.
Application
log- all logs of application-that are used by the system, Partial: not all apps
log are connected to event log.
System
Log – OS logs(services, device drivers, events,
operations)
Security
log – resource using-creating/opening/deleting files/objects. Goes to
audit. Valid/invalid login attempts(users)
Setup
logs – every update, packages, new installation, uninstalling.
Forward
events- a possible way to get events from other servers, and concentrate it to
my server
Subscriptions-
set up the way to forward events
Usage:
filter current logs>filter accordingly to look for something specific
Kind of events: information, Success, Failure, Warning, Verbose,
Error
Performance monitor:
Usage:
+add>select what to see graphs>can select a time in history
Resource Monitor:
See
usage of disk, cpu etc(real time)
Windows manager?
תיקיות
שחשוב להכיר:
Windows/system32/driver/etc/hosts קובץ
שאיתו אפשר
להריץ שרת על
המחשב המקומי.
HOSTNAME RESOLUTION.
Kinds of Servers:
Client server:multiple clients on one server.(active directory,
mail server, print server, web server, storage servers)
Example:
[Active directory – server that is responsible for authentication and
user accounts, passwords, membership access rights. create Domain inside the organization ]
Client
Server: Organized/ secure/has a point of failure X/ high costs
Peer to peer
– no dedicated server, networks of computer which are both clients and
servers
P2P: unorganized/unsecured/no point of failure V/ low cost
ROLES(of microsoft windows server):
IIS–
(internet information services) server software by Microsoft to host
websites/apps and services of the OS.
WEB
SMTP (simple
mail transfer protocol)
Active Directory – has Domain Controller(DC), which
is what mitigates between the client’s data(psw,personal data,
services data) and its access to domain, in which the services for the client
exists.
VMware
Hypervisor:
the software that creates Virtualization over the hardware.
Type1:
Bare metal hypervisor(VMware ESXi) -which has
independent OS and machine installed over the hardware(good for organizations).
Type2:
Hosted hypervison, installed over the hosting machine(hogs
resources from the machine)
Vm files:
Disk
file(.vmdk): all the OS and files inside the VM, important.
Log file: logs
of any VMactions
Configuration
file: (.vmx) stores info, machine name, bios, guest OS.
Snapshot: (.vmsd or .vmsn or .vmx) stores a current state of files and
OS.
Data Center
Data Center:
Hardware infrastructure that supports virtualization(instead
of loads of pizza servers)
Components:
Compute, Storage, Networks
Types of hardware servers:
Blade
servers: high class/expensive mounted into an enclosure and very modular-does
not disrupt other servers inside
Rack
mounted: like pizza servers
Tower
server: a single
powerful computer
Storage
Storage servers:
Some
has own OS, has storage for all other servers.
Types
of Storage servers:
SAN – Storage Area Network(expensive)-no OS. fast, only local
servers can communicate with it(usually connected with
fiber, sacsi)
NAS – Network Attached Storage (cheaper)-embedded OS,
independent managing of files/”filer”,
distributes storage for all servers-not just local.
RAID:
redundant Array Independent Disks, Hard drives linked together to create large
volume of duplicate(redundant) storage
Mirroring(RAID 1 state) - when one falls. Disk 2 is a mirror
of Disk 1- invoked by a RAID card, that does that automatically. Inside the
server.
RAID
0 state: no raid, no mirroring. Regular storage.
Data Striping(RAID 5 state): each drive has blocks/segments which
can be used as back up for what is stored, instead of whole disk mirroring.
Limited if
low in capacity
Block-Level Storage: data is written and
accessed from storage volumes/blocks. Does not provide inherent file system.
SAN typical.(accessed mostly via client OS)
File-Level Storage: Data is written to disks but accessed from default file system.
Common for NAS systems.
Common Data Center Storage Protocls:
iSCSI-
internet small computer system interface. Small card that connects to
storage(expensive)
FC-
fiber channel card that uses fiber cable.
FCoE-
Fiber Channel over Ethernet. Expensive
Storage provisioning:
Thick
provisioning: fast. pre-allocating disk space. Logical space by partition equal
to actual physical space
Thin
provisioning: common. not pre allocating. Slowing down the read write because
of constant re-assigning .
Virtual Data Center: uses blueprints instead of templates, as virtual machines/resource,
and from the blueprint the template is created.
vSphere:
ESXi – type1 hypervisor, software that is installed directly on the physical server to create a virtual layer
Unix component, VMware Kernel component.
vCenter: management software(installed on management server), on a dedicated server to manage ESXi servers and other components of virtual data center
vSphere Client : program that controls host servers and VMs, has GUI that allows administrator of data center to connect to vCenter and ESXi remotely.
NAT- (Network address translation ) single IP for the whole office. That means that you can share localhost from your VM machines(127.0.0.1), for outbound access from your servers. Doesn’t provide inbound access. IGW opens inbound traffic(unless rules in vpc) to public.
Bridged =
different IP but only internal, that means that you have different IP for each V.machine you have, and thus cannot share same localhost(127.0.0.1)
לבדוק יש 2 סוגי VPN – DHCP ועוד משהו
DHCP = (Dynamic Host Configuration Protocol)service or a server/router that configures and creates our IP address, when
unavailable we use static. But still needs convention to apply
MAC address
isn’t enough here because we need protocols to communicate the data.
Analogy: physical address is where I live, and an IP is what my name is.
It(DHCP) takes from a pool of range of ip’s and allocates one.
RAID – redundant array of independent disks. Raid 0 : regular disk. Raid 1: another disks backsup
Raid 5: 3rd disk backs up the system.
NIC –
(network Interface control) כרטיס רשת, twisted pair-crossed
cable. Very Low freq. elec.
Also called: LAN adaptor, network adaptor.
Twisted pair: כבל מוצלב, דומה לכבל טלפון. אבל יותר רחב עם מעבר נתונים גם.
RJ45 – typical cross cable. More popular between computers, and not in client server scenario.
MAC – (Media Access Control) computer has MAC address when plugged via NIC.
Unique addressכתובת פיזית שצרובה בחומרה ,
Coded in 6 groups of 2 hexadecimals.
לפי תקן IEEE 802
Modulation: הצורה שהתשדורות עוברות דרך הקווים-הסיגנל הדיגיטלי(הנתונים) עוברים המרה לאנלוגי-הגל המחזורי ומתורגמים חזרה לדיגיטלי.
השימוש
במודולציה
הוא כדי לשדר
תצורות שונות
של פרוטקולי
תשדורת,
לדוגמא
מודלציה ע"י
שינויי
אמפליטודה
או ע"י שינויי תדירות, או ע"י שינוי פאזה.
Modulator: המכשיר שאחראי על תרגום האות הדיגיטלי לאנלוגי, הגל המחזורי.
LAN – Local small private network (home/small office)
WAN – Wide
area network, can cover a city or a whole country or more.
Ethernet – חיבור פיזי או וירטואלי למחשבים
Bus network = like single linked list. או חיבור טורי לינארי.
Connects through half-duplex, slow unreliable. Old.
- Host – is a stop at bus connection, a station.
- If a host is injured the whole network can fault.
- We don’t know if the data reached the end.
- Cable is coaxal, 10base5. Un-crossed.
Repeater- enhance range of the network.
Common in hotels, repeats the data and amplifies it.
Hub – מרכזיה , physical layer(layer 1), connects devices to several computers. Like bus network.
מפצל רשת, בעל I/O לכל התקן/מכשיר/מחשב. פחות בשימוש.
Switch
– layer2.(cant replace router. doesn’t
support tunneling, private network) broadcasts frame switching. Common!
Frame
switching- frames are data packets, which sliding windows is the managing
mechanism that controls the transmission of frames.
-
Gets data
and returns with a buffer and asks to who to return also(hub
doesn’t know who to return)
-
Has a list
of of all mac addresses of devices he is connected.
-
Uses the
MAC address to forward data to data link in layer2
-
Some
switch devices can transfer(?) to layer 3 by adding a routing function, called:
-
Layer 3
switching/ multilayer switching.
Router- The router
is what provides IP addresses so we can get out, Layer 3
-
Supports
protocols to internet suppliers(switch doesn’t
have these)
-
Provides
traffic directing functions, data that is transferred via packets.
-
The router
uses the data in the header by reading the table of routers/protocol of routers
in the header(of the packet) , and then sends the
packet to her next network journey.
-
Tracert
<your IP address> - provides the journey of the packets through the IPs
Packet – transferred from router to
router as a package of the data you send/being sent. also has a-
Header
– which tells the packet/packet reader where is the
final destination
-
When a
packet reaches my router, the service(internet) provider checks the address
-
And
queries if its Global DNS or Local.
FireWall – device or app that
blocks or restricts הרשאות according to internal protocols.
Like
LAN or to deal with external network (WAN/internet)
-DMZ
(DeMilitarized Zone) a buffer area that moves between 2 firewalls.
One
border: public {} other border: LAN
Honey
Traps – מלכודות
לתפוס רמאים
באזור הזה
-a
computer can become that buffer
-
has his own IP unlike NAT. in DMZ there is no NAT.
DPS/IPS
– (Intrusion Detection System/Intrusion Prevention System) תוכנות
או חומרות
שמונעות או
מזהות
פעילויות
חשודות.
חוסמות /
עוצרות או
מדווחות.
OSI Model= 7 layer model, Open System Interconnection.
[7:application 6:presentation 5:session 4:transport 3:network 2:data link 1:physical]
Physical(1): cables, switch, router,
repeater all the hardware network.
Data-link(2): fiber cable, the signal in the cables, NIC/network
adaptors,switch, bridge
Network(3): IP, routers, protocols, connectivity-WAN LAN.
Subnetting.
Transport(4): packets, error
detection, flow control, monitoring
Session(5): opening a session/user,
client, length of session
Presentation(6): output on the
browser
Application(7): the app side,
“behind the scenes”
(some components can share several layers)
TCP/IP Model: 4 layer model (Transmission Control Protocol) / IP(Internet
Protocol)
Layers[ 5-7 Application: http, https, telnet, ftp,TFtp
4:transport(packets): TCP/ UDP
3: network : Router
2:datalink : bridge/switch
1:physical]: Hub
-
המודלים
מגדיר את
הסנכרון
הסמנטיקה
המתודולוגיה,
תהליך אחזור
תיקון שגיאות
-
iSCSI- :רכיב
שאחראי על
תקשורת בין
מחשבים
ואחראי על
החלק של
האחסון. מאפשר
הדמיה של
אחסון
מרחוק-כאילו לוקאלי.פרוש
על שכבת TCP ומאפשר
תמסורת SCSI
בLAN.
Active Directory – an ongoing list that refreshes, of users, credentials,
policies, group users, servers, DNS and other network resources.
פקודות
בדיקות
,מידע,מניפולציה
על NETWORK:
Ipconfig:
מציג מידע על IP של
הראוטר, כתובת
MAC,
Ipconfig /all
:
מידע עוד יותר
מפורט- רק בPOWERSHELL או CMD,
(בGITBASH
לא יעבוד אלא
אם כן עושים CMD.exe)
Tracert: TRACE ROUTE – מביא את כל תחנות המעבר והפינג אליהן בדרך לכתובת היעד.
Tracert
www.arielguez.com ללא https://
Route:
מאפשר
מניפולציה
ושליטה על
טבלאות הROUTING. כמו
להכריח
להשתמש בIPV4 (-4) או 6(-6).
PRINT – מדפיס
את הROUTE
ADD:
הוספת ROUTE
DELETE, CHANGE
לדוגמא:
route print :
מראה את
כתובות
היציאה של
הראוטר
פיזיות וגם
לוגיות(IP).
Arp -a : מציג
את כל כתובות
הIP מול
הכתובות
הפיזיות שלהם
כDEVICES
Arp -av: מציג
פירוט יותר
וחלוקה
לקטגוריות
Route add: כמו VPN וגם
מאפשר הטיה
לרשת מסוימת.
הטיה של הIP לכתובת
שאנחנו
בוחרים , לנתב
מחדש.(מהDEFAULT
GATEWAY)
Netstat:
בודק איזה
פורטים
פתוחים-מה
בשימוש.
telnet <ip> <port>:
מתחבר לכתובת
שנרצה לפי
פורט.
Nslookup <domain name>:
מציג את הIP של הכתובת
דומיין,
לדוגמא מה הIP של
גוגל
Hostname:
מחזיק את שם
המכונה/מכשיר/מחשב
IANA: (internet Assinged Numbers Authority)
company that responsible for fixed port numbers
Port – logical – not physical
(socket is physical)
16bit number 0-65535.
System ports:0-1023 user ports: 1024-49151 dynamic/private ports:
49152-65535
ftp: port 21
ssh: port 22
telnet: 23
25,143:
email, SMTP: 25(between mail servers)
53:
DNS
487(between
clients and Email server)
HTTP: 80
443,4483: https
2375-6:docker
(2375 rest API, 2376:https)
SQL : 3306
5432: PostgreSQL
5984: windows RM(remote
desktop)
6443:
kubernetes
6379: Redis
8080: jenkins
9200,9300:
elastic search
9090: prometheus
9093: Alert Manager
3389:
remote desk protocol(RDP)
443,
4483: HTTPS (secured)
LINUX : *Ephemeral ports for linux 32768 – 61000
dynamic(open/closes)
*Ephemeral
port: temp port that opens(high
numbers 49152-65535) and closes, used by applications or OS.
6443,
10250:Kubernetes: 6443. 10250-kubelet, dashboard:
30000-32767 for nodeport, 10250-10252:kubelet,kube-scheduler,
kube-controllermanager.
Jenkins:8080, default agent:50000 (can be
configured)
איפשור
של הIP הפנימי
להיות משודר
החוצה כדי
שיהיה אפשר להתחבר
אליו-כמו
אפליקציות
שעובדות
במחשב המקומי
ומנתבת גישה
דרך FORWARD לפורט.
PORT FORWARDING זה מצב שבו
מתעלים/מנתבים
כל תנועה
שנכנסת (לדוגמא
למחשב LOCAL(127.0.0.1)) >> דרך
פורט ספציפי-
וזה מוגדר על
ידי הROUTER או על ידי ROUTER וירטואלי.
משתמשים
בזה בגלל
שהמחשב
המקומי HOST, מפנה את
הפורט
הספציפי
מבפנים, הרשת
הפנימית,
לבחוץ-לIP החיצוני
שלו. אחרת הCLIENT לא
יוכל להכנס כי
הHOST
מאזין רק
לפנימי,
וה
FORWARDING
מאפשר מעבר
מהבפנים
לבחוץ
לדוגמא
127.0.0.1:2222
כמארח HOST,
יאפשר
כניסה/תנועה לIP רק
דרך פורט 2222. ואם
האורח מוגדר
כפורט 22, אז כל
התנועה שתגיע
אך ורק מ2222 תנותב
ל22.
במצב
שיש לנו שרת
עם SSH
שעובד כרגיל
על פורט 22,
והקליינט
רוצה להתחבר לשרת
יכול
להיות רק SERVICE/APP
אחד על פורט
אחד פר SERVER.
כי אחרת לא
תהיה הפרדה של
תנועה לפי
האפליקציות,
ותנועה
שמתאימה
לאפליקציה 1
תנותב לאפליקציה
2 -מה שיוצר
קונפליקט,
ולכן נמנעים
מזה ע"י הגדרת
פורט אחד פר
אפליקציה(על
אותו שרת).
1.User
inputs url on browser->
2.DNS
resolution-translates to ip->
3.Web
server establishes connection, hosting the user->
4.Authentication request(username/password/credentials/token) sent to user/security component->
5.LDAP(lightweight directory access protocol) or Active Directory server established(in case that’s on a server) ->
6.User validation, validates user creds. Against its own server directory database ->
7.Access granted, if authentication successful ->
8.Session management, establishes monitor state of session during interaction with website ->
9. User interaction, user interacts with website.
בד"כ
שנפתח QUERY
מול המסד
נתונים זה מול
OUTBOUND CONNECTION
של השרתים
שלנו. ואז
מועברת הלוך
ושוב גם בחזרה
לשרתים, כל
זאת מבלי
לעבור בINBOUND,
מאחר והערוץ
תקשורת עדיין
פתוח.
ולכן
לדוגמא
שעובדים מול MONGODB
בענן, אז לא
צריך לפתוח INBOUND CONNECTION ייעודי
עבורו, כי הוא
עובד רק מול OUTBOUND.
זה
אמור להיות
תקף לכל API
צד
שלישי, שעובד
עם TOKEN
והזדהות
ואימות. כך
שלא אמורים
לפתוח INBOUND
לשום API.
>get-service | where-Object Status -eq ‘Stopped’ : מראה כל השירותים שנעצרו
>get-service
|where-Object Status -eq ‘Stopped’ | select-object Name,Status מראה
רק עמודות של
שם וסטטוס:
>$data = get-service | where-Object Status
-eq ‘Stopped’ | select-object Name,Status :
שופך את הכל
למשתנה DATA
>$data | out-file .\services.csv
: שומר
בתוך הקובץ של
"שירותים" את
$דאטה
> notepad .\services.csv :
מציג
דרך נוטפאד את
הקובץ
> $data |export-csv .\services2.csv
: מייצא
לקובך
שירותים2
בפורמט סי אס
וי
>get-content .\service2.csv מציג
את הקובץ
>get-verb : פקודה
עם תת
קטגוריות
שמראה את כל
הפקודות שניתם
להפעיל
<get-verb | more : מאפשר
דיפדוף עם
רווח
>get-verb -Group Security|format-list : מציג בצורה ברורה (פורמט) תת קטגרויות עבור פקודות סקיוריטי
>get-alias
–כל
קיצורי הדרך
לפקודות
>get-help *service* : עזרה על כל מילת תוכן שנחפש
>get-command -Commandtype function | measure-object : מראה כמות של פקודות עבור פונקציות
>get-command -name *ip* -module NetTCPIP : מראה רק פקודות שקשורות לרשת(כי הגדרנו במודולו)
>get-history : כל הפקודות שהרצתי בסשן
>invoke-history -id 22 : מריץ את הפקודה מס22 לפי ההיסטוריה
>start-transcript -path .\transcripts\transcript1.txt -append : הפעלת שירות לשמור את ההיסטוריה לתוך קובץ אוטמטית
>stop-transcript : עוצר את
הרישום בלוג
הזה בקובץ,
והקובץ מכיל הרבה
פרטים על כל
הפעולות של
המשתמש שעשה
>Ping : בודק
כתובת מהירות
לייטנסי
זמינות וכולי
>Whois <ip> :
>ipconfig , : את האיי.פי שלי ביחס לרכיבי החומרה מראה
>ipconfig /all יותר מידע על התקני רשת , רשת ובמחשב עצמו
<route יכולה
לנתב אותי ל DEFAULT GATEWAY אחר
Route
add : מאפשר לי
לנתב את
הטראפיק
למקום אחר,
נניח DEFAULT GATEWAY
שיעבור
דרך גייטוואי
אחר עבור איי
פי אחרים לדוגמא.
>route print, route add
VPN מנתב
ליציאה אחרת
דרך אותו
<netstat פורטים
פתוחים או
בשימוש(מקשיב)
כלי מרכזי לבדיקת
תקשורת
עובדת/לאעובדת-
>telnet – מחבר
בינך(המחשב)
לתחנה מסוימת
לפי פורט. יש
לציין הוסט
ופורט
צריך
לאפשר את זה
בווינדוז CONTROL
PANEL ואז
לבחור TELNET
CLIENT
<curl : בודק
אתר ללא דפדפן
אבל דרך קומנד
ליין
=PAGE SOURCE
<curl – h עזרה HELP
>curl -o <filename> www.website.com יוריד את האתר לתוך שם הקובץ הזהDOWNLOAD
> curl -sSLO or curl -sfLO or curl -LO <http url> יוריד אם יש קובץ בקישור
>nslookup : מתרגם
דומיין שם אתר
רגיל באנגלית
לכתובת איי.פי
>arp , arp –
a, arp -av : מציג
את כל ה IP שמחוברים
למחשב
<tracert – מגלה
את המסלול של
הפאקטץ,
מבירות,
לייטנסי, ורואים
איפה נתקע tracert -4 <ip> נותן גרסא
מוכרת יותר של
גרסא 4
>hostname –
מחזיר את שם
המחשב
>env – מציג את
כל
האינווירמנט
וואריאבלז.
>type – כמו אקו או
cat
>netstat -an -p tcp איזה פורטים מקשיב או מקושרים עכשיו –
CRON ב WINDOWS זה task schedular
wsl –shutdown VMMEM VMEM
מכבה VMMEM
שנשאר פתוח בWINDOWS
IT : information technology
Default Gateway – : השער שממנו הכל קורה. בדרך כלל כתובת השרת/נתב ברירת מחדל שברשת.
בלעדיו
– לא ניתן
לגשת לכולם-
לא לרשת פנימית
ולא
חיצונית.(ראה ROUTE ADD)
BGP (border gateway protocol)רכיב
שנמצא בנתב(לא
תמיד) ומגלה
רשתות אחרת
שבתווך. לא
צריך לגלות
אותו,
לא
צריך- להגדיר subnet,
כי BGP
מגלה בעצמו.
אם לא קיים BGP, צריך להגדיר IP אחד אחד
Header: data/info that precedes data transmission. Contain metadata of payload, how it should be processed, origin, destination
And other params.
two kinds-
http request- sent by the client
HTTP response header- sent by the hosting server, this is what enforces the browser of the client to adhere to strict security policies(AWS ALB does not provide that)
MIME: MultiPurpose Internet Mail Extension. Basically what allows attachments or file uploads.
X-content-type-Options with value “nosniff” tells browser not to inspect MIME type “sniffing” of what file type.
The problem with MIME “sniffing” is that it can be abused and pose security threat because of it
(for example jpg starts with magic hex numbers, but later becomes a script).
“nosniff” respects the server’s choice, and lets other security measures such as CSP(Content Security Policy)
SSL : secure Sockets Layer תעודה חוקית שמאפשרת זיהוי נכון שהגענו למקום הנכון
TLS: Transport
Layer Security-
היורש לתעודה
שלעיל, והגרסא
המודרנית
יותר, makes encryption and decryption of traffic, therefor more
secure
Cipher: סוג של ENCRYPTION עם מפתח , בכל מיני דרגות כוח
UUID: (Universally Unique Identifier) 1280bit number used to uniquely id some object or entity on the internet.
Designed for distributed systems to uniquely id information without significant central coordination
UUID4 for ex, is popular due to its generation via random 122 bit random numbers, as an ID.
Low probability of collision, because of the statistical larger spectrum.
OWASP:
Open Web Application Security Project- מינימום
של 10 תנאים
לתקן בטיחות
שלהם
1.broken
access control
2. cryptographic failure
3. injection
4. Security misconfiguration
5.
SOC 2: Systems and Organization Controls 2. בדיקה שמספקת אסמכתא למהימנות האבטחה של אפליקציה או אתר/חברה.
CAPTCHA: בדיקה שבודקת אם אתה אדם או בוט, “Completely Automated Public Turing Test to tell computers and Humans Apart”
Tty:
teletypewriter- basically a terminal, console.
LVM: logical volume manager (centos) > can grow in size, traditional volume partition-is fixed!
CIDR: Classless inter-Domain Routing. A form of notating ip:192.168.14.0/24 . lookup subnet mask but CIDR is different.
ICMP: the protocol which does ping/telnet/tracert. Internet Control Message Protocol
Subnet: range of IP addresses from your IP, to compromise more IP’s/A sub-network
DNS: Domain Name System. What translate IP’s to web address domain name.
WebSocket:
protocol that allows 2 ways communication in a single TCP connection, full
duplex. For real time communication(but not gaming,
more like stock data, chats).
LDAP:
Lightweight Directory Access Protocol. מנגיש
ומציג מידע על
שירותים
באינטרנט
שרצים על
אייפי
ROLESבשימוש נרחב לאוטנטיקציה, יכול לשמור סיסמאות ומשתמשים וגם
CGNAT: Carrier Grade Network Address Translation, מספק עוד מעטפת של עוד כתובות איי פי, בגלל שנגמרות הכתובות של
IPV4
finOps: optimization of costs. Financial optimization/finance operations
gitOps: methodology that adheres to git as the single source of trurh.
All provisioning of infrastructure and its management is via the configuration of stored in git.
Helps automating the deployment
IoT: amazon the
protocol/platform which handles physical devices on cloud.
CDN: content delivery network. The service that allows caching websites/apps that are too remote. Making the content available
In closer servers, cutting response times and download times.
CORS: cross origin resource sharing. A security measure in browsers,
For ex. FE is running at localhost and backend is at https://api.something that is a cross origin. And when configured to block-or allow such cases
To
allow, the header must of the API response must be: Access-Control-Allow-Origin:
* >>or change wild card to a specific domain.
Httpd: apacheהתקנה
של
Tomcat: מאפשר
שירות
לאפליקציות
ג'אווה בד"כ על
שרת אפאצ'י,
מבוסס ג'אווה.
SDK: software development kit
JDK: java developer kit
Jre: java runtime environment
Ingress- in gress- inbound rules
Egress – out bound rules from server
Flask – framework to build web apps. Like express.js or node.js
dal: Data Access layer, in python you add this from the module you reference. It allows encapsulated API calls or DB queries. Ex.- From dal import …. As …
Thick provisioning: fixed storage (faster)
Thin provisioning: dynamic storage allocation(slower)
Internet Gateway VS NAT Gateway: NAT allows outbound traffic only, usually from private servers, while IGW allows both directions(incoming too)
URI: uniform resource identifier – in aws task definition- put image URI as the pull request(NOT URL, cause it doesn’t give network location)
URL: uniform resource locator, all URL’s are URI, see above why. A Non-URL URI ex. urn:isbn:0451450523
ISBN: international Standard Book Number. Unique id for each book and publication.
KMS: Key management service ( aws)
Webhook: trigger
like in git action which creates an http POST, can be used for notifications.
RESTful app: Repersentational state transfer (POST, GET req. etc)
Stateless: an app that doesn’t need user data to respond, an app without a “session” data. But it can be dynamic app. (static apps are all stateless)
Stateful: an app that does retain the session data, and need it to respond to user.
NFS: network file sharing , can be a server.
Routetable: איך אפשר לעשות פינג לסבנט1 אם אתה בסאבנט2? הראוט-טייבל מחבר בינהם. וגם נותן לך אפשרות להחליט מי ציבורי ומי פרטי
CRD: costume resource definitions
CDA: Content
Delivery Application, it gathers info/data from clients, like transactions.
Extended Regular
Expression (EXE): as opposed to BRE( Basic regular
expression) certain characters don’t need to escaped via special notation
to be read.
Monolith: Db+Fontend+Backend+App+OS+Middleware+Queue Management all on 1 machine.
PostgreSQL: (postgress in short) advanced database open source, that can use both SQL and non-SQL.
Drupal : like wordpress
Mutable
infrastructure: where any update or change are applied directly to the
instance.
Which will eventually can cause inconsistency/conflicts in versions of dependencies.
Because as the instance progresses with versioning it become more and more
Different from the original. For ex. Your OS needs to be updated because it doesn’t match
Your app version or dependencies. In immutable you don’t have that problem.
Immutable infrastructure: like images, that every version can replace the whole instance-Container.
Reverse proxy: לוקח כתובות של הבקאנד, ועושים להם פורוורד לאיי פי שלו החיצוני/ציבורי
יושב
בין הקליינט
לשרתים,
ומתווך בינהם,
לדוגמא כדי
למנוע
וירוסים, או
לעשות לואד
באלנסינג.
ולכן,
האיי פי שנצפה
על ידי השרת
האמיתי שמארח(שזה
לא הפרוקסי),
הוא האיי פי
של הפרוקסי
במקום
של הקליינט.
כדי שהשרת
המארח יקבל את
האיי פי של
הקליינט, צריך
להעביר לו ב
HEADER
Forward Proxy – יושב
בין הלקוחות
לשרתי
האינטרנט
ומונע כניסת
וירוסים או
עושה קאש
להיסטוריה של
הלקוחות.
HA-Proxy: free/open-source web server that can function as network loadbalancer of linux
NGINX: reverse proxy webs server, open source. Can also function as loadbalancer.
BGP: Border Gateway Protocol, in a cluster context, of metaLB, it’s a mode(not layer2 mode) it uses BGP to advertise IP addresses
Assigned to LoadBalancer type, so that for example it can expose MULTIPLE services, instead of working
With
just one load balancer per service. Because it assigns IP per service.
Service-Mesh: dedicated infeastructure for communication/layer to communicate in microservices env. , while maintaining high
Visibility, secure comm, without chages to individual services.
Requires sidecar/envoy(see istio, contour or ambassador ingress for more)
Usually microservices start small and grow. Which is why the “mesh” part is required.e
Annotation: like tags in aws, or sort of label, to be attached to a resource. But they can re-configure or configure these resources via the annotation.
IdemPotence: a concept in computer science. Meaning no matter if you run the same script again and again- it will remain the same consequences.
In ansible for example, running the same playbooks multiple times- will result in the same result, not unexpected additions.
SNMP: Simple Network Management Protocol, used to monitor and managing network devices. Can query them(unlike syslog)
SAML 2.0: (Security Assertion Markup Language) open standard for authentication and authorization mostly between identity provider(IdP) and service provider.
Used to single sign on(SSO) on web apps, to authenticate once.
Uses XML to pass messages, geared more toward enterprise security
OAuth: Open-standard Authorization protocol.
Uses JSON to pass massages, geared for more user experience. Differs from SAML as it allows access using for ex. google
To allow access to third party app. While SAML is the login itself with the users credentials.
. OAuth is simply allowing access to a resource/app/web service by using credentials of another. Like google.
It doesn’t log you in. but uses the other login to allow limited access.
Access Token: ex. JWT(JSON Wen Token) persists login of a user, without relogging him, by refreshing his token and auth him.
SSO : Single Sign On, allows users to login without the need to input their credentials again(unless expired session).
ADFS: (Active Directory Federation Services) provides SSO and secure sharing of identity info between organizations, through SAML mostly.
DownStream
service: a service that receives data from another service, UpStream service-
forwards data to another service
IaC – infrastructure as Code, like terraform and AWS cloudFormation, in which the code is building the infrastructure>servers, networks etc.
PaaS- platform as a Service, users control their app, but not the infrastructure-like OS or hardware,network. /Cloud computing model
Ex. Heroku, Google App Engine, AWS Elastic Beanstalk, Microsoft Azure App Services.
IaaS- infrastructure as a service, virtualized physical computing resources, the provider is the host of this, while the client is responsible for managing and data. /Cloud computing model
Ex. AWS(EC2), AWS Elastic BeanStalk, Azure App services.
SaaS- software as a Service, the provider is delivering the software for the user to use. User has no control over the app. /Cloud computing model
Ex. Google Workspace, Microsoft Office 365, Salesforce
KPI: key performance indicators- measurable value that demonstrates how effectively a company
(40% up time is not good, and 90% uptime can be good, hard call)
DoS: Denial of Service attack. Hacking which prevents users to access their servers/apps.
OOP: object oriented Programming, which can use ORM(object relational mapping) to translate relation DB to nonSQL DB or vice versa.
OOM: out of memory
Network ACL: network Access Control Lists(in aws) provide firewall security per subnet. Or a more costumizable of securing. Like port range etc
SHA-1: the hash protocol for git commits
OOM: Out Of Memory
RSS: resident set memory, allocated ram in Kb for a process
example: Prometheus property- sum(container_memory_working_set_bytes{container!=""}) without (container) -- shows RSS memory
Blue/Green deployment strategy: duplicate environments. With these conditions-Blue is the stable online for clients, and green is the under development.
When blue is down traffic can be routed to green , and make it blue-Thus maintaining HA, but can be costy, and DB mirroring is challenging.
Canary strategy: deployment of an updated version for a subnet of users, to test if canary “dies”, the other users are under the stable env.
And thus the canary env users/clients can be quickly switched to the stable env, if needed.
Compute optimized(Cloud): a machine optimized for computing, gaming, machine learning, high processors count.
Memory optimized(Cloud): a machine optimized for large datasets of memory, like databases.
Network optimized(Cloud): a machine optimized for networking, that require high speed networking, large scale distributed computing, or high performance web-servers.
Trunk based development: One main branch on all env. And feature branches merging into the “trunk”. Documenting a lot. Env on separate folders with kustomize to navigate through env.
Advantages over branch-per-env is much less PR’s(3 PRs at least per env), and less conflicts.
Crossplane: open source project allows management of clouds via kubectl/k8s, for example using kubectl to create s3 bucket.
JWT: JSON web Token- one use case is using the token to connect from (argocd as example) to github apps.
JWT is generated via a secret, it hashes itself using that secret- so that both sides can verify, but the secret has to be on both sides obviously.
JWT expirey is usually made short for security.
DNS record types:
1. A Record (Address Record) = from domain to ip(v4)
example.com A
192.0.2.1
example.com
to a specific server's IP address.2. AAAA Record (IPv6 Address Record) = from domain to ip(v6)
example.com AAAA
2001:0db8:85a3:0000:0000:8a2e:0370:7334
example.com
to a server's IPv6 address.3. CNAME Record (Canonical Name Record)
www.example.com
CNAME example.com
4. MX Record (Mail Exchange Record)
example.com MX 10
mail.example.com
example.com
to the correct
mail server.Authentication method for Email service
providers,
If the email really associated with the domain
it claims to be from. Verification via receiving server.
3. SPF record (Sender Policy Framework)
Which IP addresses are authorized to send emails on behalf of their domain.
Only *1* spf record per domain! --- unless with include
SPF include/multiple spf explained
4. DMARC (Domain-based Message Authentication, Reporting& Conformance)
Uses DKIM and SPF both, decides what to do with failed authentication emails.
Can
instruct server to reject/spam/ deliver. + provides reporting on failed auth
attempts.
Detailed DMARC
setup on all options
How to setup DKIM SPF and DMARC on google
5. TXT Record (Text Record)
example.com TXT
"v=spf1 include:_spf.example.com ~all"
6. NS Record (Name Server Record)
example.com NS
ns1.example.com
7. SRV Record (Service Record)
_sip._tcp.example.com
SRV 10 60 5060 sipserver.example.com
8. PTR Record (Pointer Record)
1.2.0.192.in-addr.arpa PTR example.com
9. CAA Record (Certification Authority Authorization Record)
example.com CAA 0
issue "letsencrypt.org"
10. SOA Record (Start of Authority Record)
example.com SOA
ns1.example.com admin.example.com 2021041501 7200 3600 1209600 3600
1. A Record:
example.com A 192.0.2.1
example.com
to the IPv4 address 192.0.2.1
.2. AAAA Record:
example.com AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334
example.com
to the IPv6 address 2001:0db8:85a3:0000:0000:8a2e:0370:7334
.3. CNAME Record:
www.example.com CNAME example.com
www.example.com
to example.com
.4. MX Record:
example.com MX 10 mail.example.com
example.com
to the mail server mail.example.com
.5. TXT Record:
example.com TXT "v=spf1 include:_spf.example.com ~all"
6. NS Record:
example.com NS ns1.example.com
ns1.example.com
as an authoritative name server for example.com
.7. SRV Record:
_sip._tcp.example.com SRV 10 60
5060 sipserver.example.com
example.com
with priority 10
, weight 60
,
and port 5060
.8. PTR Record:
1.2.0.192.in-addr.arpa
PTR example.com
192.0.2.1
back to example.com
.9. CAA Record:
example.com CAA 0 issue
"letsencrypt.org"
example.com
.10. SOA Record:
example.com SOA ns1.example.com
admin.example.com 2021041501 7200 3600 1209600 3600
DNS RESOLUTION
Allows resolving a certain domain by using
a reference ip to resolve it, in linux the file is resolv.conf
In windows: go to ethernet/network(windows+R
> ncpa.cpl) select internet protocol v4>properties> Preferred DNS server: 8.8.8.8, Alternate DNS server: 8.8.4.4
To flush
dns:
Ipconfig
/flushdns , in case caching of site retains.
SUBNET:
נוסחא לחישוב כמות IP עבור מספר SUBNETMASK: 2^(32-subnetmask)
/16 subnet of
Means
2^(32-16)=2^16-2=65,536
addresses
כלומר 2
בחזקת 32 פחות
מספר הסאבנט,
אם זה 8 סאבנט
זה 32-8, כלומר 2
בחזקת 24. ככל
שיותר קטן,
יותר כתובות
פנויות.
מייצר
תרגום בינארי
לכתובת IP
של הROUTER,
ומשם מאפשר
לייצר עוד
הרבה כתובות
של
מחשבים/מכשירים(מדפסות,
ראוטר)
שמתארחים.
אבל
למעשה מיוצג
בחוץ כמחשב
אחד.
הגדרה
של הרבה
מחשבים ברשת
אחת. ההגדרה
מתבצעת על ידי
קביעת תחום,
נניח 24 סיביות:
10.0.0.0/24
אומר
שיש 255 מחשבים
ברשת הזו, ואז
ניתן לגשת לכל
אחד לפי המספר
שהוקצה לו
ברשת.
ללא
הSUBNET MASK
המחשב המארח
לא יידע לאיזה
מחשב לפנות
ברשת המקומית
שלו(מי זה מי?)-
וגם
מאפשר הקצאה
של רשתות
קטנות יותר
כדי שלא יהיה
עומס על כל
הרשת בשידור.
(המספר
הבינארי
שמייצר הMASK מפריד בין
מה שמייצג את
כתובת הרשת
ומה שמייצג הHOST)
the individual number inside the IP address(first
3).
המספר
האחרון מייצג
כמות המחשבים
שחיברת לאותה
רשת
כל מספר
סאבנט מייצג
רשת נפרדת
בייצוג
ניתן לכתוב את
זה אחרת עבור
כל מחשב:
לדוגמא:
10.0.0.1 מייצג
מחשב אחד
ברשת-ואם נרצה
יותר מ255
10.0.1.0-255
הסיביות
של הסאבנט:
10.0.0.0/32 =
מכונה אחת
10.0.0.0/24 = מדבר
עם כל ה255
מחשבים
10.0.0.0/16 = קולט
גם את הספרה
שאחרי . 255*255
0.0.0.0/0 : all
the address in the whole world!
עולם ה SUBNET
מורכב מ- 3 classes
CLASS A: 0-126.
0-255. 0-255.0-255
CLASS B : 128-191….
CLASS C:
192-233…
CLASS A : BIG
:
:
CLASS D: SMALL
UDP לא
ייעודי
לחיבורים אין
האנדשייק
שמאשר שהמידע
הגיע, טוב
לפיר טו פיר, -
TCP כל בקשה או
פינג, חוזרת
עם תשובה עם
הגעה ליעד –
TLS – מוצפן TCP
STDOUT-
standard output (מה
שרואים כפלט
על הקונסולה
במסך)
SPOOL- השירות
השהיות של
המשימות
מדפסת, QUEUE
CIDR –
classless inter Domain Routing, צורת תיווי
שמייצגת
טווחי כתובות
אייפי, להלן
ייצור הסאבנט
לדוגמא
192.168.0.0/16
זה ייתן
SUBNET MASK :255.255.0.0
uWILDCARD MASK:
0.0.255.255
מה
שייתן ל192.168 טווח
כתובות של 0-255
בשני
האוקטטים האחרונים
Std-in std-out
-err: standard input(0) standard output(1), error(2).
Echo $?לדוגמא
בדיקת:
Std-out
זה
הפלט/מה
שמופיע במסך
אם
יש מספר חוץ מ-0
זה אומר שלא
הצליחה
Piping: להשתמש
בפלט כקלט
לפקודה הבאה- stdout |
command
Cat kern.log | grep 1
Redirecting: command > file, file < command
שנרצה נניח לעקוף/לסנן error
find / -user lskywalker 2> /dev/null : /dev/null שזה שופך את כל השגיאות שגיאה2, לתוך הסיפריה
numbers.txt
= “1\n2\n\3\n4\n5”
sort -R numbers.txt > numbers.txt : ייתן קובץ
ריק(במקום
סידור אקראי
)כי השימוש ב <
קודם מוחק את
הקובץ
Stdin
< command:העברת
קלט לפקודה
wc -l < numbers.txt
{ls
/etc > lsetc.txt} , sort < lsetc.txt is like cat lsetc | sort
Tee : stdin>tee >stdout/file1 : gives stdout in two directions. כלומר יתן לנו גם לשפוך או לעשות מניפולציה וגם יציג במסך מה שעשינו(כי לינוקס לא מציג כלום אחרי פקודה)
Ls /etc | tee file2 file3 : ישפוך את תכולת הרשימה ל2 הקבצים וגם יציג על המסך את מה שהוא שפך. ברידיירקט רגיל אי אפשר לשפוך ליותר מקובץ 1
Xargs: יכול לשמש כפייפ שמפעיל פקודה על סטנדרד אאוט
Cat text.txt | xargs echo
Cat args1 args2 args3 | xargs <command>
דוגמא נוספת:
Here document
cat
<<EOF > file.sh
#!/bin/bash
echo
"This is a test script"
echo
"The current user is $USER"
EOF
כלים לבדיקת דומיין:
MX TOOLBOX
DOMAINTOOLS
WIRE SHARK-
לוכד את כל התקשורת שיש במחשב
מנתח מידע וגם מוציא כתובות
MAC
יכול לעזור שאין פינג
אפשר
לבחור
קוניפגוריישן
פורפיל ואז
לבחור עמודות
שאנחנו
בוחרים
בניתוח
שיהיה רלוונטי
לנו
WIRE SHARK סניפר של פאקטץ –
LYNIS: security, vulnerability כלי לבדיקת lynis –check-all –quick רצוי לפני שליחת PROD
REGEX: כלי אונליין לבדיקת, לפי שפת סקריפט SYNTAX של טקסטים
AWSCLI: כלי לאמאזון שעובד כטרמינל
SELENIUM: סיפריה
בפייתון
שמריצה
דימויי של
יוזר לאתרים(שעושה
קליקים
ומכניס תוכן
כמו יוזר, אבל
צריך דפדפן)
Kompose: converts docker compose to deployment/manifest for argocd or other k8s
Kustomize: stream editor for yamls - it uses resources: block to indicate the yaml’s to read from. Good for overlays.
It has also the block patchesStrategicMerge: which is merging into existing yaml, as a patch or modification.
Examples:
resources:
- ../../base
- ./service-account.yaml
- ./periodic_job_remove_expired_members.yaml
- ./ingress-core-stg2.yaml
patchesStrategicMerge:
- ./taint-toleration.yaml
- ./service-override.yaml
----à resources uses the yaml in the said folder. And patchesStrategicMerge overrides previous yaml configs.
Jq, yq: JSONQuery, or YamlQuery - stream editor with MUCH better visibility. See examples in manipulating txts,
And allows re-formatting and transforming from json to yaml & vice versa.
Example:
kubectl get cm
config-map -n staging -o yaml | yq e 'del(.metadata.annotations)'
< gets you the configmap file as if written by human, without k8s
references.
Istio, Linkerd: management connectivity and routing of pods in a cluster, while providing great visibility and monitoring. Ideal for microservices
LaunchDrakly, Split: release feature for limited users(subnet) allowing developers to test production without affecting users.
Github Codespaces, GitPod: allowing development in cloud env. Faster iteration times without local pushs.
Telepresence, Okteto: remote debugging and live Development, allowing devs to code directly into the cluster and see changes live.
ArgoCD workflows- tool for CI, creating CI pipelines in a container it generates in the cluster, and runs parallel jobs(like executors in Jenkins)
It has advanced tools like: DAG(directed Acyclic graphs, which is like blue ocean or jenkins display of pipeline), machine learning pipelines,
ETL pipeline(Extract, Transofr * load) for data warehousing and analyticd.
Separate tool from ArgoCD(still opensource).
Github Apps – must be installed into the managed repo, can be used to create complex automations workflows to manage events and other triggers, with fine grained permissions.
Ex. Allows users to login to argocd and access the code in argocd according to their own security permissions/roles, in github
- must integrate with DEX or other SSO/identity integration
KEDA: (Kubernetes Evendet Driven Autoscaler), Kubernetes addon for HPA, it add to its functionality by using event driven autoscaling(horizontally)
TRICKS AND TIPS
Type “code .” to startup vscode on the same folder you are
on gitbash
journalctl
–since="today" –until="tomorrow"
ctrl+R: מילת חיפוש
מהפקודות
האחרונות
-אפשר כמה פעמים
עליו כדי
להגיע לקודם
יותר
בפדפדן/CURL:
56: בעיית SSL
401: unauthorized
יכול להיות מJWT TOEKN לא מעודכן,
אין מספיק
הרשאות
403: FORBIDDEN
כניסה אסורה
בכלל.
422:
VI- -
הכלי
הרגיל של
לינוקס לערוך
טקסט.
UNDO:
לוחצים esc
ואז U
SECURE
SHELL(SSH)תקשורת
מוצפנת בין
לקוח -שרת
איך
זה עובד?
לדוגמא:
אם
מחשב 1 רוצה לSSH
למחשב2, מחשב 2
חייב שיהיה לו
את הPUBLIC KEY
של מחשב1.
ולמחשב1 חייב
שהPUBLIC
שלו יהיה תואם
לKEY PAIR שלו
שהוא הPRIVATE.
יצירת
SSH בין
שרת ללקוח
מצריכה
שהמפתח
הציבורי/ PUBLIC יהיה
בשרת שמקבל את
הלקוח. וזה
מצריך קופי פייסט
מהלקוח
אליו(של הPUBLIC)
מהמחשב
של הלקוח
שרוצה להתחבר
לשרת, ופייסט
לשרת שמארח/HOST.)את הפאבליק
של הקליינט)
לכן
עובדים עם GITBASH או PUTTY או
אחרים, כדי
להעתיק את
המפתח.
כלומר
הPUBLIC זה
השם שלך
בהזמנה, והPRIVATE KEY זה
השומר שמוודא
שזה אתה.
שלבים:
התקנה
בUBUNTU
Sudo apt install sshd-server
האם
פעיל ? systemctl status
sshd
לאפשר
SSH בUFW: sudo ufe allow ssh
לדעת
איזה פורטים
פתוחים ציך
להתקין NETTOOLS-
sudo apt install net-tools
ואז
netstat -tanup
SSH
דרך נתיב
PRIVATE KEY
Ssh -i
“<PATH>/PRIVATE_KEY” (טל
הדר יודע)
לג'נרט
SSH
בלינוקס: ssh-keygen -t rsa -b 4096
הגדרות
נוספות לSSH נמצא ב /etc/ssh/sshd_config
שם אפשר לשנות
פרמטרים
בכניסות SSH
.ssh/authorized_keys : קובץ
שמכיל את כל הPUBLICS
אם
SSH
נכשל :host verification
failed
אפשר
לעשות:
Rm /c/users/ariel/.ssh/known_hosts
או
רק למחוק את
המפתח עם הIP
שאליו רוצים
להכנס(שמצפה
למפתח אחר)
Bash linux:
Ssh-keygen -t rsa -b
4096 !!!!
גילוי
תקלות בכניסה
לSSH
Ssh -v
ariel@127.0.0.1
כניסה
בSSH לAWS:
Ssh -i
“<PATH OF PEM>” username@<ip of server in aws>:
שים לב
למרכאות. Identity=i
קובץ
CONFIG
שנמצא בתוך .ssh/~
, מייעל ומפשט
תקשורת בSSH:
Host- nickname
HostName- name or IP
User-default user for communication
Port – port to connect
IdentityFile – the private key path
Example:
Host
myserver
HostName myserver.example.com
User myusername
Port 2222
IdentityFile ~/.ssh/myserver_private_key
Host
github
HostName github.com
User meditator3
IdentityFile ~/.ssh/github_private_key
העתקת
קבצים בין
מחשבים/שרתים
דרך SSH :
scp -P
(port num) <file name from computer> <user@ip_server>:<path>
דוגמא:
scp -P 2222 atlassian-bitbucket-8.8.2-x64.bin ariel@127.0.0.1:/tmp
בAWS
Scp -i “ariel-ket.pem”
<FILENAME> ubuntu@3.17.23.140:/home/ubuntu
Cyberduck
מוונידוז
למכונה:
בוחרים
SFTP, שזה SSH FTP,
ממלאים רק שם,
ואת IP של השרת.
ואז בוחרים
בתור KEY
את המפתח האישי,
שנמצא תחת .ssh id_rsa
NAT
יספק לנו IP חיצוני,
יחיד, לכל
הרשת, לכן
נגדיר רשת
פנימית כדי
שיהיה לנו
כתובות לשאר המחשבים.
בכרטיס רשת
נוסף.
לדוגמא
אם יש לנו
לינוקס DESKTOP
ולינוקס SERVER. נגדיר STATIC IP לכל
אחד מהם (נגיד
בהפרש של 1 בIP)
בVM BOX זה internal network ככרטיס
רשת נוסף
בלינוקס
DESKTOP
פשוט מגדירים
בכרטיס רשת IP
שאנחנו
בוחרים וSUBNET נניח 255.255.255.0 ,
ללא GATEWAY.
ואז צריך
לרפרש את
הכרטיס(לפתוח
לסגור).
בשרת
UBUNTU
אנחנו נכנסים
לקובץ שנמצא
תחת /etc/netplan/
בAWS
יש לו שם עם CLOUD, בUBUNTU רגיל
בד"כ 00-netplanner.
זה קובץ YAML
ושם עורכים
ומוסיפים
בזהירות
את
הנתונים של
הכרטיס רשת
החדש, נניח enp0s8.
באותו גובה
שדה של הכרטיס
שכבר שם.
ומוסיפים באותו
גובה dhcp4: false
ותחת אותו
גובה שדה של DHCP4,
מוסיפים addresses:
מתחת
שדה אחד קדימה
עם – את
הכתובת
שאנחנו בוחרים.
וגם את הSUBNET /24
שזה נותן את
הסאבנט של 255.255.255.0
אחרי
שסיימנו את
ההגדרות יש
להחיל את
השינויים sudo netplan
apply
BOOT:
קבצי KERNEL
מערכת. אם
נגעתי
בקובץ-המערכת
לא תעלה
TMP:
קבצים זמניים.
צבע
זוהר-כל
ההרשאות
אפשריות
בתיקיה זו
DEV:
קבצי DEVICE
קבצי התקנים.
קבצים צבועים
בצהוב-כי הם
התקנים.
ETC:
תיקיה מפעילה.
קבצי מערכת ,
כמו SYS32
MEDIA:
תיקיית CD
או USB
MNT:
שמעלים נניח
כונן פיזי
נוסף
OPT:
תיקיה
שמחלצים בה
אפליקציות,
כמו PROGRAM FILES
PROC: PROCESSES , יותר
עולם של SYS
ADMIN
RUN:
כלים שניתן
להשתמש בהם +
משימות שרצות
בBOOT. SERVICES
ועוד.
SWAP:
שימור גרסאות
קודמות של
התקנות
SYS: PLACEMENT
לשירותי
מערכת, אין
קבצים – או רק
מצביעים שהם
בשימוש
המערכת.
USR: לא
תיקיית USER.(maybe Unix System Resources) תיקיה
משותפת של
המערכת קבצים
שנשתמש בהם.
יש כאן
תוכנות,תוספות,סיפריות,סוג
של APP DATA?
VAR: גם
יש תיקיית עם
שיתוף, אבל לא
כמו USR.
חלק מותקן בVAR
ועובד דרך USR(ההפעלה),
לדוגמא.
תיקיית
LOGS: /var/log/ --
n כל
הלוגים של
המערכת. DPKG-התקנות.
DMESG-התקנים
שמחברים בBOOT
לינוקס. AUTH-היסטורית
כניסות
יוזרים ומה
שקשור
לאוטנטיקציה. SYSLOG: כמו EVENT VIEWER. FAILEDLOG-לוג
כשלונות.
n כשנרצה
לראות רק את
השורות
האחרונות -כי
זה האחרון
מבחינת הזמן –
נעשה tail
-netstat
מציג פורטים
פתוחים netstat
-tanup
-ipconfig מציג IP קיימים בהתקני רשת
Ip addr : מציג בצורה מקיפה יותר מIFCONFIG כתובות רשת מקומיות על פי התקני רשת
-ping
בודק תקינות
תקשורת עם
כתובת IP
-route:
ניתוב
מחדש לאותו
דומיין route add
-net <ip that you want to reroute> netmask 255.255.255.255 gw 192.168.0.1
<<your router gateway
-nslookup : תרגום
כתובת של
אינטרנט כמו DOMAIN NAME,
לכתובת IP
Arp : מראה את
כתובות הMAC –
הכתובת
הפיזית של
ההתקנים arp -a
Tracert: מעקב אחרי הPACKETS -כל המסלול שלה, איזה IP היא עוברת, ואיפה יכולה להיות איטיות אם המסלול או נקודה מסוימת איטית מדי. ראה BGP במושגים.
Curl telnet://<IP>:<PORT> -vvv : shows telnet communication over a designated IP, incase telnet isn’t installed
Uname:
מצציג מידע על
השרת/מחשב uname -i איזה מע,
הפעלה והאם 32
או 64. Uname -a
גרסאת המכונה.
Parted:
מציג PARTITION,
parted -l מציג
רשימת PARTITION
לסדר
אחכ
לקטגוריות:הרשאות-משתמשים
Last : כל
המשתמשים
האחרונים
Grep -i
<username> /etc/passwd : מציג
את כל היוזרים
Grep passwd -S
<username>
: מציג
פרטי היוזר –
אם נעול וכולי
Echo “hello there” |wc -w : סופר
כמה מילים יש //2
לגלות
IP של
המכונה: hostname
-I איי גדולה
שם
המכונה: Hostname
לדעת איזה גרסא של UBUNTU LINUX :lsb_release -a , אם זה 20 מייצג את השנה(2020). אח"כ זה החודש, והגרסא. לדוגמא 20.4.5 זה שנת 2020 מחודש אפריל גרסא 5,
איזה
גרסא של CENOTS:
cat /etc/os-release (ID=)
איזה
פורטים
פתוחים ב FIREWALL : sudo ufw
status
איזה
פורטים
מקשיבים : netstat -tanup
התקנת
כלים לתקשורת
: sudo apt install net-tools (
אם אין NETSTAT)
איזה
IP
פתוחים עכשיו:
ip addr show
בודק
קבצים
ותהליכים
פתוחים לפי
פורט/סוקט : lsof
מראה
רכיבי חומרה: lshw
Process כמו
: task manager top
מה
עובד ברקע? Ps -aux
להרוג
PROCESS: kill <PID(process id)>
האם
PROCESS
זה רץ? Ps -ef | grep
<name of process> | grep -v grep
כמה
זכרון
בדיסקים, מידע
על בלוק LEVEL:
lsblk
איזה
SERVICES
רצים עכשיו : systemctl
list-units --type=service --state=running
כמה
מעבדים יש לי? Lscpu
כמה דיסק פנוי? Df -h / -i(inode)
סוג
המערכת קבצים: df -T
מה
גודל/כובד
הספריה du
-sh <name of folder>
גודל
כל התיקיות
בתיקיה
הנוכחית? Dh -h –max-depth=1 ./
כמה
RAM
פנוי? Free, free -h(page file), watch
free
ERROR
שהיו לנו: journalctl -xe או systemctl status <name of service>
רק
סיפריות/תיקיות:
ls -d */
Sleepy – הפעלת
סקריפט ברקע
איזה
SERVICES
עובדים ברקע? Systemctl
list-unit-files
איזה
גרסא השרת? Uname -a
איפה
ממוקמת
הפקודה – MAN WHICH
Useradd:
הוספת יוזר,
יותר מתאים
לסקריפט. עם -m נייצר
תיקיה ליוזר .
-d נקבע שזו
התיקית HOME
של היוזר: sudo useradd -d /home/dtrump -m dtrump
Adduser – אם
צריך רק
להוסיף קצת
Passwd - שינויי
סיסמא ליוזר
Whoami – איזה
יוזר עכשיו?
איזה
קבוצות
המשתמש נמצא
בהן – cat etc/group או groups
או
עבור משתמש
ספציפי cat
etc/group | grep ariel
כל
הפקודות
האחרונות – history
Usermod – שינוי
דברים בתוך
יוזר, לדוגמא
– הוספה לקבוצה
Usermod
-a(append) -G(group) sudo lskywalker –
יכניס את
המשתמש הזה
לקבוצת ה סודו
נעילת
משתמש – sudo
usermod -L dnltrump
שחרור
משתמש – U-
רשימת
משתמשים בעלי HOME- cat /etc/passwd |grep home
נעילת
יוזר : passwd -l
<username>
איזה
יוזר נעול? : sudo passwd -s <username>
נעילת
כל המשתמשים: @
היסטורית
כל הפקודות: cat ~/.bash_history
מחיקת
יוזר – deluser לסקריפט,
או USERDEL לשימוש
בSHELL.
רפרוש
של הרשת, שלא
צריך לאתחל את
המחשב: sudo
systemctl restart networking
הצג
רק סיפריות
בתיקיה
הנוכחית: ls -d
רק קבצים : ls -p -type f
הצג
ממוין לפי
גודל קבצים: ls -lS
הצגת
שגיאה מפקודה
אחרונה : echo
$?
RUN IN THE
BACKGROUNDהוספת
פרוסס
ברקע/סקריפט
שירוץ ברקע:
פקודת הרצה ו &
Zgrep –
חיפוש בקבצי gz
Egrep –
אפשר לשים כמה
ביטויים בבת
אחרת בהפרדה
של |, לדגומא: ‘ads|ddd|123|’
איזה
קבוצות
המשתמש: cat
etc/group |grep <username>
העתקת
פלט לקובץ : <command, ls or other> > <name of file>
העתקה
לקובץ מ-פלט
בלי לדרוס: <command, ls or
other> >> <name of
file>
Wc-
ספירת מילים, -l כסוויץ מציג
כמה שורות יש
בקובץ
Head –
הצגת 10 השורות
הראשונות
Sort –
סידור קובץ
לפי ABC
או אפשר גם
סויץ -r ברוורס. -nלפי
מספרים
להוציא
מתוך קובץ
ולהחזיר
מסודר: sort -r < <filename> > reverse_order
Tee –
מעתיקה כמו
המשפך. Ls | tee file.txt שומר את
תכולת שמות
הקבצים
בספריה לתוך file.txt
Xargs-
לוקח פלט
ומעביר אותו
לפקודה שלידו: ls | xargs echo יעביר את ls
שיודפס דרך echo
Lsof –
איזה קבצים
פתוחים עכשיו -u מציג על פי USER שבחרנו.
בלי כלום זה
מציג את הכל.
Sudo lsof -n -i4TCP:22 מציג ללא הוסט, על פרוטוקול אינטרנט4, בTCP, מה עובד/רץ על פורט 22(ואם הוא בכלל פתוח)
Ls -p –
מציג ספריות
עם /
Ls -p ~ | grep -v / - יציג רק קבצים כי הgrep מביא רק מה שבלי ה / -p מכליל את הספריות
Grep
<filename> <text> יעשה
חיפוש בתוך
הקובץ לטקסט
Grep -q יביא רק מה
שאין לו כזה,
ויתן EXIT
0 אם אין כלום.
Grep
“^<string>” יביא EXACTLY
את הSTRING
הזה (בגלל ה ^)
עם
Xargs אפשר
לייצר הרבה
מאוד פקודות
על הרבה קבצים
ls -p ~ |grep -v / | xargs cp <filename>
יעתיק
את כל קבצי
הסיפריה למה
שנגיד לו בבת
אחת.
watch -n 1 df -h : ניטור DISKSPACE
בזמן אמת,
עדיף בחלון
נפרד בזמן
התקנות-שנגמר
המקום כל פעם
watch -n 1 'df
-m'
:
to see same thing but in Mb usage
tail -f <filename>
עוקב אחרי
שינויי בקובץ
או בהליך
journalctl -n: נותן את
הלוג האחרון ביותר(רק JOURNALCTL לא ייתן את
האחרונים)
משתני
סביבה ENVIRONMENT
VARIABLES לLINUX:
export
מהם
משתני הסביבה?
env : מציג
את כולם
לדוגמא
שינויי פורט
או איי פי
משתני סביבה:
export
FLASK_RUN_HOST=0.0.0.0
export
FLASK_RUN_PORT=3000
Nmcli
(ראה
CENTOS)
TIME:
Min(0-59) hour(0-23) day(1-31)
month(1-12) day of the week(0-6 or sun -sat)
Crontab -e to setup the scheduler for the script.
Use < * * ..> bash /<path of script>
*= all values
Example 1: (in crontab -e script) 0 20 4 * */path to script/ arg1 arg2 - this will run script every day 4 of month at 20:00.
If you add /<number> it means every <number> hours/minutes/days. For example, a cron of * */12 * * * will run every 12 hours( */12), or */5 * * * * will run every 5 minutes.
Example2: Ever day from 0800 to 2200 but not on Saturdays : 0 8-22 * * 0-5
Example3: * 10,14 * * * ? every day on 10:00 and 14:00
Example4: aws- if day is variable must use ? – for example 0 2 ? * 7 * - every Saturday 2:00.
Date: נותן
תאריך ושעה
, יום חודש
ושנה
Date “+%d/%b/%Y-%R:%S” : 20/Feb/2024-16:33:51 נותן פירמוט לפי מה שהגדרנו
to remove zeroes:
date "+%-y%-m%-d"
date +%z מראה
שינויי בגלל TIMEZONE
+0200
TZ=UTC+2
date "+%-y,%m,%-d" כופה את
הטיימזון
שיהיה ישראל
25,02,6
Centos:
Systemctl status crond
בודק אם CRON מופעל
לבדוק
איזה
סקריפטים רצו
עם CRON: sudo grep cron /var/log/syslog
או:
sudo grep cron /var/log/cron
השוואה
בין קבצים diff <filename1> <filename2>
, שימוש:
לדוגמא קבצי
קונפיגורציה
שגיבינו וערכנו
להם שינוי
אח"כ.
sudo du -h --max-depth=1 / | sort -rh : מציג
את הקבצים
הגדולים לפי
הסדר
Hier - מראה
היראכיה של
הקבצים
Tree –
מראה היראכיה
בצורה גרפית(בד"כ
דורש apt install tree) tree -d -L 2:
ייתן רמת
פירוט LEVEL
2, אפשר לתת LEVEL 3
או יותר כדי
לקבל יותר
עומק בענפים
Tail –
מציג רק את ה10
שורות
האחרונות של
הקובץ, בד"כ שימושי
בLOGS.
אם נרצה לשנות
כמות שורות
נוסיף FLAG -n : tail -n 12 <filename>,
יציג 12 שורות
אחרונות
Head –
מראה את ה10
ראשונות. גם
שימושי בSCRIPTING
Lsof – מראה איזה קבצים פתוחים. Ls open files
Du -sh <name of folder> - מציג כמות דיסק בשימוש על פי הסיפריה(כמה שוקלת הסיפריה)
Gzip -d <filename>
Unzip <filename>מחלץ EXTRACT קבצי ZIP
Tar -xvzf <filename>
סקריפט
קבלת שמות
תיקיות והצגת LS בכולן, לא
משנה כמות
התיקיות
ששמים
העתקת
קבצים בין
מחשבים/שרתים
:
scp -P
(port num) <file name from computer> <user@ip_server>:<path>
דוגמא:
scp -P 2222 atlassian-bitbucket-8.8.2-x64.bin ariel@127.0.0.1:/tmp
Scp -i “ariel-ket.pem”
ubuntu@3.17.23.140:/home/ubuntu/<FILENAME>
^^
למשוך קבצים
מהענן אל
המכונה שאני
נמצא בה.
Rsync(יש
להתקין APT):
Shred:
גריסה של
קובץ-אבל לא
מחיקה שלו.
סוג של ENCRYPT
אבל לא ניתן
לשחזור!
שימושי
במצבים
שהאקרים
מנסים לגעת
בקבצים חשובים.
Wipe:
מוחק לגמרי
מהקונן ברמה
הפיזית/המגנטית.
Locate {שם
קובץ שמחפשים}
צריך
להתקין דרך mlocate
או
Find / -name {name of file} 2>devnull
2>devnull removes error of permissions.(error 2)
Rsync : אולי צריך להתקין, יודע לשים לב לשינויי קבצים בספריות שנגדיר לו- ואז ישמור אותם
Rsync -avz <name of folder> <name of
target>: if we add –delete ימחקו
קבצים לא
קשורים בתיקיית
היעד. FLAGS:z מכווץ v verbose, a ARCHIVE-משמר
את כל תכונות
הקובץ מבחינת
הרשאות תכונות
ובעלות
Rsync -avz –delete /root/ tmp/sync-target/ : מוחק
בתיקיית היעד
את הקבצים הלא
קשורים.
דוגמא: ייצר ספריה: dir1 dir2, צור קבצים בdir1, פקוד RSYNC ואז שנה בDIR2 הוסף קובץ לא קשור, ותבדוק אם הDELETE עבד.
אפשרות
1:
SYMBOLIC LINK:
מבוסס
inode(סוג
של כתובת-כל
קובץ הוא בעל
פוינטר
לכתובת של
הקובץ, הפניה). Ls -li
ייתן לנו את
הקידוד של inode
ברשימת
הקבצים.
לדוגמא RENAME
לא משנה inode.
כדי
לבדוק
כמה נשארו לנו
inode: Df -h / -i
אם
יש יותר מדי SYMBOLIC LINK, אז
יכולים להגמר
הכמות של הinode ולכן
לא יהיה אפשר
לייצר עוד
קבצים
-
softlink:
כמו SHORTCUT
בווינדוז. Ln -s <filename path(link to
what)> <link to where> . -s softlink.
כאן משתנה הinode, לא
זהה לקובץ
המקורי.ולכן
שמוחקים זה לא
מוחק את
המקור.
- Hardlink: ln <file name path(link to what)> <link -the new path> ללא -s זה HARDLINK. כלומר אם נמחוק את הLINK זה מוחק גם את הקובץ כי זה אותו הinode , אם לא נשארו עותקים.
§ לדוגמא, אם מחקת עותק אחד של HARDLINK אבל נשארו עוד – הם לא יעלמו כמו שמחקת את המקור בSOFTLINK. כי זה סוג של COPY, כמו עותקים שלא נעלמים. להבדיל מSOFTLINK שאם המקור נמחק, הכל הולך.
אפשרות
2:
/usr/local/bin
אפשרות
3 -זמנית:
Export PATH=<folder path of executable>
אפשרות
4:
לשים EXPORT כמו באפשרות 3 ב ~/.bashrc
Partition (part) זה אומר FIXED – גודל קבוע, לא ניתן לשנות. אלא אם כן זה LVM, וזה מצויין שם.
ללא
LVM לא
ניתן להוסיף
כונן לשרת
והוא קרס
סופית.
Block device: מכשיר
שמאפשר כתיבה
וקריאה של DATA/מידע
בBLOCKS,
ניתן עדיין
להציל דרך BLOCKS.
TRADITIONAL PARTITIONS:
קבועים
וכבולים לנפח,
ולא ניתנים
לשינויי.
:LVM: מגיע
NATIVE עם CENTOS, LOGICAL VOLUME MANAGER, שמאפשר
הגדלה של נפח
ככל שנרצה
ונוכל.
PV: physical volume, כל
הארד דיסק
פיזי נחשב PV.
VG: volume group,
מחיצה/קופסא/קבוצה
שבה יש PV.הקבוצה היא
לוגית/דימיונית.
לדוגמא PV1,
PV2,PV3 בתוך
הקבוצה.
ואפשר
לייצר כמה
מחיצות
לוגיות שנרצה
בתוך השרת. אי
אפשר לשים
אותו PV
בכמה VG
שונים.
LV: logical
volume המצב
שאנחנו
מגדירים שבו
לוקחים את הVG
כמיכל אחד.
ואז למעשה הVG
יכול להפוך לLV וכל
השטח אחסון
הפנוי יהיה
זמין כווליום
ממשי.
בזכות
LV וVG,
אנחנו יכולים
לעשות EXTENSION ולהוסיף
עוד PV, וכך
להגדיל
אינסופית את הLV...הוא
הוא היכולות
של ה LVM
ואין
צורך אפילו
לעשות RESTART לשרת.
Lsblk:
מציג מכשירי
אחסון. גם
וירטואלים
כמו קובץ שמנגיש
אחסון. )loop( SDA
זה בד"כ כונן. SR0 זה CD ROM
Pvdisplay:
מציג פרטים על
קונן/אחסון
פיזי
Vgdisplay:
מציג קבוצות
ווליום, אם
נרצה להרחיב
אחסון-נוסיף
אותו לפי
הקבוצה
מהאחסון החדש.
Lvdisplay:
קבוצות אחסון לוגיים(לא
פיזיים)
Lvcreate:
יצירת VOLUME
חדש לוגי.
Pvcreate:
מייצר אחסון
חדש פיזי, אבל
לא ALLOCATED
Pvcreate /dev/sdb
כדי
למפות אותו
לאחסון הקודם
שיגדיל אותו:
Vgextend: מעמיס/מוסיף עוד שטח אחסון על פי הקבוצה שהגדרנו
Vgextend ubuntu-vg /dev/sdb
או: vgextend -L +10G /dev/ubuntu-vg/ubuntu-lv
Lvextend: הוספת נפח (עם הגדרת כמות) לLV, מתוך הVG.כלומר, מתוך הנפח שנותר בVG שבו נמצא הLV.
Lvextend -L 1.5g /dev/centos/root
בתוך
הVG
יש לנו את הLV, ושם
אנחנו יכולים
לבחור לאיזה PATH
אנחנו רוצים
להגדיל את
הנפח מתוך הVG
הקיים
(שאליו
משוייך הLV). יש לשים לב
להבדל שלמרות
שיש נפח אחסון
פנוי, הכוונה
היא לALLOCATED SPACE.
ולא לDATA
שמאוחסן בדיסק.
sudo vgreduce ubuntu-vg /dev/sdb : מוריד דיסק שחיברנו לקבוצת ה VG. (dev/sdb זה הדיסק שחיברנו)
Df
-T : מציג
את סוגי מערכת
הקבצים נניח ext4, xfs, tmpfs
עבור
מערכת קבצים XFS
Xfs_growfs <path of mapped storage, such as /dev/ubuntu/>
ירחיב
לנו את הדיסק
לתוך מערכת
הקבצים
אחרי
שווידאנו
שאנחנו לא
הולכים לפרמט
את הדיסק שלנו
שקיימם.
בודקים היטב
שאנחנו
מפרטים דיסק חדש
שלא קשור
לכלום:
Fdisk /dev/sdb
L : מציג את כל
סוגי מערכות
הקבצים שיש(עם
הקוד הרלוונטי
שלהם)
P: מציג את
פרטי האחסון
הנוכחי
שאנחנו
מפרמטים
N: יצירת PARTITION
XFS לעומת EXT4 יותר טוב כי יש לו (XFS) גודל PARTITION גדול יותר וגם גודל קובץ גדול יותר. וגם יותר INODES
Mkfs.xfs : make filesystem
ושמים את השם
שלה/קיצור.
Mkfs.xfs /dev/sdb
Lsblk
-f : מציג
גם את UUID וגם את
הסוג מערכת
הקבצים
כדי להוסיף אתחול של מכשיר נוסף לBOOT: יש לערוך את /etc/fstab בזהירות!!!! קובץ רגיש מאוד!!
סדר
כללי להרחבת
קונן :
sequence:
הרמת
VOLUME נוסף LVM
למכונה AWS
אחרי שהצמדנו
אליה VOLUME:
-זיהוי הכונן lsblk, יצירת ווליום פיזי- pvcreate (כי הוא עוד לא מזוהה),
לדוגמא: pvcreate /dev/sdb
-
יצירת VOLUME
GROUP, vgcreate
כדי שנוכל
להכניס את PV
ל"קרטון"/קבוצת
ווליום לטובת
הLV
שמייד יגיע.
- במידה ואנחנו רוצים לעשות EXTEND, להוסיף נפח, נעשה vgextend
יצירת ווליום לוגי- lvcreate, יצירת FILESYSTEM mkfs.ext4 לדוגמא, MOUNT של הFILESYSTEM לסיפריה, עדכון /etc/fstab להוסיף שהכונן יעלה בBOOT
-הוספת נפח
לLV קיים
מתוך הVG
שלו. Lvextend -L +1.5g
/dev/centos/root
בדיקה: LVDISPLAY
שאכן הנפח
השתנה בPATH
המצויין.
-
עכשיו צריך
ליידע את FILESYSTEM על
השינויי,
וצריך לבדוק
איזה סוג FILESYSTEM הדיסק
כדי לסדר את
האיחויי
הסופי.
בדיקה
איזה סוג
מערכת קבצים: df -T
Xfs_growfs /dev/mapper/centos-root
הרמת
MOUNT לATTACHED
DISK
- Fdisk /dev/sdc כאשר SDC הוא הדיסק החדש.. להיזהר שלא מוחקים כלום, זה פירמוט.
- בprompt, בוחרים M כדי לראות מה האפשרויות לביצוע של הפירמוט. הצגת מחיצות קיימות דרך P
- נייצר מחיצה חדשה, ראשית -שממנה אפשר לייצר עוד מחיצות. (עוגה שלמה ואז חתיכות).
-
בוחרים N, PARTITION-1,
בחירת גודל
רצוי(הכל או
חלק)-ENTER
מייצג את הכל.
- כדי לשמור את השינויים בוחרים W וזהו(או מתקנים או יוצאים עם Q)
- בודקים LSBLK, ורואים שהדיסק מחולק(אך לא ASSIGNED), כרגע יש רק מחיצה מוגדרת.
- צריך לפרמט את הדיסק ולסדר לו FILESYSTEM
- הכנת FILESYSTEM: mkfs.xfs /dev/sdc1 הנתיב של הדיסק החדש, אחרי שבנינו לו מחיצה שאפשר לפרמט אותו במערכת קבצים הזו.
- בודקים אם אכן יש FS לדיסק החדש: lsblk -fs וזה מציג איזה FS יש לכל דיסק
- עכשיו צריך לשייך אותו לPATH , נניח בMNT/ mount /dev/sdc1 /mnt
- הבעיה שבLINUX באיתחול מחדש, הMOUNT לא תופס לתמיד, וצריך לקנפג כדי שיעלה תמיד בBOOT
- תיקון- דרך הקובץ etc/fstab , ועורכים אותו VI /etc/fstab וצריך להוסיף את הנתיב. קובץ רגיש מאוד -לגיבויי- יכול להרוס את ההפעלה מחדש!
o /dev/sdc1 /mnt xfs defaults 0 0 וזה אמור לשמור את זה. DEFAULTS או AUTOMATIC אם זה מצבי READONLY.בDEFAULTS זה כולל כל ההרשאות READ WRITE ETC. ברגע שיש 0 בראשון, זה אומר שאין גיבויי. כל מספר אחר מפעיל גיבויי. 0 האחרון זה לבדיקות.
-יש לשים לב לתוכן שקיים במחיצה/דיסק וחייבים לשמור בסיפרייה נפרדת למנוע מצב שזה נמחק
הוספת
נפח בלינוקס Stages of
linux extending to VG:
Lsblk – to ID the new disk attached (ID in machine)
iSudo Pvcreate /dev/sdb : create a new physical volume from the attached disk after seeing it in lsblk(allocating it)
Sudo vgextend ubuntu-vg /dev/sdb : extend the disk to the logical volume group ubuntu-vg (extending)
sudo lvextend -l /dev/ubuntu-vg/ubuntu-lv : extending all storage space to the old VG(indicating how much)
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv : resize (telling the volume group now that it has more space and it can resize now)
Less : show content of file cut into pages , מטעין כל פעם רק חלק לזכרון
Cat
file.txt | less זזים
קדימה עם רווח
More : עמוד
אחד כל פעם גם
Wc: ספירת מילים, -w רק מילים , -l מס' שורות, -m מס' אותיות
Head: מציג את החלקים הראשונים של הקובץ,<filename> -n 1 head יציג רק שורה ראשונה
Tee:
קולט פלט
ושופך אותו
וגם מציג על
המסך. לדוגמא: echo “Hello World!” |tee output.txt
יציג
גם את "HELLO WORLD"
בטרמינל וגם ישפוך
אותו לקובץ
Grep: grep <word> <filename>= cat <filename> | grep
<word>
Grep
-v <word> <filename>
:
נותן את כל מה
שאין בשורה
שלו את word
Grep
-i <word>
<filename> : מתעלם מ upper/lower case
Grep
‘^Feb 15’ auth.log
:
ה-^ מגדיר
תחילת שורה,
כל מה שבתחילת
שורה יש את הטקסט
הזה. ולכן
ייתן כל
הכניסות של
פברואר 15.
Grep
‘host$’ auth.log
: $
מציין סוף
השורה, כל מה
שיש לו טקסט
בסוף השורה
הוא ייתן.
Zgrep -
חיפוש רק
בקבצי ZIP או
GZ
Egrep – חיפוש בכמה מילות/טקסטים, * egrep ‘10|127|1’ יחפש את כל אחד מהמספרים, ויציג את התוצאות עבור כולם.
Pgrep : לדוגמא pgrep httpd יציג אם
יש תהליך
שנקרא HTTPD
Awk : מאפשר PIPING של עמודות, בין השאר. לדוגמא ls |awk ‘{print $2, $4}’ ידפיס רק את עמודה 2 ו4 של הLS
Sed: streamEditorמאפשר
חילוץ והטמעה
של טקסט מתוך קובץ , sed -i “s/<pattern>/<replacement>/g”
<filename> יש
לשים לב -i
מתכוון לin place שמטמיע
בתוך הקובץ,
כאשר ללא -i
זה רק יציג כSTDOUT
Example: sed -i "s/ansible ansible_host=[0-9.]\+/ansible ansible_hosts=${PRIVATE_IP}/g" /etc/ansible/hosts.
This will replace whatever ip is after ansible_host. s/ is to search and substitute.
Remove
a line with the word web in it: sed
-i '/web/d' hosts_new
add
web to start of existing line : sed -i '/development
is fun/ s/^/web /' hosts_new
cut -
cut
-d’%’ -f1: removes
%, it needs -f# to know which field
to cut also
הערת
נוהל עבודה עם
SED
מאוד
לא מומלץ
לעבוד עם SED על קבצים
שמשתנים עם
הזמן, מאחר
והם יכולים לשבור
תהליכי
אוטומציה אם
הקוד השתנה
בצורה שנקראה
לא כהלכה.
לכן עדיף להעביר את הקוד עצמו למשתני סביבה או משתנים אם אפשר במקומות שבהם צריך לערוך ערך ספציפי במקום שהוא שמור בצורה קבועה.
SED נראה
זוועה.
JQ ו YQ שהם SEDים של קבצי JSON או YAML, עם ויזיביליות יותר גבוהה, דוגמאות –
jq
Example (JSON):bash
· cat data.json | jq
'.name'
· Filter objects in an array:
Get indices(index of place in string)
Jq ‘indices(“, “)’ “a,b, cd, efg, hijk” >> out put is [3,7,12] since “, “ appears in these places in the string.
bash
·
cat data.json | jq
'.users[] | select(.age > 30)'
yq
Example (YAML):bash
· cat config.yaml | yq
'.name'
· Update a value:
bash
· yq
'.name = "new value"' -i config.yaml
· Convert YAML to JSON:
bash
cat config.yaml | yq -o=json
ping:
להשתמש
בפלט כקלט
לפקודה הבאה- stdout | command
Cat kern.log | grep 1
Redirecting:
command > file, file < command
שנרצה נניח
לעקוף/לסנן error
find / -user lskywalker 2> /dev/null :
/dev/null שזה
שופך את כל
השגיאות
שגיאה2, לתוך
הסיפריה
numbers.txt =
“1\n2\n\3\n4\n5”
sort -R numbers.txt
> numbers.txt : ייתן
קובץ
ריק(במקום
סידור אקראי
)כי השימוש ב <
קודם מוחק את
הקובץ
Stdin
< command:העברת קלט
לפקודה
wc
-l < numbers.txt
{ls /etc > lsetc.txt} , sort <
lsetc.txt is like cat
lsetc | sort
Tee : stdin>tee >stdout/file1 : tee gives stdout in two
directions. כלומר יתן
לנו גם לשפוך
או לעשות
מניפולציה וגם
יציג במסך מה
שעשינו(כי
לינוקס לא
מציג כלום
אחרי פקודה)
Ls
/etc | tee file2 file3 : ישפוך
את תכולת
הרשימה ל2
הקבצים וגם
יציג על המסך את
מה שהוא שפך.
ברידיירקט
רגיל אי אפשר
לשפוך ליותר
מקובץ 1
שימוש
בPIPE
כדי לסנן
תיקיות או רק
קבצים:
Ls -p יציג
תיקיות עם /
Ls -p | grep /
יציג רק
תיקיות
Ls -p | grep -v /
יציג רק
קבצים-כי זה
הפוך INVERSE
Rename manipulation, several files:
xargs -n1 -I{} mv {}
{}.jpg | ls or echo
Awk : מאפשר הרצת
פקודות מתוך STDIN
בעזרת ‘{}’
שהפקודה בתוך.
לדוגמא כדי
לראות רק
עמודות 1,2,אחרונה
בתהליכים : ps aux |awk ‘{print $1, $2, $11}’ | tail -n 10
|grep ariel
יציג
10 שורות
אחרונות רק של
המשתמש ARIEL,
ורק העמודות
שמצוינת בAWK
עוד
דוגמא לתיעול STDOUT :
Find / 2>/dev/null |grep mod_proxy
יציג תוצאות
של MOD_PROXY עם
מסנן של כל מה
שאין לנו
הרשאות לראות.
שמים את DEVNULL
לפני כי הGREP לא מראה PERMISSION DENIED
לראות רק תכולת הARCHIVE: tar -tf bundle.tar
TEXT EDITORS:
VI- U undos while on escape mode
? finds a stirng
Drw-r—r—
D-
מייצג DIRECTORY כלומר
תיקייה
קבוצת
ה3
הראשונים-עבור
הרשאות היוזר
שבעל הקובץ
קבוצת
ה3 האמצעים
עבור ההרשאות
של הקבוצה שקשורה
לקובץ
והאחרונים
זה איזה
הרשאות יש
לשאר העולם.
Chmod u-w
מוריד הרשאת
כתיבה עבור
בעלי הקובץ הUSER
+w יוסיף
הרשאת כתיבה.
U: זה
עבור יוזר
G:
עבור הGROUP
O:
עבור OTHERS,
כל השאר.לדוגמא:
Chmod uo+x נותן
הרשאת הרצה EXECUTE
לקובץ עבור הuser והother
usermod -aG <name of group>
: מכניס את
המשתמש
הנוכחי
לקבוצה
- groupadd GROUP_NAME:
קובע קבוצה
חדשה
Chown –
שינויי הרשאה
לסיפריה/קובץ :
chown :GROUP FILE_NAME
Useradd
– הוספת
יוזר, יותר
מתאים
לסקריפט
Adduser – אם צריך
רק להוסיף קצת
Passwd -
שינויי
סיסמא ליוזר
Whoami – איזה
יוזר עכשיו?
איזה
קבוצות
המשתמש נמצא
בהן – cat etc/group
Groups:
מציג את כל
הקבוצות שיש
למכונה
או
עבור משתמש
ספציפי cat
etc/group | grep ariel
איזה
משתמשים יש: cd home
או cat /etc/passwd
מה
קורה שקובץ עם
הרשאות
מסוימות עובר
לתיקיה עם
הרשאות אחרות?
-
כל
ההרשאות
הולכות איתם
לא משנה איזה
הרשאות יש
בתיקיה. גם אם
עשינו העברה בSUDO, זה
נשאר אותם
הרשאות לקובץ
שהעברנו.
כלומר בשום
מצב לא ישתנה!
כל
הפקודות
האחרונות – history
Usermod – שינוי
דברים בתוך
יוזר, לדוגמא
– הוספה לקבוצה
Usermod -a(append) -G(group) sudo lskywalker
– יכניס את
המשתמש הזה
לקבוצת ה סודו
נעילת
משתמש – sudo
usermod -L dnltrump
שחרור
משתמש – U-
רשימת
משתמשים בעלי HOME- cat /etc/passwd |grep home
נעילת
יוזר : passwd -l
<username>
איזה
יוזר נעול? : sudo passwd -S <username>
נעילת
כל המשתמשים: @
מחיקת
יוזר – deluser לסקריפט,
או USERDEL לשימוש
בSHELL.לא
מוחק סיפריות
של הנמחק.
-
אפשר גם
ללכת ל/etc/group
ולמחוק ידנית
מהקובץ
איזה
קבוצות
המשתמש נמצא
בהן – cat etc/group
או
עבור משתמש
ספציפי cat
etc/group | grep ariel
דוגמאות:
הוספת
קבוצה:
sudo addgroup rebel-alliance
הוספת
יוזר לקבוצה
sudo usermod -a -G rebel-alliance lskywalker
שינוי
קבוצה לקובץ
ספציפי מ-יוזר
ספציפי
chown lskywalker:rebel-alliance
secret-plans.txt
לדארת'
וויאדר יש
קובץ שלו
אישית:
Chown dvader my-stuff
ורק
לקבוצה שלו
מותר לקרוא או
לפתוח
Chmod o-r my-stuff
^^^
זה הייתה
הורדת הרשאה לOTHER
סקריפט
שבודק אם יוזר
נעול או
לא+קיים
סקריפט
שנועל תיקיה לבקשת
המשתמש
Sudo ufw status
Sudo ufw allow ssh
Sudo ufw deny incoming:
חוסם כניסה של
משתמשים (כל
הפורטים)
Sudo ufw allow outgoing:
פותח לכל
המשתמשים
בשרת לצאת
החוצה מכל
פורט.
Sudo ufw enable
לדעת מה החוקים של הFIREWALL כאשר הוא INACTIVE(למקרה שSSH נניח סגור ונרצה לוודא שפתוח) : sudo cat /etc/ufw/user.rules
ב centOS זה firewalld
Scp: (SECURE
COPY)
דוגמא-
scp
username@linux-vm-ip:/path/to/source/file.txt C:\path\to\destination\
ENVIRONMENT
VARIABLES
export PATH=/my/custom/bin:$PATH
:
מאפשר הרצה של
מה שנמצא
בתיקיה למשתנה
הסביבה PATH
ואז אפשר
להריץ כל EXEC שנמצא
בסיפריות
שהגדרנו שם.
סדרך
כלל שומרים את
הקובצים
הבינארים/EXECUTABLES
בסיפריית BIN. זה
יכול להיות כל
תיקיה אבל.
SECURITY: ההרשאות
לא עוברות עם
ההעתקה. אבל
למשתמש במכונה
המקבלת יש
הרשאות לעשות
בקובץ כרצונו.
כאשר
מעבירים
קבצים בין
מכונות יש
תמיד סיכון גם
אם לשבריר
שניה שיהיה
אפשר לדוג את
המידע הרגיש.
עבור
BASH: שבנג, #! /bin/bash
ב
shell : #! /bin/sh
Chmod u+x
<filename> : כדי
לאפשר הרצה של
הקובץ x .
אחרת אין
הרשאה
Sleep 90 -
מחכה 90 שניות
לא ניתן
להשתמש בקונסולה.
אלא אם כן
נריץ ברקע עם &
variables
MY_SHELL=”BASH” באותיות
גדולות מקובל.
$MY_SHELL כדי
לשלוף אותו
Echo $?
מציג את הפלט
שגיאה של
הפקודה..
Echo $!
מציג את הPROCESS האחרון
שנפתח..לדוגמא
סקריפט
שהרצנו
Wait <process
ID> מחכה עד
שיגמר הPID,
ואז ממשיך את
הסקריפט (ראה
סקריפט
לדוגמא)
Pidof <name of script/process>
נותן את מספר
הPID
של מה שכתבנו
בשם, לדוגמא: pidof sleep
Ps -pf <PID>
נותן פירוט לPROCESS
ספציפי, (-p),
עם פירוט מלא (-f)
סקריפט
קריאה מקובץ
וספירת שורות CHARACTERS
Echo -e
מאפשר הכנסה
של CHARACTERS ESCAPE , כמו /
Conditionals
-e:
נכון אם קובץ
קיים
-d : נכון
אם זה תיקיה
-f : נכון
אם זה קובץ
רגיל וגם קיים
-r:
נכון אם יש לך
הרשאה לקרוא
ממנו
-s:
נכון אם הקובץ
קיים ולא ריק
-w:
נכון אם יש לך
הרשאה לכתוב
על הקובץ
-x:
נכון אם יש לך
הרשאה להריץ
את הקובץ
-z: אין
כלום בSTRING
If [ -e /etc/passwd ]
Then
Echo $
Fi
=
או -eq אם יש
שיוויון
-lt קטן מ-
Elif
כמו
בפייתון
-o
: OR לדוגמא $SIDE1 -eq $SIDE2 -o $SIDE1 -eq $SIDE3
||
:
גם OR
בצורה אחרת [ $SIDE1 -eq
$SIDE2 ] || [$SIDE1 -eq $SIDE3 ]
-a
: AND
Exit 1 : יוצא
מהCONDITIONAL
סקריפט שממיין מספרים שלמים בלבד(ומתעלם מעשרוני)
Add numbers from
variable:
C=3
Echo $c + 1
3 +1
Echo $(($c + 1))
4
Add counter to
lines
Filename | cat -n
Comparing STRINGS in bash
[[ comparison ]]
Bash
scripts that displays running pods or pending
pods+counts how many
For loops
For COLOR in red green blue
Do
Echo “the
color is ${COLOR}”
Done
הכנסת
פלט של פקודה
לתוך משתנה: PICTURES = $(ls *.jpg)
Positional parameters
Script.sh
<param1> <param2> <param3>
$0 : script.sh
$1: <param1>
$2: <param2>
Date: date +”%T %F” מציג
שעה ותאריך
בלבד ללא יום
WHILE
LOOP
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done
חילוץ
מתוך טבלאות:
ראה –format בפקודות,
לדוגמא:
for
image in $(docker images --format "{{.Repository}}"
| grep react) : שמראה רק
את עמודת REPO ושולף את
השם של GREP
או
| grep '^mysql\|arielguez/mysql' : נותן
או שם אחד או
שם שני
echo ${mysql_and_tag} | awk -F: '{print $2}' : מפריד את המחרוזת שאחרי : ופולט אותה
<SOME OUTPUT ECHO> | awk '{print $1}'
| head -n -1 | tail -n+2
<< removes title and removes empty lines in the bottom
CREATE SCRIPTS THAT USES ARGUMENTS
$0 refers to the name of
script
$1 refers to the arg after the script’s name
Example:
See
arg.sh script
./arg.sh
ariel
סקריפט שבודק אם פקודה הצליחה(דרך ARGS)
ARGS :
שימוש ב $1 $2
וכולי כדי
להטריג שימוש
בסקריפט
Script.sh hello
Echo $1
Script.sh hello world
Echo $1 $2
סקריפט
יצר מספרים
טבעיים בשורה
עם פסיק
להריץ 2 פקודות במקביל או יותר, בלי קשר אם הן עובדות: & לודגמא mongsh & sleep 10
לשים & WAIT אם
רוצים לראות
את הSLEEP
משהה
להריץ 2
פקודות או
יותר רק אם
הראשונה (או
כל אחת לפני)
עבדה ללא
שגיאה: && mongosh && sleep 10
למעשה
מחכה לסיום
התהליך/PROCESS
של הראשונה.
בזמן שהשניה
רצה
|| אומר שאם הפקודה הקודמת נכשלה , תריץ את הבאה.
RANDOM NUMBER : shuf -i 1-10 -n 1
מייצר
מספר אחד מ1-10,
אקראית.
Vagrant init
Vagrant up
Vagrant halt
Vagrant suspend השהיה/מצב
שינה והחזרתו.
Vagrant resume
Vagrant reload מעלה מחדש, אם שיננו קצת בהגדרות
Vagrant ssh default user name for vagrant machine: vagrant
Vagrant destroy משמיד את הכל כולל הקופסא.
Vagrant box list רשימת קופסאות שהורדנו לVAGRANT ואיתם אפשר להרים מכונות
ניתן
לקחת קופסאות
מתוך האתר VAGRANT CLOUD
Vagrant box remove <name of box> כמו DOCKER RMI - מוחק את הדמות של הקופסא
Vagrant package
–output <name we want as box>
צריך שנהיה
בתיקייה של הVAGRANTFILE ,
ואז נארז
הנוכחי לBOX, שניתן
להרים בכל עת,
כמו הקופסאות
שאנחנו מרימים.
Vagrant global-status –prune מציג ID של VAGRANTים שרצים כרגע וסביבות קיימות.
כדאי
לשים gitignore על .vagrant
כדי לא להעלות
לGITHUB
קבצים שהם לא
טקסט
Vagrant box add <name> vagrant box add laravel-ariel
file:///K:/DevOps/Vagrant/laravel/laravel-ariel
הוספה לתוך REPO
מתוך הנתיב של
הBOX
בלוקאל, הPATH זה הנתיב
של הקובץ והשם
שלו-אחרי
שהפכנו אותו לBOX
כמו
שמוסיפים ב - DOCKER IMAGE
לרשימת IMAGES
*שינויי
משאבים
במכונה:
בעורך
של Vagrantfile
,תחת הבלוק של config.vm.provider נניח
זכרון vb.memory =
“1024” , או
מעבד- vb.cpus = “2” ,
לשים לב
שסוגרים את
הבלוק עם end
*הוספת
קבצים למכונה
מתוך הLOCAL:
בתוך
Vagrantfile
מוסיפים (נניח
תיקיית DATA
שבה יש קבצים
שנרצה שיהיו
במכונת VAGRANT)-
Config.vm.synced_folder “./data”, “/vagrant_data”
כאשר DATA זה תיקיה
שנייצר ונשים
בה קבצים,
שיופיעו
במכונה.
הרמת
סקריפט שירוץ
במכונה על VAGRANT
Config.vm.provision “shell”, inline: <<-SHELL
Apt-get update
Apt-get install -y apache2
SHELL
end
או פשוט
דרך BASH SCRIPT:
Config.vm.provision “shell”, path: “deployLamp.sh”, privileged: false
end
FLAGS
Privileged: false >>vagrant user
Privileged:
false >> root user
הגדרות
רשת או הוספת
התקן רשת
בVagrantfile
Config.vm.network “forwarded_port”, guest: 80,
host: 8080 כאן יש
שרשור של פורט
כדי שיוכל
להתחבר לLOCAL
Config.vm.network
“private_network”, ip: “192.168.33.10”
וכאן יש הגדרה
של כתובת IP קבועה מתוך
הרשת פנימית
של ואגרנט
אם נרצה לקנפג לNAT, נוריד את הprivate_network –
אין
צורך להגדיר IP כי
הוא מייצר
לעצמו
להפוך לbridge
config.vm.network “public_network”, bridge:” Realtek PCIe GbE Family Controller”, adapter: 2 , type: “dhcp" השם של הBRIDGE לקוח מה PROPERTIES של הכרטיס רשת. כל זה בשביל שיעבוד דרך BRIDGE ולא NAT.
במידה
ויש לנו רק ADAPTER 1
שהוא BRIDGE
אז אפשר לשנות
לאחד, אם יש
לנו גם NAT
וגם BRIDGE
אז צריך
להגדיר
סידורי.
נניח NAT-אדאפטר 1, BRIDGE אדפטר 2.
התקנת
LARVEL
דרך VAGRANT-
ראה סקריפט1, סקריפט2.
Vagrant destroy
– f : : כאשר
צריך לאתחל
מכונה מחדש(לא
מוחק את הקובץ
וואגרנט פייל)
לבדוק
מפתחות SSH vagrant ssh-config –
לגלות
בעיות בVAGRANT-
(GITBASH) export VAGRANT_LOG=debug
cat
/etc/redhat-release - כמו lsb_release -a מראה
את מערכת
ההפעלה
והגרסא
yum check-updates: כמו apt update,
בודק מה יש
לעדכן
yum update -y: מעדכן אוטומטית *להזהר לא לעשות בPROD*
yum update system: מעדכן רק קבצי מערכת
עדכוני עורכי טקסט ודברים בסיסיים: yum install nano vim wget curl net-tools
Vi /etc/yum/Yum-cron.conf : קובץ הפעלות מתוזמנות
Yum
list installed : מציג
מה שמותקן כבר
yum search apache:
חיפוש חבילה
על פי שם(עדיף
httpd)
yum info httpd: יציג מידע
על החבילה
yum deplist httpd : מציג את כל הDEPENDENCIES של החבילה. לדוגמא במצב שאין אינטרנט או ברשת סגורה, להוריד את כל הdependencies כדי שיהיה אפשר להתקין כמו שצריך.
Yum
install –downloadonly
:
לא מתקין
-מוריד,
לדוגמא עבר
תסריט כמו
בפקודה מעל עם
הרשת הסגורה.
וגם מוריד את
כל הdependencies!
Vi /etc/yum.repos.d/CentOS-Media.repo :
מאפשר לנו
לגשת לREPO
כCD ROM,
שהCD הוא הREPO. ברגע
שזה מקונפג,
אפשר להוריד
עם yum install
Yum
remove <package> : הסרת
התקנות
Yum install epel-release
איפשור של
הורדות מREPO צד שלישי(לא
רשמי)
Firewall-cmd פיירוול של CENTOS
Yum install
כמו APT INSTALL
Systemctl status
firewalld –
מראה אם
הפיירוול
פתוח
Firewall-cmd
–state: האם רץ
Firewall-cmd
–list-all: פרטים
Firewall-cmd –list-ports: מראה איזה פורטים פתוחים
Firewall-cmd
–list-services: מציג את
כל הSERVICES
שפתוחים לFIREWALL
פתיחת
פורטים: sudo
firewall-cmd --zone=public --add-port=80/tcp –permanent
Firewall-cmd
–permanent –add-service httpd
:
מאפשר פתיחת
פורטים
שקשורים לSERVICE HTTPD
לא לשכוח RESTART כדי לאפשר פתיחת פורטים
Rpm
: red hat package manager,
התקנות לפי
קישור/לינק.
חבילה חבילה.
Rpm -Uuh
<link>: Upgrade HASH מציג
Systemctl list-unit-files: מציג קבצי מערכת שפועלים או משבתים או סטאטיים. לשים לב שזה לא אומר RUNNING.
Systemctl -t service
-a –state running: שירותים
שרצים, :type -t -a :all
Hostname : שם
המכונה
כדי
לשנות לSTATIC
ip – כותבים
Nmtui (יש
להתקין NETWORK
MANAGER אם לא
קיימת הפקודה)
משנים
ipv4 לMANUAL,
ומכניסים את
הכתובת
הרצויה-בהנחה
שהיא לא תפוסה-או
סדרה של
מספרים שלא
תפוסה. ולא
לשכוח SUBNET MASK
לדוגמא: 192.168.14.180/24
שזה אומר שכל
מה שתחת 24ביט
שזה 255.255.255.0
נכלל כרשת
המקומית. ולכן
המספר האחרון
מהווה את כל
תחום הרשת.
מכניסים
לGATEWAY
את הכתובת ROUTER
המקומית(לא של
בחוץ
באינטרנט).
מרפרשים
על ידי ניתוק
והחזרה של
החיבור רשת.
Nmcli connection show : יכול
לאפשר סדר
עדיפות
לחיבורי
רשת(במצב שבו רוצים
לתעדף חיבור
ספציפי או שיש
קונפליקט)-כאן
נותן רק את
שמות
החיבורים
nmcli
connection modify INTERFACE_NAME ipv4.route-metric METRIC_VALUE
להחליף
את השמות INTERFACE_NAME ו
METRIC_VALUE לפי
שם החיבור
והתעדוף שלו
אפשר
גם להכנס לRouteMetric
ולשנות תחת NETWORK
Tee:
פקודה שאפשר
להשתמש בה
לכתוב לתוך
קובץ לדוגמא:
containerd config default |
sudo tee /etc/containerd
מביא
את כל תוצאות
ברירת המחדל
ומכניס אותם לקובץ
המצוין אחרי הPIPE
HOSTS
כמו בWINDOWS: /etc/resolv.conf
: Dig <ip> <port> כמו PING
מפורט יותר, דורש
bind-utils בהתקנה
Netstat-
צריך yum install
net-tools
date MMDDhhmm[[CC]YY][.ss] : לשנות תאריך ושעה
alternatives --set python /usr/bin/python3 : allows python to become python3 command
TROUBLESHOOTING:
CURL
לא עובד ופינג
כן.
Systemctl status
NetworkManager -l
sudo ip -6 neigh
flush all
לשים
לב שכל MAC של
הADAPTOR שונה
ממכונה אחרת
ברשת
Source Control versioning options:
Centralized(CVCS): Centralized Version Control System.
central Repo of all versions, in which everyone works and commit/edit/change
It means the code sits on the server, not locally. Can’t work on offline.
Examples of centralized: Azure Devops Server(TFS), SVN(subversion), ClearCase, perForce, CVS(IBM)
Distributed(DVCS): each user can copy the repo and work on it, and not rely on the central repo.
After commits it can be applied later to the central repo
Code can sit locally. And can develop offline.
Examples of distributed: Mecurial (Hg), Git, Bazaar
States of git: working directory, Staging area(pre-Commit), Commit(enters history of repo)
אם מייצרים REPOבGITHUB לשים לב שבוחרים ביצירה .gitignore
כי
אחרת בכל
משיכה ועדכון
של COMMIT
הוא עלול
למשוך קבצים
ענקיים שהם לא
תואמי גיט-שזה
בעיקר קוד.
Staging-adding files to repo, working dir -no add files. Repository- commits(still local). Remote-to add to remote repo.
To make staging area on console:
Git init: creates staging
area for the current folder
שלבים
ליצירת גיט
לוקאלי מריפו
ודחיפה לREMOTE או
משיכה
rm -rf .git : removes all staging.
Git commit -am “added ..” : this also adds to staging and commits, -a is add.
git branch -m master
main : change name of branch from master to main
הוספת ריפוסיטורי לתוך גיטהאב-חייב אח"כ לעשות PULL אם זה חדש git remote add origin git@github:meditator3/git-flow.git
Git remote -v: to check what is origin url
Git remote set-url <new url>: will update it
git remote remove origin : removes the current remote origin
git remote get-url origin: shows url of remote origin
דחיפה לתוך הREMOTE ריפוסטורי – git push -u origin master
Git push <to the
remote> <from
which local branch?>
Git branch <name> - הוספת הסתעפות
git
branch -d : מחיקת
ענף
Git checkout -b “main” - מייצר
עוד ענף של main
Git branch – אומר
לך באיזה
בראנץ' אתה
Git push origin <branch name> - הוספת
ההתסעפות
לתוך הרמאוט
Git checkout <branch name> - לעבור
לענף/הסתעפות
Git log – כל
הקומיט שהיו(זה
שמופיע אחרון
ברשימה הוא
הראשון
שעשינו לו
קומיט, כלומר
הישן ביותר)
Git status- האם יש
משהו שצריך
לעדכן או
לעשות קומיט
Git add . – להוסיף
את כל הקבצים
לסטייג'
Git commit -m “<comment>”
Git rm –-cached <file> = מחיקת
קובץ מגיט
Git tag -a v1.0.0 -m “version 1.0.0”
Git log - check history
Git config –global user.email
“ariel G.” : tags the user only with the name(not an identification
process)
Git push –tags דוחף תיוג חדש חזרה לריפו של גיטהאב
Git diff <commit id> <commit id> <-- filename or without for whole repo comparison> : משווה בין קומיט לקומיט פר קובץ או לכל הריפו
Git diff <branch> < another branch> : show diff in branches( like git diff master develop)
Red: different or removed compared to target branch , (-) removed line, (+) added line
Red (-), lines that are present in current branch but not in target.
After merge- these lines are gone.
Green: different or removed compared to current branch
Green(+): lines that not present in current but in other branch, as in to be added in merge.
After merge-these lines will be added.
Git pull – pull current updates from repo and merges them to the local repo
Git fetch – pulls current updates from repo but doesn’t automatically merge them. The files are downloaded to “secret” git repo locally, but won’t be
Available or seen at all, until we merge or commit them. They are in a remote-tracking branch, can seen in git branch -r
git log develop..master :
(two dots) shows commits on master and not in develop
git log master..develop : (two dots) shows commits that are on
develop but not on master
git log --oneline --graph --decorate –all :
git rerere : reuse recorded resolution, it remembers your conflicts resolutions, and tackles it himself. Process:
git config –gloval rerere.enabled true
git rerere status
recorded resolution @ .git/rr-cache
git
rerere clear: clears the recorded resolutions
git squash – משטח את כל ההיסטורים של כל הקומיטים לקומיט אחד, עוזר בפחות ריבויי קומיטים, אבל עלול להראות סתירות בגלל שגיטהאב לא יודע את ההיסטוריה ואז הוא חושב שהענף בפיגור
בעיתייות
בSQUASH:
הוא לא מזיז
את הMERGE BASE,
מה שגורם
לתקיעות של
היסטוריה
ושינויים שכבר
מוזגו, אבל לא
זוהוה כ MERGE
BASE ולכן
כאילו לא
התמזגו.
git merge-base develop master מראה
מתי שני
הענפים האלו
התפצלו
ומציגים את הקומיט
שממנו התפצלו.
שיטות
איחוד (MERGE)
Fast forward – איחוד
בצורה לינארית,
מאחדים בצורה
לינארית נניח
2 בראנצ'ים
שבמצב שאחד לא
התקדם בCOMMIT.
2 הברנצ'ים
באותו ציר
זמן/היסטוריה
Non-fast forward – איחוד לא לינארי. מצב שבו שתי בראנצ'ים או יותר זזו בCOMMIT אחר. ונוצר MERGE COMMIT שמצביע על הCOMMIT הקודמים. בעלי צירי זמן/היסטוריה שונים.
ב merge commit הקוד של
כל הענפים
יתמזג, ולא
תהיה עדיפות
לאחד מהם.
בפשטות יותר: MERGE COMMIT
הוא האיחוד של
שני הענפים
השונים ב COMMIT חדש, הוא
ה
MERGE COMMIT
הפוינטר
יצביע על פי GIT CHECKOUT
ולפיו יעשה הMERGE,
לדוגמא אם
הפוינטר על MASTER
ועושים git
merge secondary, האיחוד
יהיה בין הMASTER לSECONDARY. Git branch רק
יחליף את הענף
שבו יופעל הCOMMIT או ADD.
PULL REQUEST – זה
למעשה בקשת MERGE. GATEWAY של הראש
צוות או מעליו
לאיחוד עם
בראנץ' שצריך
להישמר איתו.
בוחרים REVIEWER (הבוס בד"כ) והוא זה שמאשר.
CONFLICT: מצב
שבו נניח יש
קובץ בענף אחד
ולא קיים בענף
אחר, ומנסים
למזג בינהם.
אז קודם צריך
לפתור.
לדוגמא
להחליט על
מחיקת הקובץ,
או הוספתו ב GIT ADD
ואז ב GIT COMMIT,
ואז אפשר
לעשות PULL
TRACKBILITY:
לא כל ענף
נתמך ב REMOTE
ORIGIN. ניתן
להוסיף כך:
Git branch –set-upstream-to=origin/<another branch to track>
וכך
כל PULL נתפש
גם עבור הBRANCH הנוסף.
Git reset (flags --soft , --mixed , --hard)
Soft:
git reset --hard HEAD או >ID of commit>
לדוגמא
אם בחרנו
קומיט קודם ,
אז הוא יחזיר
אותו מצב אחד
אחורה.
לSTAGING
COMMIT ואז
נשאר רק לעשות
Mixed: working directory
יחזיר אותו ל
GIT ADD ואז
צריך לעשות ו-
Hard: מוחק
גם את הקובץ
וגם את הקומיט
Git rebase -I <id of commit before the problem> change of the history! <<enters interactive edit of rebasing
git rebase -i HEAD~3 : rebases the current commit to the commit from the 3 last commits.
בריבייס
אנחנו משנים
לוקאלית את מה
שאנחנו רוצים
ואז על ידי
Git commit --amend
Git rebase --continue
השינויים
תופסים
ומוחקים את
ההיסטוריה.
לדוגמא היה לי מצב שבו נחשף מפתח ונאלצתי לשנות כדי שלא יראו אותו בהיסטוריה
ריבייס
בעצם מוליך את
ההיסטוריה
לינארית, כאילו
שהענף המתמזג
היה מאז
ומעולם שם
לעומת
מרג' קומיט,
ששם רואים את
ההיסטוריה של שתי
הענפים לפני
שהתמזגו.
בריבייס
אנחנו
מוליכים את
ההיסטוריה
ומשנים אותה
שתהיה
לינארית
למרות שהיא לא
הייתה כזו.
Git blame <name of file> מראה מי ערך ונגע בקובץ
Git revert <ID of commit> : reverts back one stage before, for ex. If you wrote “I QUIT!” to your boss,
Then revert the I quit file, it will tell you it will delete it.
But this doesn’t delete the commit – but creates a new commit, and maintain the history.
Git cherry-pick <ID commit> : will place the files/updates of that particular commit into the current branch progress.
See I quit example
SUB-MODULE git
Git submodule add <link of repo> <name of new folder> :
this adds a repo INTO an existing repo, by using “shortcuts” not real files in the parent repo.
If we clone the parent repo, we will clone both repos. See example << that repo has been assimilated into this repo
GIT FLOW CHART
מצב
שבו מעדכנים
בזמן אמת את הPROD/MAIN (נניח
מצבי חירום) אז
במקום לעשות FFW,
יוצאים לענף HOTFIX.
ומHOTFIX
מעדכנים את הMASTER(לא
משנה כמה COMMIT עשינו
בדרך בענף של
הFIX)
וגם חייבים לעדכן את ענפי ה DEV וה STAGING שלא יהיו מאחור אחרי שכבר יש עדכון.
הסנריו
הוא: הבעלים
מביא גרסא 1.0
לחברה, שנמצא
בענף MAIN,
החברה מפתחת
מהגרסא הזאת
בענפים אחרים –
DEV STAGING
לגרסא
2.0 ואז
דוחפים/ממזגים
חזרה לענף PROD,
ומשם הבעלים
גילה שיש תקלה
ובמקום
להוציא מיד
תיקון לתוך הPROD
הוא
יוצא לענף HOTFIX ואז
אחרי כמה COMMIT, דוחף
חזרה לDEV
וSTAGING
שגם מתקנים
ומשדרגים, ואז
משם מגיעה
גרסא 2.0.1 אחרי הHOTFIX.
ראה
שרטוט.
נעילת BRANCH: בSETTING >BRANCHES > לסמן do not allow bypassing
git credential fill <<<"url=https://github.com/meditator3/Grad_proj.git"
protocol=https
host=github.com
username=meditator3
password=
בתוך
קובץ CONFIG
כדי לעשות SSH
Host github.com
IdentityFile ~/.ssh/<name of rsa ssh key>
User <name of your user>
ONBOARDING:
Git clone git@github.com:meditator3/google.git
משכפל
מתוך ה REMOTE אל
LOCAL-----------------------------------עובד
רק על REPO
ראשי , לא על
סיפריות בתוך
הREPO.??>>
Fast forwarding: linear commits
Non fast forwarding: more commits that are not present in another branch, must
use merge or rebase for histories to match
Git reset –hard head^ מוריד
את מה שיש
בסמן, אולי
הקומיט
האחרון
Git reset –soft <commit code>= מחזיר
את הקומיט
המצוין
לסטייג'ינג
Git reset –mixed <commit code>
= מחזיר
את הקומיט
המצוין לאזור
העבודה
Git reset –hard <commit code>מוחק
את הקומיט וגם
את הקובץ =
Git pull – מושך
שינויים
Git commit -am
“<comment>” – מוסיף
ומעדכן קבצים
שהשתנו או
נוספו וגם מוסיף
קומיט
Git tag -a(add) v1.1 -m(comment)
“version 1.1” – הוספת
תיוג
Git push –tag – מעלה
את התיוגים
לרמוט
REBASE: git rebase -I <commit id>
REBASE changes history!
UNDO REBASE:
git rebase
–abort
Git log –oneline :
מציג
לוג מקוצר
Squash – איחוד
כמה קומיטים לאחד(לצרכי
פישוט), נעשה
דרך ריבייס
Git Rebase -i:
PICK)זה
פותח עורך
טקסט שבו נשנה
לסקווש במקום
פיק
לדוגמא:
pick f12a345 Commit C
squash f12a345
Commit C
SSHבדיקות
חיבור :
Git remote -v
Ssh -T git@github.com
התקנת
גיט לפי גרסא-
(בדיקה: git
–version(
curl -LO https://github.com/git/git/archive/v2.37.0.tar.gz
מעדכן
את
הרפוסיטורי
כדי שיהיה
אפשר להתקין
·
tar
-zxf git-2.15.1.tar.gz
·
cd
git-2.15.1
·
make
configure
·
./configure --prefix=/usr
·
make
all doc info
·
sudo
make install install-doc install-html install-info
·
Note: If the command make configure error you can install
autoconf apt-get install autoconf.
if the command make all doc info error you can install zlib with apt-get
install zlib1g-dev.
If the command sudo
make install install-doc install-html install-info error
you can install asciidoc and docbook2x with apt-get install asciidoc and
apt-get install docbook2x.
GITHUB DEFAULT
SETTING OF REBASE
עלול
ליצור
קונפליקטים,
במצב שאותה
שורה נניח של MAIN
שונתה גם בDEV אז GIT לא
יידע לפתור את
הקונפליקט,
ויפלוט כבירור
לפני מיזוג.
או
בשינויי שמות
קבצים, שנניח
נשאר השם בDEV אבל
שונה בMAIN,
גם יפלוט
קונפליקט.
Apt update: רק
מרפרש את
הרשומות REPO במידה ויש
גרסאות חדשות
או אפליקציות
חדשות. לא
מתקין כלום.
לגלות
dependencies : apt-rdepends <name>
התקנת
PING במע’
הפעלה שאין
לה: apt install iputils-ping
גיבויי
ספריות
עדכונים: sudo cp /etc/apt/sources.list /etc/apt/sources.list.0
לראות
את הרשומת
סיפריות ללא הCOMMENTS: grep -v “#” sources.list (גורע
את השורות עם
ה#)
Sudo apt list –upgradable : רק מציג מה
ניתן לשדרג
Vi sources.list : לערוך
ולהוסיף REPOSITORY
Sudo do-release-upgrade : לשדרג
גרסאת UBUNTU
(נניח 20 ל22)
Sudo apt full-upgrade:
עדכןו מלא
Sudo apt autoremove : מוריד
חבילות לא
נחוצות או שפג
תוקפן
חיפוש:
Apt search
<search word>
מידע
על חבילה: apt show
<name of package>, sudo apt show apache2
מה תלוי בחבילה שנרצה להתקין: apt depends <name of package>, sudo apt depends apache2
מטרת
הקריפטוגרפיה:
authentication,
Privacy/confidentiality, Integrity,
Non-repudiation(mechanism that prove the sender indeed sent this
message)
דוגמת
ארכיטקטורה
מפתח
של אליס
הפרטי+הציבורי.
מהווה חותמת
דיגיטלית שלה.
כך שכולם
מכירים אותה.
שאליס
שולחת הודעה,
ההודעה עוברת HASH,
והצפנה וש-בוב
ינסה לקרוא
אותה מוצפן,
בוב צריך
לפתוח את
ההודעה עם
מפתח ההצפנה
שרק
לו
יהיה-כדי
לקרוא את
ההודעות של אליס.
המפתח
צריך להיות גם
אצל בוב וגם
אצל אליס.
הגדרה
המפתח הפרטי
נועד לפתוח
הצפנה,
והמפתח הציבורי
נועד להצפין.
מידע>מוצפן( ע"י מפתח ציבורי)>נפתחת הפצנה(ע"י מפתח פרטי)>מידע נגיש בחזרה
סוגי
אלגוריתמים:
SKC: secret key (symmetric) cryptography. שימוש
במפתח אחד גם
להצפנה וגם
פיענוח הצפנה
PKS:
Public Key (asymmetric) cryptography
שימוש בשתי מפתחות(SSH
לדוגמא) -אחד
להצפין, ואחד
לפיענוח
HF:
Hash Function(one way
cryptography) חסרות
מפתח ולא
ניתנות
להיקרא אחרי
ההצפנה שלהן(אין
פענוח), לכן
נקראות ONE
WAY
המטרה
היא יותר לאמת
מידע מאשר
לקרוא את
התוכן שלו.
סוג של חתימה
בלבד.
כי אם
יש למידע
שנשלח אותו HASH אז
כנראה שהוא לא
עבר שינויי.
או לשימור
סיסמאות.
כך
שגם במצב
שהמאגר
סיסמאות
נפרץ-עדיין לא
ניתן לקרוא
אותו. אבל
אפשר להשתמש
בו. וגם מהווה
חותמת
דיגיטלית.
התקפות
קריפטוגרפיה
Chipher text only:
המידע הזמין לתוקף
הוא רק CIPHER
TEXT, המידע
המוצפן בלבד.
Known plaintext
attack: מה שזמין
לתוקף הוא גם CIPHER TEXT וגם
חתיכות/חלקים
של CIPHER ו PLAINTEXT
אחרים-ע"י
ניחוש או
שפגומים.
Examples:
Pretty good privacy- very strong encryption that is very hard to break
Bitlocker – encryption of a disk(Microsoft).
Print(“Hello World”) = print(“Hello” + “ “ + “World”)
Print(‘
“Hello-world”? ‘) : מדפיס
עם הגרשיים
Name = input(‘type your name: ‘) יקבל
את הערך
המוקלד
name
Print(“hello\nhello2”) יודפס
בשתי שורות
נפרדות
Print(“1\t2\t3\t4\t5”) 1 2 3 4 5
ESACPES
Print (‘ the pet shop owner said “No, no,
\’e\’s uh, ..he\’s resting”.’) the pet shop owner said “No,
no, ‘e’s uh, …he’s resting”.
print(""" eberything ff' ' ' "" ''''
"" '''' can be entered here
you know""")
מכניס כל דבר לתוך 3 גרשיים
Print(4/3) = 1.25 float
Print(4//3)= zeros the float to integer (unless 4//3.0, where its still float)
Loops:
1) Only with integers.
2) Once declared range- cannot dynamically change inside the loop
a. For I in range(a, b):
b. b=b+10 <<< wont change the range
For i in range(1,13):
For key in
<dict> :
For x, y in
[(1,2), (2,3), (3,4)]:
X = x + 1 >in
python > x += 1
חזקה = **
Conditionals
If <condition> :
Else :
Elif
<condtion> :
While
<condition> :
Continue, break
= ממשיך
את הלולאה או
יוצא
<variable> = <variable1> or
<variable2> נותן
ערך בהתאם אם
התנאי
מתקיים.1 אם
מתקיים.
2 אם 1 לא מתקיים
Functions:
Def <name of
function>(<values to pass into it>): הגדרת
פונקציה
Return <value we want the function to return>
Def calc(weight, system = ‘metric’) מגדיר
ברירת מחדל אם
לא הועבר ערך
בסיסטם
Operators:
// = חלוקה
ללא שארית
מעגל למטה
תמיד
A % B כמה שארית יש לאיי אחרי חלוקה לבי =
Operators Scripts1, operators scripts2
Sequence type [list, string, tuple,
range, bytes & bytearray]
list[-1] = מתחיל
מהסוף
list[0:6] = מציג
את 0-5
list[:9] = מציג
0-8
list[10:] = מ10
ואילך
list[:] = על
הטווח
list[0:6:2] = בטווח
של 0-5 מדלג על 1 כל
פעם
list[1::4] = מתחיל
מאינדקס 1 עד
הסוף וקופץ 4
כל פעם
list[25:0:-1] = מסדר אותו ב-סדר הפוך
השמת
ערכים
במשתנים
<var> += <value> מוסיף
את הערך
למשתנה/מערך
a, b = b, a הפיכת
הערכים
במשתנים:
<value> in <array/string/tuple/> בודק
אם קיים הערך
שם
או not in
Booleans:
“b” > ”a” : אמת. כי
משווה לפי סדר
הצ'רקטרס
1 and 2 : מחזיר
2 כי שניהם אמת,
מחזיר את
האחרון(2)
0 and 1 : מחזיר 0 כי הוא נחשב לא אמיתי בפייטון, לכן מחזיר את הראשון(0)
If
False ----כל
ערך לא נכון
יוחזר בתנאי
כלא-נכון
None
= NULסוג
של
True/False - None will give false value when prompted.
Tuple
Immutable, Fixed array values. Constants. Can be circumvented to add cells(not values).
Len(<array/tuple/string>) מחזיר
את אורך
המחרוזת/מערך/טופל:
Tuple(<array>) : ממיר
את המערך
ל-טופל
Tuple scripts1, Tuple scripts2
Object bytes
Similar to string. But machine readable. Use <bytes value>.decode() to decode bytes to a string
Usage:
Redis stores strings/lists/dict in bytes
Methods
<string/array>.join(<string/array>) מחבר בין המחרוזת/מערך :
<string>.split(“,”) מוריד
את הפסיק
והופך לרשימה
Int(num) : הופך
למספר שלם
Float(“1.1”) : ממיר
את המחרוזת
למספר עשרוני
<array>.remove(<value>):
מסיר
את הערך
מהמערך
<array>.pop(<value>)
: מוריד את
הזנב של המערך
<array>.append(<value>)
: מוסיף
את הערך למערך
Type(<var/value>)
מציג
את הסוג של
הערך או
המשתנה
Len(<array/tuple/string>)
מחזיר
את אורך
המחרוזת/מערך/טופל:
Tuple(<array>) : ממיר
את המערך
ל-טופל
Str(<value>):
ממיר
הכל למחרוזת
<string{key} => {value}>.format(key=<dict
key>, value=<dict val>)
Print( f”<string{value we pass}> : {template literals}.” ßinstead of format
age = 24
print("my age is {0} years old".format(age))
דוגמאת סקריפטים להטמעת ערכים במחרוזת
<string>.startswith(<value>)
: אם
המחרוזת
מתחילה בערך
הזה
Min(items) מחזיר
את הערך הנמוך
ביותר ברשימה
Max(items) highest value of list
Key value pairs/ Dictionary
An object that has a key as a name and a value –
<key> : <value> ex. {‘bob’:64, ‘age’:’old’}
Dict([(tuple2D)]) : ממיר
מערך שיש
בתוכו נסטד
טופל של 2
משתנים כמו
מילון
Dict(kevin=160, bob=50, jana=30) : מגדיר
מילון {‘kevin’:160, ‘bob’:50,
‘jana’:30}
<dict>.values()
: פולט
ערכי המילון
<dict>.keys(): מפתחות
המילון
<dict>.items() :
מחזיר
את הצמד
מפתח:ערך
<dict>.get(<key>) מפתח מחזיר
ערך מתוך
Example 3 script interview question
Strings
“\n” מוריד
שורה
“\t” עושה
טאב
‘ \” hello\”
‘ : מתייחס
לגרשיים בתוך
המחרוזת ולא סוגר,
אפשר לשים כל
סימן
“”” 342/4erw/34’’’/// \\~````` “””
הכל
נכנס בשלוש
גרשיים, כולל
ירידת שורות
ומרווחים
1סיפריות
Import time
: package from lib, that has reserved functions
אבל
כל קריאה
לפונקציה זה
יהיה דרך השם
שלה:
Time.localtime()
כל
המתודות
נצטרך לייחס
דרך הסיפריה
טיימ
Time.strftime(‘%X’,
time.localtime()) מציג
בפורמט קריא
Time.mktime(time.localtime()) : ממיר
לשניות
אם לא
נרצה לייבא את
כל הסיפריה:
From time import
localtime, mktime, strftime
ואז לא
נצטרך לייצג
דרך טיימ
Localtime() במקום
time.localtime()
Example
script time package1, example
time script2
Dependencies:
Pip show <module/lib name> : detailes of module
Pip list : shows all dependencies installed
משתנה
סביבה -לתוך
ווינדוז
Import os : ייבוא ספריית מערכת הפעלה
Os.environ[“<שם משתנה>”] מושך את המשתנה מתוך הסביבת משתנים של ווינדוז
Os.getenv(“שם
משתנה”) מושך
ערך מהמשתנה
סביבה אם קיים
ואם לא- מייצר
אותו
FILES
Type <name of file> : מדפיס את סוג הקובץ
<variable for file> = open(“<filename>”, ‘r’) : פותח קובץ –
‘r’: read
‘w’: write
‘r+’: read + write
‘a’ : append to file מוסיף לקובץ
Xman_file = file(“xmen_base.txt”, “r”) : “r” means read.
Print(<variable for file>.read()) :
מדפיס את
הקובץ בעזרת READ אבל
צריך לאפס את
הסמן שיהיה
אפשר לקרוא
שוב
Xman_file.read()
<variable for file>.seek(0)
: מאפס
את הסמן שאפשר
יהיה לקרוא
שוב מהקובץ
Xman_file.seek(0) – READואז
להדפיס מחדש
עם
<variable for file>.close() : סוגר את הקובץ ללא זמין
<variable for file>.write(‘<text>’) : כתיבה לתוך הקובץ, צריך להיות פתוח לכתיבה
New_xmen = open(‘new_xmen.txt’, ‘w’)
New_xmen.write(xmen_base.read()) >> this pours old xmen to new xmen file using write
<file variable>.name : xmen_file.name is the same as saying xmen_base.txt
WITH
With <object example:open(‘<filename>,
‘a’) as f:
f.write(‘<something>’) משתמש באובייקט שאחרי ה"עם" ומגדיר אותו כמשתנה שבחרנו, "אף", ואז ניתן להשתמש בו
with open(‘xmen_base.txt’, ‘a’) as f: <<< f is a declared variable, of that file
f.write(‘Professor Xavier\n’)
שימוש ב"עם" גם סוגר את הקובץ ללא צורך להשתמש ב
f.close()
.strip() – מוריד
ספייס, מקצץ,
או איזה ערך
שנשים
בסוגרייים.
Strip(“a"( : a יקצץ כל
Line.strip() : יחזיר אמת
אם קיים כל
כרכטר.
f.writelines(<array of lines>) : writes lines for each cell of an array
סיפריות2
Passing
arguments in a file name( like echo $1, $2)
Need lib sys-
Import sys (std library)
Sys.argv[0] – leads to the path of the file in question. From 1 and above it means the args beyond it.
Print(f”first argument : {sys.argv[0]}”) –
will print the path of the current file running this.
Print(f”Second argument : {sys.argv[1]}”) – if you execute <script_name>.py running_now it will print-
Second argument: running_now >>> but this can still result in an error if there’s no argument,
or there are more.
Positional args:
Sys.argv[1:] will use any argument(args) we pass. Even if we don’t pass one. But it puts on a list/array on default.
Running
a script without .py
Depends on : import argparse (std library)
Process: create .py file, use the usr/bin/env/python 3.6 at first.
Script
for CLI-based-reverse-file,
Almost
Same script-adapted to linux system
תפיסות
שגיאות
try:
f = open(args.filename)
limit = args.limit
except FileNotFoundError as err:
print("Error:
this file does not exist! {err}")
#to make it as an error, otherwise it won't be
marked as an error
sys.exit(1)
def exceptions():
a = 5
b = 0
try:
quotient = a / b
except Exception as
err:
quotient = f'nope. you cannot divide by zero, or else you get infinity,ERROR: {err}'
return quotient
print(exceptions())
סיפריות3
from
argparse import ArgumentParser- package that allows using args and utilizing
their values
from
argparse
import
ArgumentParser
parser = ArgumentParser(description='kill the running processes listening on
a given port')
parser.add_argument('port', type=int, help='the port number to search for')
parser.add_argument('port_name', type=str, help='if no port number is declared. for ex.
http')
port
= parser.parse_args().port
port_name = parser.parse_args().port_name
import subprocess : מאפשר
שימוש
בפקודות
לינוקס/באש
כמו LSOF
לפי
מספר הפורטPROCESSדוגמאת
סקריפט שהורג
עבודה עם JSON וקבצים- סקריפט שמסכם קבלות בJSON, ופותח תיקיה(שלא קיימת) ומעביר לשם את הסיכום.) GLOB, SHUTIL)
סקריפט
של מזג אויר-נותן
לי את מזג
האוויר לפי
אתר מסוים,
דרך package:requests
ונעביר מפתח
כדי לקבל גישה
לAPI
(הערה שימושי לDEVOPS חיבור ושימוש בנתונים מהAPI של החברה)
סקריפט
שפותח אתרים
לפי JSON
או HTML
ומציג אותם(כTEXT)
Installing new dependencies/packages:
Pip3 list: shows all dependencies installed for python
Pip3 install boto3 : installing new package.
Pip3 install -r requirements.txt : If we need a whole list of new libs to install from a text file
But this wont install it globally- only available for the user installing.
To make it globally- make it with sudo
Pip3 freeze > requirements.txt : how to prepare the list of dependencies myself
Pip3 uninstall boto3 : remove the package
Pip3 uninstall -r requirements.txt: will prompt to erase all packages from the list.
Venv: Virtual
Environment - for developers
Creates a vir.env. for example, they create an env. That doesn’t have the boto3 package.
This Is for developers who want different pakcages env. Without harming the OS.
Or for those that have packages unrelated to the project, and want to maintain a more sterile and conflict-less environment.
Process:
Sudo apt-get install python3-venv
Creates an env. Of python in that installed path
But needs to be activated:
Source venv/bin/activate
And now we are inside venv/vir.env.- should see (venv) near the console prompt >
The “source” linux command
We can check the list again, and do pip list under venv, and install DIFFERENT packages.
Python3 -m venv /home/ariel/venv
3rd party option : pipenv – with automatic dependencies.
FUNCTIONS-more advanced
**kwargs: keyword arguments, can pass any number of arguments to the function, and can pull them via their key pair name
Def var_args(name, **kwargs):
Print(kwargs[“description”], kwargs[“feedback”]) >> will print love python None
# from calling this function
Var_args(“ariel”, description=”love python”, feedback=None)
Nested functions
Script nested function example
Yield
When once utilized in a function – it makes the function a generator/constructor function.
It preserves the states, not just the yielded value. And is memory efficient in managing large data, because it only pulls
Required values rather than all.
Lambda Function
It’s like the => function of javascript, doesn’t retain value, just uses a passing value to calculate
Example:
multiply = lambda x, y: x * y # we pass x,y as values for the function, and “:” is what the operation on them
print(multiply(2, 3)) #
Error handling/debugging
In except: Exception, ValueError
Try:
Except Exception as err:
Print (“something went wrong”, err)
תרגילים
נוספים
ופתרונות
בודק
כמה זמן
המכשיר דלק LOGPARSE
מה
זה?
בניית או הורדה של דמויות שהן יכולות להיות אפליקציות או סביבה, או שתיהן.
הדמות
היא התבנית.
הקונטיינר זה
שהתבנית רצה והיא
זמינה לשימוש,
אם זה
אפליקציה, שרת
או מע' הפעלה.
למה?
שידרוג של הליך פיתוח אפליקציה:
monolith app
כי פעם
היה-
שרת1,
שבתוכו יש מע'
הפעלה(שכבה1),
סביבה/MIDDLEWARE(שכבה2),
אפליקציה(שכבה3)
>>FRONTEND
שרת 2(בישראל לעיתים הכל באותה מכונה),מע' הפעלה(שכבה1), MIDDLEWARE(שכבה2), אפליקציה(שכבה3)>>BACKEND
אם
יש VM
אז כל אחד בVM
נפרד, על אותו
מכונה. והייתה
מערכת כלשהי
לניהול תורים.
הכל על אותה
מכונה
מערכת כזו נקראת monolith. . שfrontend,backend רואים את אותו הDB> tightly coupled
IDF,
SAP, ERB
חברות לדוגמא
שבהן חייבים DB
שלכולם יהיו
אותם נתונים,
שיהיה אחידות,
יושבות על
אפליקציות monolith.
חסרון שכולם רואים את אותו הDB: מחייב עדכון גם של הFRONTEND. כי כולם עובדים תחתו.
ושם
אין CD(continuous deployment)
וVERSIONING
ללא Downtime .
באפליקציות
שהן לא
מונוליט, הכל
בנפרד-
Microservices
עדיין
צורת עבודה
ארכאית.
שכל
השירותים
מדברים דרך API,
ולכל אחד יש DB או
נתונים משל
עצמו. הם לא
משותפים.
אפילו
יכול להיות
שהאם מאותו
שרת, אבל לכל
אחד יש טבלה
משלו. וחייב
לדבר עם API
כדי להגיע
לנתונים של
האחר.
יתרון על מונוליט-גם אם רכיבים בMICROSERVICES אחרים לא יעבדו. האתר עדיין יכול לעבוד. אבל במצב ירוד/פונקציונלית לקויה.
MIGRATING למונוליט-שיטת
הGRAPING.
כותבים הכל
מחדש/הכי יקר.
אבל בגלל
היוקר, וגם מפחדים
להרוס, אז
נשארים עם
הLEGACY
ומפתחים
מערכות חדשות
אבל שידברו עם
הLEGACY.
(בנקים
וארגונים אחר
ישראל).
שיטות
-revert sourcing, envers, hibernate
VERSIONING: משדרג בקלות לכל רכיב עצמאית.
עצמאות: יש לכל
רכיב COMPONENT
קונטיינר
משלו/סביבה.
תחת
BAREMETAL כל שרת
פיצה היה לו
שם/מדבקה APP1, DB2 וכולי.
ומערכת
הפעלה משל
עצמו. לפני
עולם הVIRUTALIZATION
HyperVisor
HYPERVISOR(של
חברת VMWARE):
מנגנון
(שנקרא hypervisor)
שיוצר מכונה
וירטואלית עם
מערכת
הפעלה+האפליקציה
והתלויות שלה
ומנהל אותה.
3-4
מכונות על
אותו שרת.
חוסך חשמל,
קירור, מקום.כסף.
ואז להביא עוד
מכונה זה
וירטואלי ולא
צריך לקנות
בנוסף.
חסרון- עדיין צריך מערכות הפעלה. לכל אפליקציה. צריך לשלם על כל רשיון. וגם זמן התקנות/הגדרות. צריכת משאבים מהשרת הפיזי.
למעשה,
כל הרצה של VM על הווינדוז
שלנו זה HYPERVISOR.
Containers
הטכנולוגיה
העדכנית:
האפליקציה
ללא מערכת
הפעלה. במקום VM. יש
שרת שיש לו
מערכת הפעלה
אחת, על כל
השירותים/אפליקציות.
למרות שהם
מבודדים.
גם
מדלג על התקנת
מערכות הפעלה,
וגם הרבה יותר
קל משאבית.
וגם מכיל את
כל הDEPENDENCIES
של האפליקציה
וקל להעביר
אותו.
הקונטיינר
משתמש רק בKERNEL של
המערכת הפעלה
המארחת ולא
בכל ההתקנות
שלה. מאוד LIGHWEIGHT(alpine
לדוגמא זה
גרסא קלה)
לסיכום:
בעבר הקצת
רחוק -שרתים
פיזים פר
אפליקציה-בזבוז
זמן וכסף וגם
משאבי אנוש.
עדכני/עבר:
HYPERVISOR - מספר
אפליקציות על
שרת אחד, יותר
יעיל מהפיזי
עדכני/עתיד:
קונטיינר - יותר
יעיל מHYPERVISOR,
כמה
אפליקציות פר
מע' הפעלה.
מה
זה קונטיינר?
הגדרה:
PROCESS (לא
וירטואליזה)שרץ
בצורה מבודדת
על ENVIRONMENT משלו. כאשר
הוא מתארח על
שרת שיש בו
פלטפורמה/מנוע
להריץ
קונטיינר.
אחד הקונטיינרים הנפוצים בעולם- DOCKER
Container הוא immutable
service , כל גרסא
ועדכון של
הקונטיינר
ניתן לייצא כדמות.
בניגוד לזה
שהיינו
מעדכנים
ישירות לסביבה
ויכולים
להסתבך
עם
גרסאות לא
תואמות.
עם
הIMAGE,
אני מחליף את
הIMAGE
הקודם/גרסא.
וזה אמור
לעבוד בכל
סביבה. כמו
שהיא.
DOCKER
Docker image: read-only template composed of layered filesystems
used to common files and create Docker container instances
container: an isolated and secured shipping container created from an image that can be
run, started, stopped, moved and deleted
requirements: docker engine, container support(windows server or linux-LXC)
יתרונות: eliminate app
conflict, faster dev onboarding, env. Consistency, ship software faster
פקודות
docker run -itd <name of image> אפשר
להוסיף –name <container name>
docker logs <name of docker>:
לוג
רשימת
לוקלי IMAGES: docker images
רשימת
הקונטיינרים: docker ps -a
מחיקת
IMAGE:
קודם לעשות STOP
לקונטיינר- docker stop <name of container> <several names>
ואז
– docker rm <name of container>
למחוק
IMAGE- docker rmi <image name>
DOCKER RUN
הפניית פורטים מהמכונה(צד שמאל) לאינטרנט: docker run -itd –name ariel-nginx -p 8080:80 nginx
-p זה אומר PUBLISH
-d חשוב DETACHED,
זה מה שמאפשר
להגיע
מהאינטרנט
RUN יקח IMAGE שקיימת לוקאלית ואם לא יחפש בריפו אונליין.
קיימת
אפשרות גם
להריץ/לשנות
את פקודת
ההרצה שקיימת
בIMAGE (Dockerfile)
EXEC –
כניסה
לקונטיינר
כניסה
לDOCKER
עצמו (אם זה UBUNTU): docker exec -it ariel-nginx /bin/bash
מכניס אותך
לטרמינל של
הדוקר
אתחול/התחלת
קונטיינר
שנעצר: docker
start <name of container>
VOLUME PERSISTENT
VOLUME:
חלוקת
קונטיינר
בתוך וולויום
שהגדרנו, חולקים
משאבים ורשת.
פשוט
לאפשר נתיב
אצלנו במכונה
ששם נשאר הpersistent Data.
לדוגמא
במכונה
המארחת/שרת
יהיה נתיב /mnt
פשוט מוסיפים הגדרה של הנתיב עם הפלאג -v
Docker run -itd -p 8080:8080 -v /var/www node
-v מייצר
את הווליום.
אם לא נשים
הנדל -v לא
יישמרו והכל
יימחק!
אפשר
להגיד לו קובץ
ספציפי שנרצה
שיהיה PERSISTENT:
Docker run -itd –name ariel-nginx -v /home/ubuntu/data:/usr/share/nginx/html -p 8081:80 nginx:latest
-v <folder in hosting
machine>:<folder in container>
ואז שמריצים RUN, הוא ילך לVOLUME שמצויין לו כTARGET(הראשון) וישים אותו בDESTINATION(השני) שזה בקונטיינר.
חסרון לVOLUME: אין גרסא.
סתם זרוק
בתיקייה. כך
שאם נשים את
הקוד בVOLUME-הIMAGE לא
יכלול את הקוד
החדש.
כדי לפתור צריך משהו שמייצר IMAGE>> DOCKERFILE
Docker volume ls : מראה
רשימת VOLUMES
וגם אפשר
למחוק ולפנות
INSPECT
זיהוי VOLUME: docker inspect <name of volume>
יראה
לנו גם את
המיקום שלו
בקונטיינר
ובמכונה
המארחת
הורדת
גרסא הכי
אחרונה של IMAGE: <image name>:latest
ששמים בסוף
פקודת הרצת הDOCKER
Docker top –
איזה PROCESS
עובדים עכשיו
Docker stats – סטטיסטיקות של הקונטיינר
DOCKER REPO(HUB)
docker push <username>/<repository>
להכנס
לדוקר HUB:
docker login <user and password>
Docker volume ls :
מציג רשימת
ווליומים
Docker system prune –force --all –volumes : לא
משאיר זכר לDOCKER
שבמכונה
לצאת
מתוך SHELL של CONTAINER : CTRL P ואז CTRL Q , אם
הרצת docker -it
מה
קורה ב DOCKER
CONTAINER RUN?
-
מחפש
אימג' לוקאלי .
לא מוצא
- מחפש בREMOTE ריפו(ברירת מחדל DOCKER HUB)
- מוריד את הגרסא העדכנית ביותר LATEST
- יוצר קונטיינר על בסיס האימג' ומתכונן לאתחל/להריץ
- נותן IP וירטואלי לרשת פנימית בתוך מנוע DOCKER
- פותח פורט 80 ועושה FORWARD לפורט 80 שבתוך הקונטיינר
- מתחיל את הקונטיינר על ידי ה CMD שכתוב באימג' על הDOCKERFILE
-
בא
בגלל החסרון של VOLUME: אין
גרסא. סתם
זרוק בתיקייה.
כך שאם נשים
את הקוד בVOLUME-הIMAGE לא יכלול
את הקוד החדש.
כדי
לפתור צריך
משהו שמייצר IMAGE הוא
ה...
DOCKERFILE
מייצרים
אותו כהוראות
לבניית דמות
הקונטיינר,
שאותו אח"כ
נפרוש בDOCKER
BUILD.
כדי שתהיה לנו גישה לדמות מבחוץ אנחנו מעלים לDOCKERHUB דרך DOCKER PUSH
יש להוריד מה REPO כדי שיהיה לנו את כל הנתונים של האפליקציה שעובדת עם הבסיס של הדמות.
יש
בד"כ גם DEPENDENCIES
בREPO
שאמורים
להריץ בRUN
לדוגמא אפליקציה של FLASK עובדת על פייתון-ולכן צריך שיהיה את הקבצים של האפליקציה מהריפו- לוקאלית, וגם את הIMAGE של פייתון.
<docker
file is inside the app main folder:”Dockerfile”
> עם f קטנה!
MAINTENER: מי שכתב את הDOCKERFILE(לא חשוב לציין)
אלו
החשובים:
FROM <python/js/language>
WORKDIR <PATH we want to put temp files> : איפה הקבצים בזמן הבניה-ייצר תיקיה אם לא קיימת.
לא
ניתן להעתיק
קבצים שהם
מחוץ להגדרת BUILD CONTEXT
(שקיים בDOCKER COMPOSE)
COPY <what to copy(.
If in current folder) where to copy(. If in same
WORKDIR folder)>
Ex:
COPY requirements.txt (PYTHON) :
איזה תוכן
מועתק לתוך הIMAGE
RUN <what we run while installing/building,usually dependencies> רק בזמן הבניה. לא בהרמת האפליקציה.
EXPOSE : חושף
פורטים (אם לא
שמנו publish -p)
ENV: משתני
סביבה שאפשר
להגדיר לתוך
הדמות
VOLUME: גם אם
לא נעשה -V
ולא ציינו,
הוא ידע לשמור
בתוך הדמות
נתיב שבו שם
יהיה הVOL.
ENTRYPOINT : פקודות הרצה שאי אפשר להתעלם. צריך להריץ PROCESS. וגם להוסיף ARGS לפקודה.
דוגמא
להפעלה: ENTRY POINT: [“node”,
“server.js”] אומר
שהוא מריץ node server.js
להבדיל
מCMD : COMMANDמגדיר
פקודת ברירת
מחדל שרצה
על הIMAGE
כדי להרים את
האפליקציה
ואפשר להתעלם
ממנה גם.
בזמן
הבניה של הIMAGE: FROM, WORKDIR, COPY, RUN, ENV, VOLUME .
בזמן ההרצה של הקונטיינר/RUNTIME: ENTRYPOINT , CMD, EXPOSE
מה
זה אומר AS
BUILD?
שאנחנו
מצמצים את
המשקל על ידי
סלקציה של החבילות
בתוך ה COPY
–from=build
מציאת
דמות OFFICIAL העדכנית
ביותר:
בDOCKERHUB תחת TAGS, כותבים LATEST. ומשם מגיעים גם לפקודה הנכונה.
Alpine version: minimal installation
Bookworm,bullseye: Debian release names/stable more extensive libs.
Slim-bulseye/bookworm: minimized versions
Ex:
RUN dotnet restore
RUN dotnet publish -c Release -o /app
RUN apt update && apt install -y maven (JAVA)
RUN mvn clean install (JAVA)
RUN mvn package (MAVEN)
RUN npm install (NODE, EXPRESS JS)
RUN pip install –no-cache-dir -r requirements.txt (PYTHON)
ENTRYPOINT [“<run command(node,
python3)>”, “<what to run>”]
Ex:
ENTRYPOINT ["dotnet", "YourApp.dll"]
ENTRYPOINT ["java", "-jar", "your-app.jar"]
ENTRYPOINT ["node", "app.js"]
CMD [ "python", "app.py" ]
Docker build -t <image name>:v1 . : this builds an image according to
dockerfile
וודא
שיש לך FROM
מגרסא
שמתאימה
לאפליקציה
ולא סתם LATEST
בכלליות
הDOCKERFILE –
משתמש בדמות
ממקום אחר
כרפרנס, ומריץ
DEPENDENCIES,
וגם מה שצריך
כדי להריץ את
האפליקציה.
docker push your-docker-hub-username/my-nginx-image:v1
לפני
PUSH
לעשות LOGIN
לבדוק
שהאפליקציה
רצה
והקונטיינר:
docker run -p host_port:container_port -itd <image name>
formatting:^^^name of image must be last in argument, unless you want to do something IN the container. Then its after image ex:
Docker run <outside the container args> image <inside container
stuff>
·
host_port
is the port on your host machine where you want to access the container's
application.
· container_port is the port on which the application inside the container is listening.
·
-itd : interactive+
tty, keeps STDIN open+ detached(runs in background)
ERRORCHECKING
Like Kubernetes, docker logs <name>
TIPS
Check code in repo, first run the app without container to save time.
And to understand the order of installations
Diskpace
Docker system prune : מוחק
את כל הCACHE
וכל הדמויות
שקיימות או
הקונטיינרים.
רק בזהירות!
אפשר לצמצם עם
IMAGE PRUNE
DOCKERFILE
Maven/java: [“java”,”-jar”,”<app file name.jar>”]
Multiphasic: FROM <value> AS build
Next phase:
COPY –from=build <path of target> .
Ex:
(maven)
COPY pom.xml /workdir
EXPOSE : לחשוף פורטים
Docker file example-python(helloworld Django) for this repo
Dockerfile-nodejs-EmptySiteTemplate
Multi-stage Builds of dockerfile(maven example)-
you can detail after first package run, another FROM and RUN that uses the opened packages.
A docker file that has 2 FROM and RUN.
Example: simple-java-maven-app
We check the pom.xml for all details about the maven version, files to run.
To find the correct version we search in dockerhub for java engines: ant or maven
Then after first build is running ok. We check in the container
Docker run -it maven-app:1 /bin/bash
See whats’ changed in the folders compared to the repo-
And see if we can run the java app from there – java -jar <app name> : check
We then use the build to run a java (FROM java) but only runtime.
Then we RUN it via where the app is located, where we ran it from inside the container of the previous build
(verified working script)
FROM maven:3.5.4-jdk-7-alpine
AS build
WORKDIR /src/app
COPY . .
RUN mvn package
FROM openjdk:7u91-jre-alpine
WORKDIR /app
COPY --from=build /src/app/target .
ENTRYPOINT ["java", "-jar",
"my-app-1.0-SNAPSHOT.jar"]
Docker rmi $(docker images -aq) –
מוריד את כל הIMAGES מהLOCAL REPO.
MULTI-STAGE EX2
Example Dockerfile Dotnet-core helloworld:
Cannot run over linux. Must be run under powershell
Here we use sdk v3.0 because we saw it in the file CSPROJ, but only version 3.1 is available-we checked with docker pull
RUN dotnet restore (dependencies)
RUN dotnet publish -c Release -o out << install according to configuration (-c):Release and publish/install in the out folder(-o),
This will only copy the binaries in the out folder. Which is why we specify it later on the runtime image
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build-env
WORKDIR /App
# Copy everything
COPY *.csproj ./
COPY *.sln ./
RUN dotnet restore
# Copy the rest of the source code
COPY . .
# Build and publish a release
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .
ENTRYPOINT ["dotnet", "dotnet-core-helloworld.dll"]
find out which dll binary is suited>dotnet-core-helloworld.dll”] > you use run -it /bin/bash and ls
לקיחת
DATA מנקודת BUILD
ספציפי
--from = 0 זה אומר שהוא לוקח משלב 0 של המולטי פייס BUILD, לדוגמא אם רוצים לקרחת משלב 2 של הBUILD אז זה –from = 1 וכולי.
אפשר
גם פשוט לתת
לכל שלב שמות
ואז לקרוא להם
מהFROM,
לדוגמא
FROM node:14 AS stage1 ……and later call it with: COPY –from=stage1
DOCKERFILE
EXAMPLE NODEJS
# Use
the current directory as the build context
# No
need for a base image, as you're building from the local files
# You
can leave this line out altogether if desired
FROM node:4
# Set
the working directory inside the container
WORKDIR /app
#
Copy the entire project directory into the container
COPY . .
#
Install application dependencies
RUN npm install
#
Expose the port your application will run on
EXPOSE 8080
#
Define the command to start your Node.js application
CMD ["node", "server.js"]
NETWORK:
A network that connects between containers
The communication doesn’t exits/travels outside the containers. They are all closed
If we want traffic out we need to -p it/publish
The network can ping each container in its network by name/ip that been created via the network
Docker network ls
Docker network inspect
Docker network create <name> --driver : creates new network/default=bridge, unless –driver=something
else
Docker network connect
Docker network
disconnect
Docker uses aliases to avoid using static ip’s , has inherent DNS(domain name system) so it
Can interact with each container instead of
using ip’s.
Process of network+test ping:
-Loadup nginx and mysql by just using Docker run
Docker run -itd -p 8001:80 nginx (will download if not exists)
Docker run -itd -e MYSQL_ROOT_PASSWORD=<whatever psw> mysql << make sure both are up & running
Docker network ls (will show ID’s of network containers), will show-bridge, host, null
Docker network inspect <ID of container>
As of now, they have ip’s, and ID’s in a the same network,but They can’t talk with each other yet. Its default network.
Can see it Under containers. And that driver=”bridge” or driver= default.
We need to create a new network for them to communicate.
Looking again at host in the docker network inspect, will show the VM communicating with the VM ubuntu server.
Null network no one can communicate into or outside. Sort of private network.
*create a new network: docker network create –driver bridge ariel-network
The containers still don’t communicate via each other, I’ll have to assign my network to them.
So now we’ll need to delete our containers, and run them again using --network <name> <<which is ariel-network
docker run -itd --name mysql -e MYSQL_ROOT_PASSWORD=password --network ariel-network mysql
inside the nginx container!
Docker exec -it nginx /bin/bash
apt update
apt install iputils-ping : this will test ping between our containers
ping mysql >>this should test and show ping (but only from the nginx server)
can’t test on mysql container because no apt.
docker run -itd –name centos --network ariel-network centos:latest
inside centos container run ping for mysql and nginx.
--Network alias <name>
: assigns an alias for a container in the network. Which allows
communication via that alias.
ראה
script network alias-RRobin-docker-search
TIP: in docker network NO PORT FORWARDING OR INDICATING PORT IS NEEDED, ONLY NAME OF SERVICE(AS THE URL!)
יש
לשים לב
שבאפליקציות
דפדפן הקוד
מדבר על הדפדפן
ולא דרך סביבת
הקונטיינרים,
ולכן דווקא יש
להשתמש
במשתני
סביבה של LOCALHOST עבור
המכונה
המארחת
עם
הפורטים שלהם!
ARGS –
בתוך הDOCKER FILE
מגדיר איזה
משתנה מועבר
מהCI
או משלב בילד
אחר.
BUILD ARGS –
יכול להיות בCI,
והוא מעביר את
הערכים שנרצה
לתוך המשתנה
שהוגדר בARGS בDOCKER FILE.
מאפשר
הטמעה ממשתני
סביבה של
הקונטיינר
שרץ MULTI STAGE
כשלב ראשון,
ואז ב BUILD
מאפשר להטמיע
לפני הRUNTIME
את מה שצריך.
לדוגמא
CONFIG JSON בFE שבו
יש DOMAIN
של האפליקציה
והוא תלוי
סביבה-STG
או PRD,
כל אחד DOMAIN אחר,
לכן יש צורך
כזה. במקום
שהמפתחים כל
פעם ישנו את
הדומיין כדי
לא לדחוף
דומיין של STG אל PRD.
Compose מאפשר
לנו לבנות כמה
קונטיינרים
בקובץ YAML אחד, בד"כ
שיתקשרו
בינהם עם רשת
שנקבע(ראה
לעיל)
COMPOSE
לוקח מהדמות
שייצרנו בDOCKERFILE,
ומניח SERVICES
עליהם. כדי
שיתקשרו וגם
כדי להרים את
כולם.
בד"כ
גם מייצרים
ווליומים כדי
שהאפליקציה יהיה
לה PRESISTENT STORAGE,
נניח כמו DB, שדורש
זכרון
שמתעדכן.
COMPOSE לא
יחליף את DOCKERFILE במצבים
שצריך הרבה DEPENDENCIES כי
זה משהו שקל
לעשות עם DOCKERFILE.
פקודות:
Docker compose <up, version, down,run, logs,start, port, event>
sudo docker compose down -v --remove-orphans : מוריד
מה שנתקע ולא
יורד בDOWN רגיל.
Filename: docker-compose.yml or
.yaml
docker-compose
down --volumes --rmi all :
אם
רוצים להוריד
את כל מה
שהעלנו
בקומפוז
docker
compose up -d : -d is detached, so it can work in the
background
מציג
רשימת כל
הווליומים
docker volume ls:
-p זה PUBLISH,
לדוגמא 8080:3000 זה
אומר שהמכונה
המארחת (127.0.0.1)
מדברת עם
הקונטיינר
דרך 8080,
והקונטיינר
מדבר ב3000
Docker-compose/drupal examp[le
Docker compose -f <filename if not indicated the default docker-compose.yml> : to run docker compose yaml file
Docker compose up/down : מרים/מוריד את הקומפוז
Version: “x.x” – number we
choose as a start version for the docker compose file itself
Services:< what images we are pulling and
their config>
(two
spaces in the indent field)
Drupal: (container name)
(two
spaces in the)
Image: <image name>
Ports:
Add minus before port number
8080:8080
Networks:
-drupal-network<a
name we choose for the network>
./ <PATH> :
<PATH WE INSTALL TO> <the ./ -uses the relative path.where YAML file
is >
Ex:
Volumes:
אם
מוגדר מחוץ לBUILDS אז
צריך לעדכן
בתוך הבילד את
ה PATH,
דוגמא:
NESTED
בתוך SERVICES(לא
בתוך איזה BUILD):
Volumes:
Frontend_vol:
בתוך
FRONTEND(BUILD):
Volumes:
-<space>frontend:/var/www/
-<SPACE>./modules:/var/www/html/modules
Environment:
<passwords
or user names we need for auto login> Ex:
-<space>MYSQL_DB=mysql
-<space>MYSQL_USER=user
-<space>MYSQL_PASSWORD=pass
בשימוש
עםDOCKERFILE
(שבונים YAML
בעזרת
דוקרפייל)
Build:
Context: ./<PATH of
DOCKERFILE>
****
קונטקסט חייב
לקנן בתוך BUILD ****
Networks:
<name
of network>:
Ex:
Networks:
Webapp-net: (indented inside
Networks)
לוודא
פורטים
שנחשפו בYAML COMPOSE שהם גם
פתוחים בVM BOX!!!
וגם
לבדוק איך הBACKEND
מתקשר עם הDB(MYSQL HOST:DB) לדוגמא
Docker compose up -d –
מרים את
הקומפוז
בצורת DETACHED בגלל
זה הD(אחרת הוא
תוקע את
הטרמינל)
Docker compose down –
מוריד את
הקונטיינרים-ומוחק!
Aliases
ב COMPOSE זה כמו בDOCKER NETWORK
שאפשר לקרוא
לכל קונטיינר
בכינויי שלו (ALIAS)
בדוגמא של DRUPAL
בניית COMPOSE עם DOCKERFILE:
יש
פשוט לציין BUILD: כמו
בדוגמא, כדי שCOMPOSE ידע
להשתמש בDOCKERFILE(לא
חייבים
להשתמש ב DOCKERIFLE: )
דוגמא
MYSQL+WEBAPP עם DOCKERFILES
אם
ישנם שינויים
בBUILD,
לדוגמא
בקבצים של הREPO, אז
אפשר לעשות docker compose
build --no-cache <name of service that rebuilds, webapp for ex.>
אפשר
להשתמש ב:
Depends_on:
<NAME
OF SERVICE>:
להבטיח
תלות אחרי
בניה
רשת
NETWORK
בCOMPOSE לשים לב:
הקונטיינר
יכול לפנות לURL
שנגדיר לו כשם
הSERVICE
שקבענו בCOMPOSE. לדוגמא
במקום LOCALHOST זה יהיה redis:12762
Docker
compose build –no-cache מומלץ
שמשנים משהו
בקונפיגורציה,
ואז אפשר להרים
עם docker compose up -d
Context : מציין
את הנתיב
שאנחנו רוצים
לתעל אליו את
הDOCKERFILE
לדוגמא, והוא
מוגבל אך ורק
לנתיב הזה ואי
אפשר לצאת
מעליו לדוגמא
עם ../
Integration from hell
Ram has code, naama has code. Each one removed certain files/dll from its dependencies, and now the code cannot integrate
Devops not understanding code enough to know what the problem is
There is no central integration in which the code is evaluated.
That means we need a designated server for CI, that EACH code change/dependency will be evaluated and saved in the CI server.
)מנהלי
תצורה היו
עושים CODE FREEZE
ומנסים כמה
ימים לאחד את
הקוד של רם
ושל נעמה.
וכיום ב CULTURE
של DEVOPS
זה לא קיים. (
ה DEVOPS בונה את הCI, כדי שאוטומטית הכל מתעדכן, וכך מיד רואים עם התקנות של DEPENDENCIES לא עובד, והאינטגרציה נכשלת. כל COMMIT שמישהו הרס, המפתח צריך לתקן, שTEST לא עבר. אם הקוד לא עבד. מכל סיבה. אבל אם הCI עובד – ההליך עובד, אז מיד אפשר לעלות על בעיית אינטגרציה.
ומבחינת
החברה לא
נותנים ללכת
הביתה אחרי שמפתח
דוחף קוד לא
טוב. כדי לא
לשבור את
ההליך ואת
המשך הפיתוח.
עוד
דוגמא של חברה
שעבדה רק עם CD, ואז
את כל הCI
כל אחד עשה
אצלו במחשב,
שזה לא CI,
כי CI
זה אומר CENTRALIZED SERVER
שייעודי רק לCI.
CONTINUOUS DELIVERY
אחרי
שגמרנו CI
אנחנו בודקים
את האיכויות
של הPACKAGE/IMAGE/BINARY בכל
מיני סביבות,
אם אפשר לפרוס
אותו – אז זו
הבדיקה. זה
תהליך ידני.
CONTINUOUS DEPLOYMENT
אוטומטי, כמעט ולא קורה באף חברה. שהCI והDELIVERY מגיע אוטומטית ל PRODUCTION! נפרש.
כלומר ההליך הזה לא יעצור שיש תקלה אלא לא יפרוס ל PROD.
מה
זה?
פלטפורמה
להרצת CI
לבדיקת BUILD
שונים וגם
ייצור
ארטיפקטים
לשלוח
לקליינטים או
למפתחים.
הליך
CI ב JENKINGS:
- קוד בגיט נדחף מהמפתחים שסיימו לפתח משהו, ג'נקינס מותרע ומפעיל את ההליך
- CHECKOUT CODE, לוקח את הקוד מהGIT ומושך אותה לRUNNER שלו כדי לבנות
- BUILD/COMPILE בונה ומריץ את הדמות או האפליקציה
- RUN UNIT TESTS מריץ בדיקות אחרי שהרמנו
- RUN INTEGRATION TESTS
- לעיתים צריך DEPLOY ENVIRONMENTS לסביבת אינטגרציה שיהיה אפשר לבדוק את האינטגרציה(INTEGRATION TESTS) לפי הסביבה שהיא עובדת בפיתוח.
- PACKAGE כיווץ אם זה לא דמות שמוכנה
- יש NOTIFICATION לSLACK למקרה שמשהו מתקלקל, או לכל פלטפורמה אחרת שנצטרך להאזין
הסבר
על JENKINS:
כתוב
בשפת JAVA
ומרים
CONTINUOUS BUILD SYSTEM , תומך
במעל 400 פלאגין.
ראה מצגת
לעוד.
JAR WAR
התקנה על TOMCAT. או בDOCKER. או ב5
פקודות MASTER
INSTALLATION. מומלץ
התקנת WAR.
- יודע לקשר מספרי גרסאות
- מפעיל BUILD
- מתזמן לפי בקשה
- יכול להריץ סקריפטים של BASH
- PUBLISH
- יכול להוציא EMAIL OUT OF THE BOX(ללא פלאגין)
- הגברת הפונקציונליות על ידיד התמיכה במלא פלאגינים.
- תומך בטכנולוגיות ישנות(להבדיל מAZURE DEVOPS).
- וגם כלי הרבה יותר מהיר מהכלים הישנים(AZURE DEVOPS..)
יותר
טכני:
כותבים
בשפתPIPELINE DECLERATIVE ואפשר
להשתמש בGROOVY SYNTAX כדי
לקבל את הSYNTAX המורכבים.
בשלב
צ'ק אאוט,
הג'נקינס פותח
סיפריית(תיקיה)
WORKSPACE,
שאיתה הוא
עובד, ומתקין DEPENDENCIES, DOCKER BUILD וכולי.
נעזרים
בצד שלישי כדי
לקבל יותר
אפשרויות כמו SONARQUBE
לבדיקות קוד, ARTIFACTURY/JFROG או NEXUS
כדי לייצר
ארטיפקטים
ולשלוח אותם
או BLUE OCEAN שזה גם תצוגה יפה יותר של CI
שאלת
ראיון רכיבי JENKINS:
Agent:
מכונה שמריצה JOB או PIPELINE
עבור השרת
הראשי של JENKINS , כמו SLAVE
כי
לדוגמא נרצה
להריץ את הPIPELINE
בסביבה אחרת WINDOWS או LINUX או ANDROID,
נוכל לעשות
אותו בעזרת הAGENT.
Executer:מה
שמריץ את ה JOBS מיוצג בד"כ
ע"פ כמות CPU, כמה THREAD
יכול לרוץ
במקביל,
לדוגמא אם יש
לנו 2 STEPS
הם ירוצו
במקביל שיש
לנו 2 EXECUTERS.
האם
ג'נקינס שומר
את המידע שלו
בDATABASE?
לא.
הכל בקבצים
בתיקיות.
כל
פלאגין שאני
יכול להתקין
אני צריך לוודא
בכל פלאגין
שאני לא שובר
לחברה את
הפיתוח בגלל
הפלאגין החדש
TESTING
Unit testing – does my small part of code is working properly?
Integration Testing = Does OUR code work correctly against a code we CAN’T change?
Acceptance testing = Does the whole system working properly?
Menus:
Dashboard>people>user name> modify details, for email notification for ex.
עבודה
עם פלאגינים:
- מה שמותקן אפשר לחפש בקלות בשורת חיפוש
- בחיפוש התקנות חדשות אפשר ללחוץ ולראות כיצד משתמשים בכל פלאגין.
- פלאגינים שצריך להתקין עברו הPIPELINE שלנו-
MENU
חדשים
שנוצרו
לדוגמא
SAFE RESTART,
יכבה וידליק.
תחת
MANAGE JENKINS
Manage
Jenkins>Docker : מציג את
המנועי DOCKER
שרצים
Manage
Jenkins>prepare to shutdown:
מכבה רק את
ג'נקינס
THIN BACKUP : אומרים
לו מה נרצה
לגבות ולאן
MY VIEWS
Manage Jenkins>scripts
לתכנת את
הג'נקינס על
ידיד סקריפט
שרץ על
ג'נקינס(לא GROOVY לCI)
Jenkins CLI
אפשר לדבר
איתו דרך CLI במקום
הDASHBOARD,
אם הוא כבד
מידי, איטי
מדי,
לעצור
להפעיל ג'ובים
וכולי.
Manage Old Data
אם רוצים
לנקות
סטטיסטיקות
– אם יש עומס,
על ה EXECUTERS.
JENKINS LOGS : מה
קורה בהתקנות
של JENKINS,
אם פלאגין
הותקן כהלכה
או עם שגיאות.
SYSTEM INFORMATION:
מופיע גם ENV VAR
השמורים.
Credentials>Credentials provider – JIRA או כל דבר
אחר, SSH,
כל CRED,
מנהלים את זה
מפה.
CONFIGURE GLOBAL SECURITY הרשאות ספיציפיות לכל USER.
Security->Authentication->LDAP
מאפשר
לי להגדיר את
כל ההראשות
לפי קבוצה,
משתמש או
אפילו JOBS.
דרך-
-<MATRIX BASED
מאפשר
לי
להגדיר/להוסיף
יוזר, קבוצה
וכולי.
-אפשור
למשתמשים
להירשם
עצמאית:
ALLOW USER TO SIGN UP
אפשר
גם לתת להם
להירשם בעצמם
דרך הJENKINS(קופסא
לסמן)
MANAGE USERS
אפשר
לייצר עוד USER, שרק
יכול לעבוד על
ג'נקינס(לא
עבור ACTIVE DIRECTORY
או בשרת)
Manage Jenkins>global security
Git host key – עדיף לבטל סיסמא כדי שיהיה מהיר יותר כי גם ככה מאובטח בSSH.no verification
לקבוע
איזה PORT מדברים
עם ה AGENT
(ולפתוח בAGENT) אפשר FIXED
או משתנה
Manage files: configuration of Jenkins
Manage nodes and clouds: configure new nodes
Configure cloud: Kubernetes or docker
Global tool configuration
הגדרת
כלים גלובלית
לכל הAGENTים
שלי. נניח
נרצה GIT
בכולם. או JDK, או GROOVY.
שיהיה על
כולם.
או
TERRAFORM,
או ANSIBLE.
כלים שיהיו
מותקנים
גלובלית על כל
ה AGENTים.
Configure System
HOME DIRECTORY : מראה
איפה שמור כל
הDATA של
ג'נקינס(נתיב).
קביעת
כמות ה EXECUTERS,
בד"כ על פי
כמות הCORE.
QUIET PERIOD-
קביעת מספר
שניות לתחילת
התהליך. במידה
ולוחצים מהר
מהר קליק
קליק, עדיף
להוריד ל1
שיעבוד מהר
GLOBAL PROPORTIES:
אם נרצה
להוסיף ENV
VAR שלא
קיימים NATIVE.
הרמת PIPELINES 1:
CONFIGURE> ADVANCED PROJECT
תחת
PIPELINE SYNTAX
שמתחילים
עם DSL
עושים
ALLOCATE NODE – שזה
הSLAVE
שמריץ לנו את
הJOB>מתוך
הSYNTAX
לפני
שמתחילים
בתהליך הCI, נעטוף
קודם בשמות של
השלבים , STAGE>בוחרים
מהSYNTAX>נותנים
לו שם
וכך
לכל אחד
מהשלבים לפי
השמות שלהם(BUILD, TEST וכולי)
1)פורק
לתוך המכונה
מגיט- CHECKOUT
גם בוחרים
מתוך הSYNTAX
שמים את הקישור לריפו ואת הענף הנכון. ועושים GENERATE, מעתיקים ומדביקים.
2) ווידוא
שיש את הפקודת
הפעלה
מהדוקר(אם
מריצים מריפו)
צריך להוריד
את הכל לתוך
המכונה קודם
אם
אין-צריך
להתקין או דרך
APT או
דרך WGET
והתקנה דרך
סימבוליק
לינק:
Ln -s <path of command folder> <path
of usually /usr/local/bin/>
אפשר
לבדוק דרך WHICH
וגם
כדאי לעשות
סימבוליק
לינק לפקודה
שתרוץ על ה LATEST דרך
אותו רעיון
3)
הרצה של
האפליקציה-לוודא
שהפורטים
הנכונים פתוחים
ושהכל פתוח גם
בVM
וגם בFIREWALL.
וגם
שהנתיב נכון.
4)בדיקת
אינטגרציה- CURL על
הכתובת עם
הפורט ואפשר
לעשות תנאי
החזרות שגיאה
5)
כיווץ
ארטיפקט-האפליקציה,
בצורה
אוטומטית(דרך
הסקריפט)
6)
שחרור לתוך הPIPELINE
שיהיה זמין
להורדה דרך
פקודת ARCHIVE
שקיימת דרך SYNTAX
אם
נרצה לראות
דרך MY VIEWS:
תחת
DASHBOARD< JOBS
בוחרים
+ יוצר NEW VIEW
נותנים
שם, ואומרים
לו איזה JOB
וכמה BUILD
אחורה נרצה
שיראה לנו.
העבודות
נשמרות תחת :
/opt/tomcat/.jenkins/workspace
שצריך
גישת ROOT
שבהן
אפשר לבדוק מה
הותקן מעבר לREPO,
כדי לדעת מה
לכווץ/לארוז PACKAGE.
TIP TESTING
FLAG של FAIL:
-f בCURL:
להריץ
curl -f <ADDRESS> כדי
לקבל את
התכולה
מהפלאג FETCH,
כי אם
מתקבל 404 זה
עדיין יכול
להתקבל כטסט
שעבר.
sh 'sleep 8'
sh '''curl -f http://127.0.0.1:8080/hello-world-war-1.0.0/;
if [ $(echo $?) -ne 0 ]; then
exit 1
fi'''
הרמת
SLAVE לJENKINS שיריץ DOCKER
-לפתוח
מכונה חדשה(CENTOS)
שעובדת BRIDGE
וגם בTOMCAT JENKINS
משנים ל BRIDGE
-
בודקים ב IP ADDR
במכונת SLAVE
מה הכתובת
שהוגדרה
ומתחברים SSH
-
הכניסה לJENKINS בדפדפן
היא עדיין דרך
פורט 8080 אבל
הכתובת החדשה
(של הMASTER
לא של הSLAVE)
-
משנים שם בSLAVE כדי לא
להתבלבל הין הGIT BASHים.
NMTUI בSUDO
-
לוודא שאנחנו ROOT ולא
משתמש אחר
-
אם אין הגדרת
רשת בSLAVE
יש להגיע ל vi /etc/sysconfig/network-scripts/ifcfg-enp<number>
ולשנות
ONBOOT=YES
-
להוריד
ולהתקין דוקר
בSLAVE : curl
-fsSL https://get/docker.com -o
get-docker.sh
-
אתחול DOCKER
ולוודא שהוא
רץ : systemctl status docker
וגם docker info
לראות שאין
שגיאה
-
צריך גם
להתקין JAVA
כדי שהSLAVE
ידע לדבר עם JENKINS
שעובד בJAVA
-
Yum
install java-11-openjdk-nevel
-
MKDIR
JENKINS בתיקיית ROOT
עוברים
לדפדפן ב JENKINS:
-
פותחים NODE חדש
-
מסמנים PERMENANT AGENT
-
2 בCPU
, לשנות REMOTE
ROOT DIRECTORY לאיפה
שהסיפריה של JENKINS ב SLAVE(ROOT)
-
USAGE בוחרים אך
ורק ניהול
שלנו ONLY BUILDS
MATCHING THIS NODE אחרת
ג'נקיס יחרבש
את כל
הפייפליינים
של כל החברה
-
LAUNCH
VIA SSH הMASTER
והSLAVE
מדברים דרך SSH
-
מכניסים
את הכתובת של SLAVE.
-
כאן
מייצרים CREDENTIALS
שג'נקינס שומר
ומייצר כדי
שלא יהיה חשוף
לכל עין.
-
אז
עושים ADD לCREDENTIALS
ושמים את
הפרטים, שיהיה
ROOT
-
בוחרים
ב CREDENTIALS
המרשימה את מה
שהזנו עכשיו
-
בוחרים NON VERFIABLE ו SAVE
עכשיו
הNODE
של הSLAVE
צריך להיות ONLINE
רואים בSTATUS
וגם צריך
לראות EXECUTERS(CPU)
שזמינים.IDLE 1 IDLE 2.
INTEGRATION AND TESTING
-
פותחים PIPELINE חדש
ונכנסים לSYNTAX
-
בוחרים NODE
ושמים בלייבל
את המכונה
שאיתה אנחנו
עובדים(לדוגמא
DOCKER).
מדביקים ל DSL (declarative syntax)
-
CHECKOUT
בוחרים REPO ומדביקים
הכל לDSL,
-
אם
לקחנו מGIT
וזה לא מותקן
בSLAVE
נקבל שגיאה ב BUILD NOW, אז
להתקין GIT(YUM INSTALL GIT)
-
בונים
את הCONTAINER
עם BUILD -T אבל
צריך שיהיה
מוכן REPO FOLDER
אחרת זה יהיה
חסר שם ולא
משוייך.
-
נעשה REPO חדש
לCONTAINER
שאנחנו בונים
עם השם שנבחר
-
השם של הREPO
שבחרנו זה השם
של הIMAGE.
ולכן נשים
אותו בפקודת BUILD בDSL
-
הגענו ל sh”docker build -t
arielguez/hello-from-jenkins”:
-
נוסיף
גרסא. שצריך
להשיג מתוך
(לא מתוך SYS
INFO >>ENV)
כי זה עלול
לדרוס קודמים.
אנחנו רוצים
את הגרסאת BUILD
הנוכחית
-
כדי
להגיע לזה
נפתח JOB
חדש. נבחר EXECUTE SHELL, ושם
יש רשימה של
כל AVAILABLE ENVIRONMENT
-
ואנחנו
צריכים את BUILD_NUMBER שזה
מספר
ההרצה-המספר
שהפייפליין
רץ בBUILD
(1-2-3 וכולי)
-
אז
נוסיף אחרי : ${env.BUILD_NUMBER}
וזה ייתן את
המספר לעיל.
-
Sh”docker build
-t arielguez/hello-from-jenkins:${env.BUILD_NUMBER} .”
-
תזכורת-
הנקודה בסוף
הסקריפט הזה
היא המיקום של
הDOCKERFILE.
כלומר אם היה
בPATH
אחר יש לציין
-
ERRORS:: לוודא
שהSLAVE
אכן רץ ברשימת
NODES. וגם
אם זה WAR
לוודא מה שם
האפליקציה
בתוך
הקונטיינר(EXEC) ואז
לשים כROUTE
בLOCAL HOST
לדוגמא: localhost:8888/hello-world-war-1.0.0
-
נוסיף לSTAGE TEST: sh “docker run -itd –name <new name> -p 3000:3000
arielguez/hello-from-jenkins:${env.BUILD_NUMBER}” יש
לשים לב ששמנו
את הנתיב והשם
המלא של הIMAGE.
-
יש
להוסיף SLEEP לפני
ואחרי CURL
כדי שהוא
יספיק לקרוא
אותו, וגם
צריך לסגור אותו
בהרצה הבאה
-
Sh
“sleep 4”
-
Sh
“curl localhost:3000” זה
הבדיקה שהאתר
רץ
-
נשרשר
שתי פקודות
באמצעות &&.
אחת לעצור את
האתר ואחת
למחוק.
-
Sh
“docker stop hello-from-jenkins && docker rm
hello-from-jenkins”
-
עבור STAGE PUSH TO DOCKER:
-
Docker
login בשימוש
עם WITH CREDENTIALS: מוסיפים
בהגדרות עוד+
קרדנציאלז.
ומזינים לפי
ההגדרות של DOCKER HUB. ואז
נותנים משהו
פיקטיבי לJENKINS
שיראה בDSL
-
withCredentials([usernamePassword(credentialsId:
‘docker login', passwordVariable: 'pass', usernameVariable: 'user')]) {
-
sh
"docker login -u $user -p $pass"
-
sh "docker push arielguez/hello-from-jenkins:${env.BUILD_NUMBER}"
הרמת
PIPELINE 2
- NODE,.
Node(‘docker’) {
STAGES
באינדנטציה, NESTED בתוך-
Checkout
לוקחים
את הקוד
העדכני כדי
לעדכן את
הפייפליין
Stage(‘Checkout’) {
קוד
עבור כל שלב(מGENERATE PIPELINE SYNTAX)
אם
לוקחי מGIT
לבחור הורדת CODE>> HTTPS. כדי
להדביק לCHECKOUT
BUILD
Docker build -t <name WITH repo name
for ex:> Arielguez/hello-world: ${env.BUILD_NUMBER}
TEST
Docker
run
Curl
PACKAGE
tar -czvf app.tar.gz *
-c : compress
-z : gzip compression
-v : verbose
-f : specify which filename after
the tar file, namely *
שלבים
אחרים
Archive,
artifact, garbage disposal
טיפים
חשובים
-ג'נקינס
עובד עם משתני
סביבה, כך שאם
עדכנו משהו בSLAVE של
הג'נקינס- רוב
הסיכויים שלא
ייתפס. לדוגמא
התקנו GIT בSLAVE של הWINDOWS.
אז עד שלא
ננתק ונחבר את
השרת של הWINDOWS
דרך TASK SCHEDULER, ג'נקינס
יכשל הPIPELINE שמפעיל
GIT.
-אפשר
לשים POWERSHELL
בתור שפה בGROOVY
-blue ocean from Jenkins>new pipeline
- select github(or
other repo)>access token:
- to get access token: click to get from
link>authenticate>(inside github):”new
personal access token”, type ref.name we want+expire time+generate
-copypaste to blue ocean>choose your
main repo of github>select sub-repo to work on the pipeline
- ניתן
לראות את כל
הפייפליינים
והג'ובים
pipeline
layout:
- click start>select agent (node) and
label for it (docker or other)
- put all stages > checkout, build,
test, artifact, push to dockerhub
-for checkout select GIT from list>
paste URL and branch name
-for build>shell script from list
- test> same as DSL
- artifact> zip or tar(usually
in the folder itself) tar -czvf nodejs.tar.gz * <<the * is because all
files in the folder
- push to dockerhub> need to use bind
credentials with variabls>docker login -u $user -p $password (shell)
+ docker push arielguez/reponame:$BUILD_NUMBER (DSLבשונה
מ )
מאפשר
STATIC CODE ANALYSIS –
הערכה של קוד
ללא הרצה שלו,
מספק צפיה בVULNERABILITES, SECURITY, מאפשר
שערים GATES בהתאם
לבעיות שנצפו.
שזה
בדיקת קוד כמו
בוויזואל
סטודיו – אבל
עם אפשרות
לחסום קודים
ספציפיים על
ידי RULES.
ואז
לחסום או
להוריד PIPELINES
SonarQube = לוקאלי. Sonar Cloud
= בענן, פשוט
יותר
יש
לו TOKEN
שהשרת JENKINS
נותן וצריך
לשמור
אפשר
לקחת מGIT
דרך SONAR CLOUD,
ומראה לך
בעיות על כל
קוד שיש בכל REPO
כיצד
רואים?
נכנסים
לאחד הREPO
שיש בו בעיות
– ולוחצים על
המספר של
הבעיות , וזה
מציג.
בSONAR SCANNER CLI, נצטרך
לעשות קובץ בGIT sonar-project-properties
לא
נשים STATIC CODE
ANALYSIS על COMMIT,
כי זה יאיט
והמפתחים
יתקעו. אבל כן
נשים על MERGE
בין BRANCH
מעבר
לCI
כמו בג'נקינס, Git-Action
מספק לך HOSTING
לTESTING.
מה שנקרא RUNNERS.
Supercharge workflow model
הוא מספק
הטמעה של כל
תהליך CI CD
בכל שלב של
הפיתוח.
לדוגמא, בתוך FEATURE
אחרי גרסא
ראשונית.
הגדרות
של ההטמעה
יכולות להיות
לפי מיקום בבראנץ,
או לפי EVENT טיפוסי
או כמה
במקביל.
Runner זה כמו NODE
בג'נקינס, וזה
מה שגיט אקשן
משתמש בDEPLOY
של COMPOSE
או DOCKERFILE.
לדוגמא,
מציינים זאת
דרך RUNS ON
וכל מה שנכתוב
עם LATEST זה
יבחר RUNNER
של GIT.
אם נרצה שלנו (SELF HOST) -צריך לציין.
אפשר
לקחת תבנית
מוכנה עם
פקודות
מוכנות בהתאם
לפרויקט.
אפשרויות
עבור ON –
release, pull, check_suite, deploy
או
הפעלה על פי
שעון/טיימר - on:
schedule:
אם
אנחנו
מפעילים כמו
פעולות על
הקונטיינרים
שרצים בRUNNER
של ACTION,
אז משתמשים
בשמות של
הקונטיינרים
כמו IP.
לדוגמא_COMPOSE)
services:
frontend:
image: your-frontend-image
ports:
-
"3000:3000"
בדוק
שם הקונטיינר:
DOCKER PS -A
ואז
בACTION:
-
name: test_frontend_container
run: sleep 5 && curl <container
name>:3000
X not working
To get own runner (self-hosted:
Settings>actions>runners
Choose OS
והתקן את
הפקודות בRUNNER שלך.(במכונה)
On:
Push: <<<<
only on push command
Branches:
-master
<<<<
only for master branch
Tags:
-v1 <<<< only
applies over v1 commits
Paths:
-‘test/*’ <<<<
only files inside test folder
SCRIPT EXAMPLE- AND MORE ON SCRIPTS:
name:
trigger workflow
# Controls when the workflow will run
on:
#
Triggers the workflow on push or pull request events but only for the
"main" branch
push:
# pull_request:
# branches: [ "main" ]
# Allows you to run this workflow
manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs
that can run sequentially or in parallel
jobs:
#
This workflow contains a single job called "build"
trigger:
# The type of runner that
the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence
of tasks that will be executed as part of the job
steps:
- name: trigger another workflow
run: |
curl -X POST https://api.github.com/repos/${{ github.repository }}/actions/workflows/issue.yml/dispatches \
-H 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: Bearer ${{ secrets.REPO_ACCESS_TOKEN }}' \
--data '{"ref": "${{ github.ref }}"}'
בפתיחת WORKFLOW של REPO, יש לשים לב בהגדרות הACTIONS>WORKFLOW PERMISSIONS שאפשר לעשות READ WRITE PERMISSIONS
TRIGGER כהפניה לWORKFLOW אחר, יש
לשים לב
שאנחנו
מציינים ב CURL את ה PATH ושם
הקובץ YML
של הWORKFLOW
המופנה
בתוך
DATA יש גם
לציין את הBRANCH אבל
זה נגיע דרך
--data
'{"ref": "${{github.ref}}"}'
יצירת WEBHOOK ל SLACK:
פותחים SECRET
חדש ב: CURRENT
REPO>SETTINGS>SECRETS>ACTIONS>NEW REPO SECRET
ב SLACK יש להכנס ל WORKSPACE שנמצא מצד
שמאל
למעלה>תפריט>ADMINISTRATION>MANAGE APPS
CREATE NEW APP>SELECT WORKSPACE>לבחור
שם>לסיים
בWORKSPACE שאנחנו
בחרנו-MANAGE
APPS> שם
של האפליקציה
שעשינו שלב
קודם>BASIC
INFORMATION>ALLOW WEBHOOKS>למטה:GENERATE
TOKEN>COPY של
הTOKEN
בGITHUB בריפו
שאנחנו
עובדים עליו>SETTINGS>SECRETS> להכניס שם
הSECRET שיהיה בYML(SLACK_WEBHOOK)>להדביק
מהקודם.
ראה SCRIPT לפירוט
INPUTS:
ניתן לקבל INPUTS מהGIT
נתונים שלו
כמו HASH ID של COMMIT, או
מאיזה סביבה
נבחר לבנות(DEV או PROD)
דוגמא:
on:
workflow_dispatch:
inputs:
environment:
description: 'Indicates environment for deployment'
required: true
default: 'development'
service:
required: true
default: 'htd-core-ms'
revision:
required: true
נוכל לשלוף
את ההגדרות
שלעיל כך:
${{ github.events.inputs.service }} שיתן לנו
את ערכו של SERVICE
במקרה זה htd-core-ms. אלא אם
כן הועבר ערך
אחר
REQUIRED אם TRUE, מחייב
שיהיה INPUT VALUE שנכנס
אחרת הWORKFLOW לא
יתחיל.
העברת ENVIRONMENT VARIABLES בACTION
משתנה
מוגדר בGITHUB הוא $GITHUB_ENV
ואליו אפשר
להעביר על
משתנה סביבה
שנרצה שיהיה בRUNNER
שלנו, בתהליך
הCI, שאולי
נרצה גם
להעביר לIMAGE שיהיה
בתוך
הקונטיינר, על
ידי שימוש בARGS.
אחרי
התקנה (טריאל
זה 14 יום עם כל
הדפנדנסיז), OSS
גרסא חינמית
אבל כמעט בלי
כלום. רק
מייבן.
יצירת
חוק-
תפריט
> XRAY > WATCHER & RULES >
להכניס חוקים.
נניח רק לעצור
התקנות עם
שגיאה קריטית.
יצירת
WATCHER
-
והשמה של החוק
שלעיל. ואז כל
התקנה עם
שגיאה קריטית-לא
תותקן או
תמחק.
יצירת
REPORT
בוחרים
REPO,
ועושים GENERATE(אם
לא צריך עוד
הגדרות)- ואז
זה מייצר דוח
עם כל הVULNERABILITIES.
שאפשר לשלוח
למפתחים.
(הם
האחראים על
פגיעויות של
הארטיפקטים)
נקסוס וJfrog הם
REPOSITORY MANAGER.
מאחסן ARTIFACTS
וגרסאות BUILDS.
NEXUS
תחת
גלגל השיניים,
ניתן לראות REPOS
קיימים, BLOB
STORE זה סוג של
ווליום
האחסון של
נקסוס-שם
נשמרים כל הARTIFACTS, אם
נגמר המקום
מייצרים BLOB נוסף.
SYSTEM-
יש מה שנקרא SWAGGER. API של נקסוס.
והוא מאפשר
עבודה מולו
דרך סקריפטים.
(טוב
לאוטמציה?),
עבור כל תפריט
שקיים DASHBOARD
שמציג SCRIPT
דרך הCURL
פורמט JSON
הוספת
REPO
בGROUP יש
לציין HTTP
עם PORT,(לסמן
V)
בהנחה שאנחנו
מאחורי Secure
Proxy .
צריך
שיהיה גם HOST ו PROXY
הסרה
של NEXUS
חייבים
להוריד יוזר NEXUS
אחרת לא יעבוד
-חייבים
להוסיף REALM
TOKEN BEARER לכל REPO
שנרצה להוסיף.security>realm
-
עובד רק עם PRO LICENSE ב DOCKER
NPM
-יש
לצרף ריפו – HOSTED וPROXY
כGROUP,
ואז להסב פורט
שתהיה גישה
לריפו כי זה
לא מאפשר HTTPS רק HTTP,
אז מאפשרים
דרך HTTP בGROUP
-יצירת חיבור
בין JENKINS לNEXUS:
יש
ליצור/לערוך
במחשב המארח-WINDOWS-
קובץ שנמצא
בתור users/ariel/.docker
בשם daemon.json:
להוסיף
–,”insecure-registeries”:[<ip
of nexus machine>”192.168.14.13: 8088”]
ואז יש
לעשות docker
login לIP של
מכונת הNEXUS docker login 192.168.14.13:8088 עם
הסיסמא של NEXUS!!
KUBERNETES
ייחודי בגלל Scaling,
ניצוח/ORCHESTRATING
וניהול
קונטיינרים
עבור CLUSTER של
מכונות. יכולת
להרים כמה
מופעים של
אותה אפליקציה
(horizontal(
יכולת ניטור מצב בריאות של שרתים וקונטיינרים וגם אתחול שלהם לרציפות בDEPLOYMENT.
לקוברנטיס
גם אפשרות
לדרוס משתני
סביבה קיימים
בIMAGE,
ולשים משלו,
דרך SECRET GENERATOR
ולרפרנס אותם
דרך DEPLOYMENT
****סכנה: MASTER של
קוברנטיס
אסור שיפול!
הפצות
מסחריות של
קוברנטיס:
AKS, EKS, GKE, RackSack KAAS, IBM Cloud Container Service
(זה בקטנה
על קוברנטיס,
פירוט מלא
בנושא הבא KUBERNETES CLUSTER)
MINIKUBE
---------------------
יש
התקנה בPOWERSHELL
לווינדוז:
Winget install minikube
Minikube version
בדיקת הגרסא
פתרון
שגיאות: אם יש
בעיה FAIL-
Minikube delete –all
אם
יש בעיה
בהתקנה גם
אפשר להוסיף
לפקודות
Minikube start --no-vtx-check
POD:
תאור
האפליקציה,
יכול להיות
קונטיינר או
שניים.
Minikube kubctl – get pods -A
אפשור
של KUBECTL
מכל מקום(גם
ללכת לENV
ולשנות ב PATH)
NODE:
מכונות או
מכונה
וירטואלית או
פיסית
שמריצה
services וגם את הPODS
בדיקת
צריך
גם KUBECTL
סגירת
MINIKUBE:
קודם
SAVESTATE
ואז minikube pause
וכדי
להפעיל מחדש
קודם מעלים בVM ואז minikube unpause
Minikube addon list
Minikibe enable addon
פקודות
KUBECTL:
Kubectl get nodes:
איזה מכונות
רצות עכשיו
Kubectl get pods -A :
איזה פודים
רצים
Kubectl get all -A:
מציג את כל ה RESOURCES
Kubectl describe node minikube
: מתאר
את פרטי הנוד
של מיני
קיוב-אפשר
לבחור גם שם
אחר עבור NODE אחר.
Kubectl get rs : מציג ReplicaSets
שזה שכפול של
הקונטיינרים
הרצת
אפליקציה דרך POD:
קובץ
YAML
Kubectl create -f <path of yaml file, and
its file name> יצירת
האפליקציה
בפוד
גילויי
של הדומיין : kubectl get pods -A
Kubectl logs <(domain
name) >
Kubectl port-forward <name of app/pod>
8081:3000
מאפשר
הרצה של
האפליקציה
בדפדפן ע"י
הפניית פורטים
שיטות
SERVICE:
Service נותן לנו
גישה
לאפליקציה
דרך הדפדפן
לדוגמא.
LoadBalancer-
-Node
Port
NODEPORT
מאפשר
כניסה לכל POD
מאיזה פורט
שנבחר כשירות,
וגם מכל NODE
הרצת
SERVICE:
Kubectl apply -f <name of yaml file>
בדיקת
השירותים
שרצים SERVICES:
Kubectl get services – או svc גם עובד
בדיקת
הIP
שרץ :
Cat c:\users\ariel\.kube\config
לחפש
איי פי פנימי
ERROR אם יש
להריץ דרך ADMIN את הPOWERSHELL
הרצת
קונטיינר
חיצוני מדוקר
האב:
kubectl run -i --ty --image=busybox
--restart=Never – sh
ומאחר
ואנחנו
מריצים
מהמכונה
הפנימית שלנו אפשר
ממש מתוך הCONTAINER הזה
שהבאנו
מDOCKER HUB
לעשות PING ל SERVICE :
Ping helloworld -service
Minikube service helloworld-service:
מציג את
השירות וגם
פותח אותו
בדפדפן
REPLICATION CONTROLLER
מאפשר
שיכפול HORIZONATLLY,
שזה אומר שהוא
לא מבזבז עוד
משאבים
ואנרגיה-בניגוד
לוורטיקלי.
האפליקציות
המשוכפלות
חייבות להיות STATELESS – כלומר STATIC, שלא
צריכות הזנה
של נתונים מהCLIENT.
ראה
SCRIPTS
Kubectl delete <name of container>
ימחוק את
הקונטיינר
אבל בגלל שזה
תחת REPLICATION CONTROLLER,
זה ימחוק
ויבנה אחד חדש
כדי
למחוק את
הקונטיינרים
תחת RC:
Kubectl delete rc helloworld-controller
Kubectl get rc : יציג מה
קיים בREPLICATIN
CONTROLLER
REPLICATION SET(advanced
version of controller)
חלק
מ DEPLOYMENT(בCONTROLLER אין DEPLOYMENT)
לא
מבוסס רק על SELECT על
פי EQUAITY,
ניתן לבחור
בצורה אחרת גם
עובד
יותר טוב עם
עדכוני
גרסאות
DEPLOYMENT
מאפשר
קוסטמיזציה
של עדכונים,
הגדרת מצב עדיף
של האפליקציה,
יש ACTIONS:
Create -
יצור DEPLOY וגם
יאתחל REPLICASET בהתאם
למספר
השכפולים
שהגדרנו
Update –
ישלוט בSCALING
וייצור REPLICASET
חדש בהתאם
לעדכון.
Rollback –
לחזור אחורה
גרסאות
PAUSE/RESUME
הDEPLOYMENT יגיע במצב של פוד עם הגדרה של DESIRED STATE לכמות פודים וגם מאפשר את הלעיל(לחזור אחורה וקדימה)
חייב שיהיה לו שדה/בלוק של TEMPLATE ושל LABEL כדי שהDEPLOYMEWNT ידע לנהל את הפודים לפי השם.
Kubectl get deploy מציג DEPLOYMENTS
פעילים
Kubectl get pods –show-
Kubectl rollout status
deploy/helloworld-deployment –
הסטטוס בודק
אם הDEPLOY
הצליח
Kubectl set image deploy/helloworld-deployment
k8s-demo=webdevian/k8s-demo:2 - מעדכן
לגרסא 2 על ידי SET IMAGE
כדי
לבדוק מריצים
את הפקודה עם
ה ROLLOUT
Kubectl rollout history deploy/helloworld-deployment : בודק את
כל ההיסטוריה
של הגרסאות
UNDO
Kubectl rollout undo
deploy/helloworld-deployment
>>>>>לכן
גם חשוב מאוד
לא למחוק IMAGE אן לעשות kubectl delete –all -A כי זה
יכול להשמיד
את ה UNDO
LABEL
הדבקת
תווית על
אובייקט בדרך
כלל בYAML(ראה
SCRIPTS)
:kubectl get pods
–show-labels מציג
לייבלים של
הפודז
Kubectl get rs –show-labels
: יציג
את הלייבלים
של REPLICASET
הנוכחיים
kubectl get deploy
--show-labels: יציג
לייבלים של ה DEPLOYMENT
- השימוש בLABEL לדוגמא שצריך לפנות לגרסאת PROD או DEVELOP, אז אפשר לתייג/LABEL לפוד שתואם את זה.
POD
היחידה
הקטנה ביותר
של הקלאסטר,
להבדיל מהגדולות
יותר כמו REPLICA SET שיש בה
יותר מפוד
אחד, או DEPLOYMENT
שממכיל גם REPLICA SET וגם SERVICE
DAEMONSET,
וכמובן NODE
שהוא מכיל את
הכל. פודים לא
מייצרים
בצורה ישירה,
כי אז קוברנטיס
לא יחדש אותם
שהם נופלים.
לכן יש DEPLOYMENT
או REPLICASET
סוגי
STATUS
של הפוד:
What happens when you run a Pod with kubectl?
node
labeling:
kubectl get nodes : כדי
לדעת את שם הNODE
kubectl label
nodes minikube(node name) <label>hardware=low
kubectl get
nodes –show-labels יציג אלנו
את הלייבלים
שעשינו- HARDWARE=LOW
TROUBLESHOOTING LABLES
נניח
שהYAML
כתוב hardware=high-spec
צריך
לגלות איפה
השגיאה כי הוא
רק יעצור ולא
יתן לעשות
APPLY
בגלל
הקונפליקט
בלייבלים -low<>high-spec
nodeSelector:
קובע
באיזה NODE
שבחרנו יהיה
מחוייב
הלייבל (ראה SCRIPT)
פתרון
TROUBLESHOOT:
Kubectl describe pod helloworld-deploy:
שם נמצא בתוך nodeSelector את
הלייבל הלא
מתאים
אם
נרצה לעדכן ל HIGH SPEC:
Kubectl label nodes minikube hardware=high-spec
–overwrite: OVERWRITE
מאפשר כפיה
- יש לשים לב שלא ירוץ פודים אם לא יענה על הדרישות של NODESELECTORS
Annotations:
קינפוג
של RESOURCE
קיים בS8K. עוד KEY PAIR, אבל
בשונה מLABELING
יכולים להכיל
יותר
מורכבויות.
ולא כשימוש לבחירת
אובייקטים/NODE/POD.
הANNOTATION נקבע
על ידי צד
שלישי, API,
משאבים וכולי
וכך קוברנטיס
יכול להעביר
אותם והם ממש
יכולים לשנות
קונפיגרציות או
לעקוף אותם
על
ידי השימוש
באנוטציות(ANNOTATION).
דוגמא
של INGRESS REACT ANNOTATION
בדוגמא
לעיל מוגדר 100MB פר
בקשה ללקוח,
והפניה
קבועה ל-/ של
הראוטים של
האפליקציה כל פעם
שמשתמש פונה
לכתובת של
האפליקציה(כדי
למנוע
קונפליקטים
בין הראוטים)
READINESS CHECK + HEALTH/LIVENESS CHECK
HEALTH CHECK –
עושה בדיקה אם
האפליקציה
מצליחה לעשות DEPLOY
לדפדפן
Kubctl describe pod <name of pod> : יציג
אם הHEALTH CHECK הצליח
או נכשל
READINESS CHECK : בודק
אחרי שהפוד
רץ, שמוכן
לקבל תעבורה. אם
הבדיקות של
גישה אל השירות
עומדות
בתנאים
שהצבנו בYAML, ואם כן אז
הוא "בריא", אם
לא, הוא מאתחל.
בדיקת
TCP SOCKET
לדוגמא
LIVENESS TEST - בודק אם הפוד עובר מבחן בריאות בזמן שהוא רץ, ואם לא- אז הפוד "לא בריא" ולכן יאותחל עד שיעמוד בדרישות הבריאות
זה לא
בדיקת עומס,
אלא מריץ GET לhealthz
ואז לפי
הפקודה שיש שם
בקוד של
האפליקציה, אז
יחזיר שזה
עומד בדרישות
או לא.
הערה:
הקונטיינר
אכן רץ בזמן
שיש בדיקות,
ויכול להראות
שהכל עובד. או
להגיע בסוף
למצב CRASHLOOPBAKCOFF.
שזה יותר מדי
כשלונות
ואתחולים של
הפוד.
במצב שהוא שיש כשל בבדיקות אבל לא עצירה של הDEPLOYMENT, יש לעבוד עם ALERT MANAGER שיתריע על תקלות.
POD STATE
Pending: יש
בקשה אבל לא
רץ עדיין-או
שמוריד לאט
בגלל מרחק, או
בעיית RESOURCES)
- אם עדיין מוריד
-
אם לא
עומד בRESOPURCE
CONSTRAINTS לדוגמר NODESELECTORS עם ה HIGH
HW.
Succeeded:
מחק והשמיד את
כל
הקונטיינרים
ולא אתחל אותם
Failed:
כל
הקונטינרים
הושמדו ואחד
לפחות החזיר
שגיאה
Unknown:
כנראה בעיית
רשת או חיבור
שלא מאפשרת
לבדוק את המצב
של הPOD,
או שנגמרו לו
הNODE
לעשות לו ALLOCATE
הכל
נמצא ב DESCRIBE
SECRETS
במקום שהDEV ישים את הTOKEN בGIT, נשים את זה בקוברנטיס או כמשתנה סביבה, או כקובץ קוניפגורציה.
Secrets
כברירת מחדל הם
רק בעלי HASH64
שזה לא
קריפטוגרפי,
אלא רק דרך
לשמור בינארי.
כל
SECRET
שהוא לא שמור
בצורה מיוחדת,
ניתן לקחת
אותו ולצפות
בו עם
Echo “<SECRET HASH>” | base64 –decode
שמירת
SECRET :
-או
כקובץ(מוצפן
שרק
הקוברנטיס
יכול לעשות לי
DECRYPT,
ורק שהפוד רץ
זה מופעל!)
-או
כמשתנה סביבה
-זה
לא נכנס ביחד
עם הIMAGE!
זה שמור בMASTER איפשהו.
שיטת
ENV VARIABLES,
ודרך FILE:
שימוש
בFILES:
Echo -n “root” > ./username.txt
Echo -n “password” >
./password.txt
זה
שופך לתוך
הקבצים האלו
את השם משתמש
והסיסמא-ללא
שורה רווח.
הפלאג -n
מוריד את
השורת רווח
Kubectl create secret generic db-user-pass
–from-file=./username.txt –from-file=./password.txt
מייצר
SECRET
ג'נרי תחת השם user-db-pass מהקבצים
שבנינו קודם
אפשר לבדוק עם: kubectl get secrets
ורואים סוג opaque של הsecret
כדי
לראות הסבר:
Kubctl describe secret db-user-pass
כדי
לראות את
הסיסמא
שייצרנו:
(למעשה
שמנו את שמות
הקבצים בתור
סיסמא ומשתמש-
לא את הסיסמא
והשם עצמו)
SECRETS
דרך YAML:
מעבירים
לENCODING של
בסיס 64,
Kubectl get secret db-user-pass -o yaml
יציג
לנו את הסיסמא
והשם משתמש בENCODING של
בסיס 64
Echo -n “root” | base64
Echo -n “password” | base64
יציג
את אותו משתמש
וסיסמא בENCODING של בסיס
64
מבחינת
בטיחות
האחסון של
הקבצים הללו
הם תחת RBAC
וETCD
שאומרים להגן
מפני קריאה.
כלומר
ההצפנה עצמה
אינה
הגנה/אבטוח
אלא רק דרך
להעביר מידע
בבטיחות
דרך
YAML כENV. VARIABLES. ראה ENV בSCRIPTS
לעשות
APPLY
לקובץ כדי
להפעיל
Kubectl apply -f deploy-helloworld.yaml
בדיקה
שהסיסמא
והמשתמש אכן
במשתני סביבה:
Kubectl exec -it <name of pod> /bin/bash
בתוך
הקונטיינר:
Env
ונראה
שם את SECRET_PASSWORD=
וכולי
SECRETS WITH YAML in FILES
אפשר
ליצור SECRET
דרך קובץ YAML ראה SCRIPT db-secrets.yaml
+ראה
החלפה של הSCRIPT של ENV מהDEPLOY
הקודם. תחת deploy-helloworld-with-secrets.yaml
שזה
מייצר VOLUME
וSECRET
שנשמר בתוך הVOLUME.
החלפנו
את הBLOCK
שהיה בENV בסקריפט
YAML הזה
והגדרנו
לו VOLUMEMOUNTS
עם נתיב ושם(db-secrets) וגם
הגדרת READONLY
וגם הגדרנו VOLUME בתחתית העמוד וגם שיש SECRET עם השם שהגדרנו קודם(db-secrets)
בסקריפט
האחרון הבלוק
של הSECRET
ניזון מהקובץ
של הSECRET
ומטמיע אותו
בתוך הENV
של הקונטיינר.
DASHBOARD MINKUBE
להריץ
DASHBOARD
של מיניקיוב
בדפדפן:
Minikube dashboard
כל
הדברים
שהרצנו
קיימים שם: SECRET, PODS- מה רץ LIVENESS
CHECK..
אם
נרצה להוסיף RESOURCES –
לוחצים על +
גדול מצד ימין
למעלה והכל
נכתב ב YAML
או
נרצה לראות LOGS DESCRIBE של POD דרך ה-3
נקודות ליד
השם, גם EXEC
יש
CONFIG MAP
מה
זה?
דומה
לSECRET,
הגדרות שאני
שומר מחוץ
לפוד, ולא
ביחד עם הפוד
עצמו. בבלוק DATA,
מייצר קובץ
קונפיגורציה.
זה הפרדה של ההגדרות מהאפליקציה- UNCOUPLED.
בד"כ
מועלה ביחד עם
VOLUME
אחרי שהוגדר
בקובץ
נפרד.כך:
valueFrom:
configMapKeyRef:
כלומר- CONFIGMAP מייצר "כוונה" לייצור קובץ עם הערכים שלו, ופורס אותו בMOUNTS איפה שנגיד לו, הוא לא נשמר כלל לפני הINVOCATION שלו.
בעל 3 סוג קונפיגרציות –
Environment Variabls, Container Commandline arguments, Volumes
איך?
הקונפיג FILE יהיה MOUNTED ויהיה נגיש אחרי שהפוד עולה, מתוך הVOLUME שיהיה זמין אחרי שהפוד עלה.
מגדירים
בDEPLOYMENT
את שם הCONFIGMAP
שנגדיר בקובץ
נפרד כCONFIGMAP,
איזה VOLUME
ואיפה
בקונטיינר זה
יתיישב
ובקובץ
של הCONFIGMAP
עצמו, נגדיר
את הDATA.
ואז קוברנטיס
יצור קבצים בMOUNT
שהגדרנו לו
בתוך
הקונטיינר
לפי הערכים
שהגדרנו
בCONFIGMAP
כערכים של .KEY PAIR
לדוגמא אם בDATA
בתוך הCM
הגדרנו driver:
jdbc אז
יווצר קובץ
בשם DRIVER
בתוך
הקונטיינר בMOUNT PATH
שהגדרנו עם
ערך בפנים של jdbc
Kubectl get cm <name of config map>
CHARTS
הגדרה:תבנית
קבועה(TEMPLATE)
של אוסף של
סקריפטים:שירותים-DEPLOY-PV-PVC כTEMPLATE אחד
שניתן לקנפג,
במקום להריץ
לחוד כל אחד.
מנוהל
ע"י:
HELM
שלוקח את הTEMPLATE מהCHARTS (שבקוד GO) ומייצר קובץ YAML לTEMPLATE.
K8s jobs
One time or more jobs to run, on a container periodically or not. Unlike pods which are indefinitely.
Usually deployed via cronjob
CLUSTER
משמע לפחות 3
מאסטרים- מספר
אי זוגי של
מאסטר. ו-2 WORKER
הסיבה
בגלל שרק 2
משאירים אותך
עם סכנה שאם
אחד קורס לא
יהיה לך חלוקת
ניהול כמו
שצריך.
שומר על HIGH AVAILABILTY
COMPONENTS של
קוברנטיס(קישור):
5
עיקריים:etcd, controller manager, api server, scheduler, kubelet(on worker node
only)
MASTER
-ETCD : סוג של DATABASE בעל KEY PAIR ,
שומר CONFIGURATION DATA,
ששם כל המידע
אם זה על
תקשורת או על
מצבי הפודים-
שמור. לדוגמא,
שומר SECRET
וגם RBAC RULES(אבל
הוא לא כופה
אותם, זה הAPI)
-API SERVER : מרכז ההתקשרות המרכזי. שמתקשר עם הכלים של הקוברנטיס KUBECTL וחושף את הAPI עצמו.
-
CONTROLLER MANAGER: תחזוקה.
MAINTAINING- מה
שאחראי
לניהול כשלים.
וגם להפעלה
מחדש של
פודים, כמו REPLICASET.
האיש אחזקה,
מתי שנשבר-
מתקן.
-
SCHEDULER:
מאפשר השמה של
POD חדש
שנוצר (בעקבות
כשל או מחיקה)
לNODE
קיים. לדוגמא
מדבר עם ה DEPLOYMENT, האיש
כוח אדם-מקצה
פודים לפי
הדרישות.
ההבדל
בין SCHEDULER
ל CONTROLLER
זה שSCHECUDLER
בוחר לאן לשים
כל משאב של
קוברנטיס(כמו
פוד),
לפי
פרמטרים כמו
קיבולת של הNODE, AFFINITY. ALLOCATION+SELECTION
בCONTROLLER הוא
עובד לפי DESIRED STATE
ומתחזק את
המשאבים של
קוברנטיס לפי
הDESIRED.
איש אחזקה(CONTROLLER)
לאיש משאבי
אנוש(SCHEDULER)
WORKER
-
KUBELET : AGENT
שמתקשר עם הCONTROL PLANE ,
אחראי על
אתחול עצירה
וניטור הCONTAINER בתוך הPOD.
מדבר עם הAPI SERVER
- KUBE PROXY: מאפשר CONNECTIVITY בתוך הCLUSTER , תקשור אחד עם השני.גם תומך ב LOAD BALANCER לSVC שחושף SERVICE
· מתקיים ב LAYER4 , מאפשר traffic routing , loadbalance traffic בין הפודים בשימוש בIPTABLES או IPVS
·
גם מנטר
ובודק על
שינויים
ומגדיר מחדש PROXY
בהתאמה.
- CONTAINER RUNTIME : אחראי על הרצת קונטיינרים ומשיכת דמויות, זו הSOFTWARE שמריץ את הCONTAINER ים בתוך הPOD
SECURITY
- RBAC: Role Based Access Control
o הוא שולט בגישה אל כל המשאבים של קוברנטיס, SERVICES, PODS, DEPLOYMENTS,קונפיגמאפ, NODES,
o מתקשר דרך בדיקת אימות(AUTHENTICATION)
o Service account זה מה שעושה BINDING לROLES והוא בעצם אומר לAPI SERVER של קוברנטיס -איזה הרשאות מותר לו לבצע על איזה משאב.
§ לדוגמא GRAFANA יכול להשתמש ולראות כל מיני מטריקות של NODE ושל פודים ושל DEPLOYMENTS כי הוא קיבל את ההרשאות מה ROLE אבל אותו ROLE מתקשר לSERVICE ACCOUNT שהוא מה שמדבר עם הAPI
§ 1. Grafana Pod (with ServiceAccount) → Makes API request
§ 2. API Server → Authenticates the ServiceAccount
§ 3. API Server → Looks for RoleBindings/ClusterRoleBindings for this ServiceAccount
§ 4. API Server → Checks if the bound Roles/ClusterRoles allow the requested action
§ 5. API Server → Allows or denies the request based on the result
o גישות והרשאות דרך ROLE, ROLEBINDING או במצב של כל הNAMESPACE על כל הקלאסטר CLUSTERROLE ו CLUSTERROLEBINDINGS
פודים
נוספים-
- CoreDNS:
מביא שמות
דומיין
לפודים אבל
צריך CNI
קודם. יורם רק
כאשר יש
פלאגין של NETWORK,
אחרת הוא ישאר
בPENDING
CNI – container network interface מה שמאפשר לקונטיינרים ולפודים לתקשר בינהם. מייצר את הIP לכל פוד.
ישנם
כמה שיטות
לייצר, אחת זה ENCAPSULATING
שיש כתובת IP של הקונטיינר ואז נשלח הPACKET ש"בקפסולה” עטוף בIP שלו.(לא ברור עדיין)
Kube
flannel:פלאג CNI
פופלרי
קביעת
המנהיג במצב
של יותר מMASTER אחד:
למה
צריך מנהיג?
כדי לאפשר מצב
של "אמת
יחידה" ומניעת
קונפליקטים.
כדי
לחבר בין כמה MASTER
שייתקשרו
בינהם צריך
להשתמש בLOADBALANCER
על MASTER ספציפי
שיהיה ה"מלך".
החינמיים
הם NGINX או HA PROXY.
הKUBELET
מתקשר עם ה Api server
ושהוא מגיע לLOADBALANCER הLB
מחליט לאיזה MASTER הוא
מפנה.
NFS: Network FileSystem ,פרוטוקול שמאפשר לclient גישה לקבצים ברשת כמו local storage, וגם מאפשר PERSISTENT VOLUMES
CSI: זה הINTERAFCE או
של הSTORAGE
בקוברנטיס
עבור
הקונטיינרים. Container storage interface,
בעלת יכולת SCALING>STORAGE דינמי.
לדוגמא-
כשפותחים STORAGE CLASS חדש
הCSI
מתקשר עם
הגדרת הCLAIM
שנקבע בPVC
ומתעל את הSTORAGE CLASS אל הVOLUME.
והCSI גם יהיה אחראי להעלות את הVOLUME לאיזה NODE ולהוריד אותו שאין צורך בו.
NFS יכול
לעבוד ללא CSI, אבל
הSTORAGE לא יהיה
דינמי.
ארכיטקטורה
בסיסית:
דאגת
HIGHLY AVAILABLE: מאחר
ויש מספר
קומפוננטות ל MASTER(SCHEDULER CONTROLLER MANAGER API SERVER)
אז ככל שיהיו
יותר זמינים
כך
הקלאסטר יהיה
פחות בעומס ובHA.
לפחות 3 MASTER. הCONTROLLER
MANAGER והSCHEDULER
מאפשר הצבעה
על
מי המנהיג,
ולכן צריך
שיהיה מספר אי
זוגי, כדי שלא
יהיה תיקו. הNODE
של המאסטרים
שהם לא המנהיג
הם במצב של
STANDBY עד ובמידה המנהיג נפל והם צריכים להחליף אותו.
Services
in k8s:
SERVICES
זה מה שמאפשר
גישה מבחוץ,
או מדיניות של
גישה באופן
כללי
לקונטיינרים/פודים. לדוגמא
ASSIGN
של IP
או של DNS
לפוד.
סוגים-
NODEPORT:
נותן
גישה מבחוץ
אבל רק דרך PORT. עובד
בפורט סטאטי,
מפנה TRAFFIC
לא משנה מאיזה
NODE.
אין
דינמיות וללא LOAD BALANCING CAPABILITIES
LOADBALANCER:
מספק
תמיכת LOAD
BALANCE חיצוני
דרך CLOUD
ומפנה את
התנועה בהתאם.
בא גם עם
בדיקות HEALTH,
SSL וAUTOMATIC SCALING
ClusterIP: עובד
רק עבור
הקלאסטר-לא
יוצא החוצה.
אין גישה
מבחוץ. הקצאה
של IP קבוע
ויציב לPOD.
בד"כ גם
משוייך לזה DNS
Headless: ללא הקצאת IP , מקובל בשימוש בDB כדי להפוך את הגישה לחסויה יותר-שאין גישה מבחוץ(HEADLESS קיים בSTATEFUL SET)
PERSISTENT VOLUMES
למה?
כי
לדוגמא פרשנו LOCAL STORAGE בNODE1 אבל
הNODE
הזה נפל,
ועכשיו אין
לנו את VOLUME
כי הNODE
נפל, ולכאן
מגיע PV
שמרים בNODE
אחר למקרה
שאחד נופל.
בענן
יש כבר מוכן:EBS לAWS, google disk או azure disk כדי
לשמר DATA/VOLUME
מה
זה?
יצירת
ווליומים
באמצעות SERVER של NFS(ראה
טקסט התקנה)
שמאפשרים
חלוקת VOLUME בתוך
הCLUSTER
מכל מקום(LOCAL או CLOUD)
PVC- persistent volume claim מה
שאחראי על
שחזור
ווליומים, אם
אחד נופל או נכשל
או נמחק, הCLAIM משחזר. אבל
אם נמחוק את הCLAIM
הVOLUME יעלם
NFS SERVER –
service שמאפשר MOUNT של וויליומים בצורת PERSISTENT. ONPREMISE במקרה של ההתקנה הזו.
למה?
כי
מאפשר VOLUME
בין פודים
שיקחו ממנו
בלי קשר באיזה
NODE הם
נמצאים/SHARED
STORAGE
מורכב כservice בקוברנטיס דרך YAML ברכיבים הבאים:
RBAC: Role BasedAccessControl.
מקצה תפקידי
הרשאות.
Provisioner: מה
שמקצה את
הנתיב של הMOUNT
ואיזה SERVER NFS
לעבוד(לדוגמא)
SC: STORAGE CLASS
ההגדרה
ויצירתו.
PV נשלט על
ידי הCONTROLER
שפונה לSTORAGE
CLASS כדי
להקצות VOLUMEים. אם
לא מצוין SC הוא פונה לDEFAULT, לכן
יש לוודא שהSC שלך
הוא אכן DEFAULT.
Volumes טובים שרוצים לחלוק שטחי אחסון בCLUSTER בין כל הפודים והקונטיינרים, מה שלא מתאפשר ברק פודים שזה סביבה סגורה.
מכניסים
volumeMounts:
עם – name: ואת
השם של הPVC
בתור הCLAIM שצריך
להשתמש בו. זה
בבלוק של הDEPLOYMENT – זה
במצב שעובדים
עם NFS
ולהוסיף
גם שורת mount:
עם הנתיב הרלוונטי
המקומי שבתוך
הקונטיינר
סוגי VOLUME:
רפרנסים:
הPV
לוקח רפרנס מהSC כדי לדעת
מאיפה לקחת STORAGE קבוע, הPVC זה רק הCLAIM שמאפשר
התאוששות.
והוא ללא
הפניה לSC.
הPV
תמיד לוקח
רפרנס מPVC
לגבי הכמות
לפי השם של הPVC.
רק אחרי
שיש לך Storage Class
אתה יכול
"לתבוע" אותו
עם הPVC,
ואז יהיה לך
התמדה/PERSISTENT
דרך הPV.
REPLICASET
מה
שמוודא שמספר
ספציפי של POD או
שכפול שלהם (REPLICA)
תמיד רץ בכל
זמן
בקוברנטיס.
גם
מחליף
אוטומטית
פודים
שנפלו/הושמדו/נמחקו
לא
אחראי על SCALING
מומלץ
להפעיל DEPLOYMNET
ולא להשתמש
בצורה ישירה בREPLICASET, כי DEPLOYMENT נותן
יותר יכולות
ושימוש טוב
יותר בREPLICASET.
וגם
מפעיל בעצמו REPLICASET
תחת RS יש לנו למעשה גרסאות קודמות. אבל DEPLOYMENT מפעיל גם פוד וגם RS.
ואז אפשר לעשות ROLLBACK
הבלוק
של TEMPLATE
הוא הכרחי בRS
kubectl rollout history deployment/<deployment-name>
kubectl rollout undo deployment/<deployment-name> --to-revision=1
sequence of events in case of creating a ReplicaSet
DAEMONSET
בברירת
מחדל פורס
פודים על כל הNODE
האפשריים,
כוללהMASTER.
ניתן לקנפג
להקצאה
ספציפית של NODE.
STATEFULSETS (STS)
למה?
במצב
שלדוגמא MYSQL עובד בתוך
קלאסטר של
עצמו- ויש פוד
ראשי נניח מספר
אחד, והשאר
מקשיבים לו
והם משניים.
במצב כזה המיספור והשם ה*לא* ג'נרי – משמעותי.
כי
ככה
לאפליקציה
שעובדת בצורה
קבועה עם פוד ספציפיים
ברשת שלה,
תמיד תעבוד עם
אותם שמות.
בדומה
לרשת של COMPOSE(שניגשים
לאותו שם קבוע
שהקצנו
לקונטיינר ברשת)
אבל
לקוברנטיס יש
את האפשרות
להרים מחדש את
הפוד שנפל עם
אותו השם.
מה
זה?
הקצאות
משאבים על פי
שם, למרות
שהשם נשאר יש
הפרדה לוגית בPODS.
שומר על
סדר(טכנולוגיות
METALLB וINGRESS)
-מה
ההבדל בין DEPLOYMENT? השם
ג'נרי ואקראי.
הSTATEFULSET גם מייצר פודים אבל בשונה מהDEPLOYMENT הוא מייצר משאב אחר, ואז הפודים גם ממוספרים.
STATEFUL –
אומר שהוא
שומר את הSESSION DATA, לעומת STATELESS שזה
ללא. המספור
מאפשר להנגיש
על ידי REPLICA
SET במידה
ונניח מספר 0
נופל הוא הולך
ל-1 וכולי.
נניח במצבים שבהם הDB קורס. עובד עם HEADLESS SERVICE.
עוד הגדרה: פודים מיוחדים(לא דיפלוימנט) שיש להם STATE מסוים וקבוע למטרת :"רכילות" בין הפודים באותה מערכת של קונטיינרים .
TOPOLOGY CONSTRAINTS VS Affinity,
Anti-Affinity
הגדרת
פוד, שמאפשרת
פריסה לפי NODE, או LABELS
אחרים, בדומה
לNODE AFFINITY
אבל יותר
ייעודי
לסוגים
משתנים או
ייחודיים של
פריסות.
נניח
לפי אותו AZ, או לפי
אותו שם. לפי
הגדרות ה TOPOLOGY
שמתקיימות
כנראה בLABELS
בד"כ.
spec:
# Configure a topology spread
constraint
topologySpreadConstraints:
- maxSkew:
<integer> degree in which pods may be unevenly distributed. According to when Unsatisfiable.
לדוגמא 2
יכול
לתת כאלה
פריסות:
או:
או אידאלי: 4/4/4
minDomains:
<integer> # minimum number of eligible
domains. maxSkew will zero if matching pods
not meeting req. Topology<if Unsatisfiable, if schedule anyway it will give precedence
to topologies which reduce the skew.
topologyKey:
<string> according to which hostname/zone
whenUnsatisfiable:
<string> DoNotSchedule or SecheduleAnyway
labelSelector:
<object> uses key value matches from labels of node
matchLabelKeys:
<list> # optional; beta since v1.27
nodeAffinityPolicy:
[Honor|Ignore] # optional; beta since v1.26
nodeTaintsPolicy:
[Honor|Ignore] # optional; beta since v1.26
### other Pod fields go here
מה
זה TOPOLOGY KEY?
topology.kubernetes.io/zone: Pods will
be scheduled in the same zone as a Pod that matches the expression. כלומר
ינסה לפרוס
בצורה שווה על
פי הטופולוגיה
של כל אזור.
-לדוגמא אם יש 2
אזורים, אז יפרוס
כמה שיותר
שווה על
שניהם. שלושה,
ארבעה וכולי.
kubernetes.io/hostname: Pods will be scheduled on the same hostname as
a Pod that matches the expression. ינסה
לפרוס בצורה
שווה לפי כל DOMAIN או
שם HOST, אם
לכל NODE יש
שם אחר, אז הוא
יפרוס על כל
שם בצורה שווה
ככל האפשר.
podAntiAffinity - היא
הגדרה
שמונעות מPOD להתקיים
על NODE
מסוים.
podAffinity - כופה על POD
להתקיים ב NODE ספציפי.
apiVersion: v1
kind: Pod
metadata:
name: with-pod-affinity
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: security
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
containers:
- name: with-pod-affinity
image:
docker.io/ocpqe/hello-pod
labelSelector - עם MATCH EXPRESSION מחייב
ביטויי שיש בו
מפתח KEY בעל
ערך VALUE
ספציפי, וכך
ניתן להבטיח
סלקציה של POD ל NODE
עם KEY VALUE
ספציפיים,
שמתבטאים בLABEL של
כל NODE
טיפול
SCALING
TOPOLOGY SPREAD CONSTRAINTS –
יכול לאפשר
דברים שאין בAFFINITY, או
באנטי, כי אם
לדוגמא נעלם
לנו NODE,
ואמורים
להיפרס לנו 2
פודים, אז ב AFFINITY או
אנטי, רק 1 יפרס.
ובSPREAD
יפרס לנו 2 על ה NODE
שעובד.
Pod topology MUST BE UNDER TEMPLATE.SPEC if patched into deployment, because its pod level definitions and not deployments definitions.
AUTOSCALER-HPA
Horizontal Pod Autoscaler-
יתמרן משאבים
בהתאם
לדרישות QUOTA כולל
להוריד פוד או
להרים, בצורה
אוטמטית. לדוגמא
אם CPU USAGE נהיה
עומס-הוא
יוריד משאבים.
Scale out- שייך לhorizontal autoscaler שבו
מנפיקים עוד
פודים
ומשאבים, ללא
הגדלה פיזית
Scale in
– גם לHPA
-הורדה של
משאבים.
Vertical Autoscaling
ירים משאבים
"פיזיים"
נוספים,
לדוגמא מכונות/NODE.
Scale UP –
שייך לvertical autoscaler
שזה בעצם מה
שהוא עושה.
פקודותKUBERNETES-
Kubectl get pods -o wide :
יציג לנו
פירוט יותר,
באיזה NODE
מותקן איזה POD
Kubectl get nodes -o wide:
יותר פירוט- IP , מע'
הפעלה ועוד.
פריסה של
APP בWORKER גם
תפרס בMASTER וגם בWORKER
אחרים.
Kubectl describe service hello-service.yaml
Kubectl get deploy:
מציג את
האפליקציות
שפרשנו
Kubectl delete deploy <app name>:
הסרה של APP
ממצב DEPLOY-
לא משחזר!
יצירת
STORAGE CLASS:
ראה SCRIPT
Kubectl get sc : מציג
את הSTORAGE CLASS
הקיים שלי
Kubectl get pv : אחרי
שייצרנו PVC זה מציג
מידע עליו(PERSISTENT VOLUME)
Kubectl get pvc
:
מציג עבור
שימוש/בקשות לSTORAGE מהאפליקציה PERSISTENT
VOLUME CLAIM
Kubectl delete -f <svc or pod or deploy>
מוחק כאלה שיש
הרבה SVC בבת
אחת במקום אחד
אחד
Kubectl scale replica:3 : משנים
את הסקלזיציה
של הרפליקות
Kubectl get rs : מביא replicaset
Kubectl get pods -n myspace : מציג
פודים של namespace המצוין
Kubectl get sc-
מציג storage class
כשיש.
Kubectl get roles –
מציג את
התפקידים,
חלקם של
ההרשאות של RBAC
Kubectl get sts –
מציג מצב STATEFULSETS
Kubectl config get-contexts :
אומר מול מי
אני עובד(נניח
בתוך WINDOWS
רואים שזה MINKIKUBE)
Kubectl config view:
מציג את הSETUP של הCLUSTER
Kubectl top nodes : נותן
כמו TOP
מצב המעבדים
והעומס בNODES >>> דורש METRICS SERVER עבור הNODES
Kubectl config use-context <name of cluster> : to switch clusters
איחוד
של CONFIG
של WINDOWS כדי
שיהיה אפשר
לעבוד מרחוק
על הCLUSTER,
ללא צורך
להתחבר
למכונות.
KUBECONFIG=~/.kube/config:~/.kube/kubeadm.conf
kubectl config view –merge –flatten :
פקודת איחוד
של כל הCONFIG
גם של הWINDOWS
וגם של מה שיש
לנו בCLUSTER של
VM BOX
kubectl config use-context
kubernetes-admin@kubernetes:
לבחור קלאסטר
ספציפי מאלו
שמותקנים
kubectl get events -w:
עושה TAIL
לEVENTS
kubectl api-resources: מראה
את המשאבים
והאופרטורים
של הCLUSTER
kubectl get all
:
מציג את כל
הדברים
שהותקנו בCLUSTER, PVC, HPA, SVC, PODS, DEPLOY
וכולי
kubectl top : צריך להתקין METRICS – מראה בריאות ומה רץ, כמו בלינוקס
kubectl get ingressclass : מציג
איזה CLASS
הINGRESS
של הקלאסטר,
יכול להיות ALB של AWS, או NGINX.
Kubectl get servicemonitor -n monitoring: במידה ויש OPERATOR יש CRD שאפשר לקבל עליהם נתונים, כמו kubectl get promethuesrule
kubectl get nodes -w:
עושה TAIL לNODES,
מעדכן שיש
שינוי.
Kubectl api-resources : מציג
את כל המשאבים
עם התפקידים
והתקציר שלהם
בקלאסטר.
kubectl scale deployments/my-deployment --replicas=4 : מוסיף
או מחסיר REPLICA כמה
שנרצה -אפשר
גם לPOD או כל
דבר
kubectl delete pod <pod name> --force --grace-period=0
kubectl patch deployment –set-file patch-secret -n argocd מוסיף עדכון לDEPLOYMENT קיים, מבלי להרוס את הישן. PATCH.
kubectl get roles -n argocd
מציג את כל הROLE, הROLE הוא
מה מותר לעשות
על המשאב שבNAMESPACE.
לדוגמא READ
ONLY. מיועד
לעבודה מול NAMESPACE
יחיד.
kubectl describe clusterrole
<clusterrole-name>
אותו דבר כמו ROLE אבל
מתפרש על כל ה NODE
שבקלאסטר.
ועובד על כל ה NAMESPACEים!
kubectl get rolebinding מראה את הקשר/קישור בין המשאב למשתמש או קבוצה.
kubectl get clusterrolebindings- אותו דבר רק מתפרש על כל הקלאסטר. ועל כל הNAMESPACEים.
kubectl get crds מציג
את על מה יש CREDENTIALS
kubectl get all -n argocd: נותן את כל הRESOURCES תחת ה NS הזה
kubectl port-forward <name of service> -n
<namespace> <host port>:<container port> : מאפשר
כניסה לפוד
דרך השירות
שלו SERVICE
kubectl port-forward svc/argocd-server -n argocd 8080:80
הגישה תהיה דרך localhost:8080
kubectl rollout restart deployment
argocd-dex-server -n argocd מרענן את
הקונטיינר אם
שיננו לו
הגדרות ולא נתפסו
kubectl
get componentstatus- מציג את
הבריאות
ושגיאות אם יש
של רכיבי המאסטר
kubectl get nodes -o json : dsiplays in json format
kubectl get pods -o yaml: displays pods in yaml format(just the list, not the deployment)
kubectl run my-pod --image=nginx:alpine מרים פוד של אנג'ין איקס.
Kubectl get pods -l env=prod מציג
את כל הפודים
עם הלייבל הזה
kubectl scale deployment pluck --replicas=5 עושה
סקייל ידנית,
זה טוב גם
לבדיקת עומס
kubectl get ep <name> :
list the endpoints of a certain app
kubectl auth can-i '*' '*' –
בודק אם יש
למשתמש שכותב
את הפקודה
הזו, יש הרשאות
לכל הפעולות
בקלאסטר
קיצורי
דרך:
in your .bashrc file:
# Set an
alias for the production context
alias kc='kubectl config use-context $1'
in cli run:
kc <namespace name>
kubectl
get cm <name of config map>
kubectl get cm config-map -n staging -o yaml | yq e 'del(.metadata.annotations)' : יציג כמו קובץ שנכתב בידי אדם, ללא רפרנס של קוברנטיס.
Kubectl describe pod <name of pod>
Kubectl logs pod <pod name>
Systemctl status kubelet:
מראה גם על
שגיאות
שיכולות
להיות קשורות
בפריסת
קונטיינר
Journalctl -u kubelete
Kubectl get clusterroles :
מציג את כל
ההשמות
תפקידים בCLUSTER
Kubectl logs -n <namespace> <name of
pod> - מציג לוג
של הפוד ביחס
לNAMESPACE
שלו
ALWAYS השמד
פודים או כל
דבר אחר
שנתקע. לעיתים
זה רק בעיות
משאבים או
סתירות אחרות.
Kubectl describe nodes :
מציג מצב
בריאות כללי
של כל
הקומפננטות
של בNODES
Kubectl get events
: מציג LOG של
הצלחות
כשלונות/פעולות
שנעשו בDASHBOARD
Kubectl get pods -n kube-system:
מציג את רשימת
הרכיבים של
הקוברננטיס
kubectl logs -n kube-system <name of ku8s
component from list above>
לבדוק
אם לא מצליח
לעשות BIND
או ליצור PV, לוודא שהSC אכן
נחשב כDEFAULT
שצריך לפנות
אליו כדי ליצר
ולהשתמש בו.אם
לא:
kubectl patch storageclass nfs-client -p
'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
הפקודה
לעיל מסדרת שהSC
הספציפי NFS-CLIENT יהיה הDEFAULT.
kubectl get nodes -v=10:
מציג פירוט
אדיר – מצוין
לINSTALLATIONS VERBOUSE scaling
journalctl -u kubelet -o cat :
מציג בצורה
מסודרת יותר
את הלוג
curl -vv <ip address or domain> : מציג
פירוט נרחב של
השגיאות אם יש
kuectl get endpoints nginx מביא את רשימת הEND POINTS IP עבור שירות שנבחר
kubectl exec לפעמים לא
עובד על GITBASH
בWINDOWS
על BIN BASH,
צריך להוסיף DOUBLE SLASH:
kubectl exec -it
core-web-67f5c9bbf-kvs6r -n staging -- ls //bin/sh
^ לעיתים אין BASH בכלל, ואז גם לשים לב שזה עובד רק בלי סמן כמו root> , לא קיים כלום, רק סמן ללא אינדקציה.
Flannel
Required to allow communication between pods and nodes in the cluster.
התקנה
פשוטה, לא
תומך ב NETWORK
POLICIES, ומסרבל
ואולי מעמיס
על שליטה
במספר רשתות,
בגלל שיש לו DAEMON לכל NETWORK,
במקום DAEMON אחד
שחולש על הכל.
Calico = flannelאבל עם יתרונות חסרונות אחרים
Pod Communications
בין הNODES ובין עצמם, למעשה ללא NAT(שזה תרגום של כמה כתובות תחת כתובת אחת חיצונית),
אלא
שלכל פוד וNODE יש
כתובת משלה. Internally
– NO NAT. כדי
שיוכלו לדבר
אחד עם השני.
למעשה
זהו הכלל שהם
חייבים לתקשר
ללא NAT.
MetalLB( מטאל LB)
טוב
למצבים ללא CLOUD/on premise. מנתב
בקשות IP
של ARP(address resolution control)
ומפרסם את
כתובת הMAC
של אחד הWORKER NODE.
TRAFFIC
מנותב,
והקוברנטיס
מנתב אותו לPOD
הנכון.
עובד
ב2LAYER (של
מודל הOSI)
בעל
2 COMPONENTS:
controller pod-
speaker
pod-
בקצרה
– מנפיק כתובת
-עובד בשכבה 4.
. אפשר גם ליצור LB סרביס לכל אפליקציה שתאפשר כניסה מבחוץ. הMETALLB ינפיק לנו כתובת IP -שונה- לכל LB שנקבע, מתוך הPOOL שהגדרנו לו בCONFIG-MAP
MetaLB
אחד הMODEים
שלו הוא LAYER2,
או BGP:
BGP: Border Gateway Protocol, in a cluster context, of metaLB, it’s a mode(not layer2 mode) it uses BGP to advertise IP addresses
Assigned to LoadBalancer type, so that for example it can expose MULTIPLE services, instead of working
With just one load balancer per service. Because it assigns IP per service.
RESOURCE QUOTA/OBJECT QUOTAS
Object Quota:
הגדרת כמות
משאבים פר NAMESPACE.
Resource quota
הגדרת
משאבים כמו CPU MEMORY עבור RESOURCE QUOTA
או
פודים,
אינגרס, משאבי
קוברנטיס
כדבעי כ-OBJECT
QUOTA
למה?
במצב
שיש כמה
צוותים
שעובדים על
קלאסטר, שלא יגזלו
משאבים יותר
מדי ויגרמו
לעומס בלתי סביר.
ולכן ישנה
הקצאה מוגדרת
דוגמא:
אם
מגדירים 200m בQUOTA, אז
אנחנו דורשים
20% עבור CPU
אחד, או 10% עבור 2 CPU, לכל POD. זה
באופן כללי
לפוד אחד.
אם 400m אז זה אומר 40% עבור מעבד אחד או חצי מזה עבור 2 מעבדים פר פוד.
Example script Resource quotas
INGRESS
מאפשר כניסה מהOUTSIDE WORLD, עובד בשכבה 7, ברמת האפליקציה. ניתן להוסיף אותו כRULE לתוך SPECS ולהגדיר גם DNS ZONE שיעבוד לפי הINGRESS.
מה
עושה הINGRESS?
למעשה
כל POD
שנחשוף עם SERVICE לא
מספיק לנו כדי
שנעשו להפניה
מDOMAIN(למרות
שבטח יש עוד
דרך לזה), INGRESS
מספק הפניה
ראה
הגדרת HOST
בYAML,
ומשם לאן
אנחנו מפנים.
ההפניה היא לSERVICE
פנימי של
הקלאסטר. וכך
האינגרס מפנה
בקשה לDOMAIN ספציפי
לתוך הקלאסטר
שלנו.
דרוש
IP
חיצוני שMETALLB מנפיק כדי
לתקשר. .
על
כל אפליקציה
נריץ INGRESS שיתפקד
לפי הIP שMETALLB
הנפיק לנו
סוגים - nginx, Traefik, Contour
חייב
להעביר איזה SECRET לINGRESS שיקבל
הרשאה לתקשר.
לדוגמא TLS,
spec:
tls:
- hosts:
- some_app.com
secretName:
someapp-secret-tls
בדוגמא לעיל, לשים לב לבלוק של RULES, שקובע איזה פרוטוקל(HTTP או HTTPS) איזה PATH, וגם הגדרת הBACKEND ,
Contour
הוא המתחוכם
יותר, משתיל ENVOY
ובעל הרבה
פונקציות ראה k8s-3
במצגות.
Traefik בעל יכולת של CANARY שיכול לתעל חלק מהתעבורת INGRESS לCANARY(שזה סימולצית אפליקציה שעוברת עדכון, לפני הפריסה שלה).
Ambassador
זה גם INGRESS
טוב
לקוברנטיס,
נתמך
במניפסטים-קל
להתקנה. גם
בעל ENVOY
ISTIO-
כנראה שעם הכי
הרבה
פונקציות
והכי מקיף.
וגם בעל ENVOY
משלו. ממש
מאפשר SERVICE
MESH ושליטה
הרבה יותר
מקיפה על
התעבורה, וגם
VISIBILITY גבוה.
METRICS SERVER
נותן
סטטיסטיקות
במיוחד דרך:
kubectl top nodes
ורכיב
הכרחי לAUTOSCALER
TAINTING NODES
- TAINT מצב שבו
אנחנו מזהמים NODE
ספציפי כדי
שקוברנטיס
ידע לא לפרוש
עליו, אבל
נוכל נניח
להגיד לDEPLOYMENT
אחר שיש לו TOLERATE כן
להפרש. לדוגמא
במצב שיש
קלאסטר אחד לSTG וגם
ל PROD.
דוגמא:
apiVersion:
apps/v1
kind:
Deployment
metadata:
name: my-app
spec:
template:
spec:
tolerations:
- key:
"key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
ה NOSCHEDULE אומר לקוברנטיס לפרוש שם. זה משהו שצריך להיות קיים בהגדרה של הTAINT. לדוגמא KEY: staging value: true .
ROLLING UPDATE
מצב
שבו אין DOWNTIME
למרות שאנחנו
מרימים מחדש
פוד שעודכן.
וגם מאפשר ROLLBACK לגרסא קודמת.
HAPROXY
loadBalancer that supplies external IP for the whole cluster. And can also provide stats using browser access.
יכול
לגלות אם נפל
מאסטר NODE ואז
להחליף אותו
אם קיימים
אחרים ובכך
לשמור על HA.
OpenEBS, GlusterFS
Thin provisioning עם
אופציות
נרחבות – SNAPSHOTS, DATA REPLICATION,
הגנות,
סקליזציה. FILE BASED STORAGE(GLUSTERFS(
CHARTS:
מאפשר פרישה
של כמה DEPLOYMENTS
בבת אחת בקובץ
אחד שינוהל על
ידי HELM
CRD
Costume resource definition
ISTIO
מספק
ניטור ושליטה
במיקרוסרבסים
באמצעות ENVOY או SIDECAR
שמנפיקים TLS
שאיתם
האפליקציות
יכולולת לדבר
עם הפודים ללא
שינויי
באפליקציה
עצמה.
יש
לו 3
רכיבי(שבד"כ
פורשים בHELM) BASE, ISTIOD, GATEWAY.
הISTIO משתמש בINJECTOR שנותן
את הניטור,
ובעזרתו
מייצר את הSIDECAR שזה
בעצם
קונטיינר
נלווה לכל SVC
שנבחר.
עושים
זאת על ידי
שינויי בDEPLOYMENT עם LABEL על פי NAMESPACE.
כלומרISTIO יזריק SIDECAR לכל
המשאבים של הNS
שעשינו לו LABEL.
וכך שנראה פריסה של פודים נראה כפילויות כאילו יש לו 2 REPLICA, אבל זה בעצם התוספת של הSIDECAR.
הENVOY מתפקד, בין
השאר, כLOAD
BALANCER במידה ויש
המון בקשות לMICROSERVICES,
ובכך מאפשר HA.
וגם
הPROXY
שלו ניתן
לקינפוג. בין
השאר. יש לו
בדיקות בריאות
ואפשר לקנפג
אותו לגילוי
דינמי של SERVICEים.
KIALI
בשיתוף
עם METRICS
מספק המון
מידע בתצורת DASHBOARD על
הדפדפן. על
בריאות הCLUSTER, התנועה,
מצב כל הCOMPONENTS
של הקלאסטר
ועוד הרבה.
CONFIGMAP
מאפשר
הפרדת
הקונפיגורציות
של
האפליקציות שבתוך
קוברנטיס,
ולזמינות
שלהן בכל
הקלאסטר.
ההגדרות
של
האפליקציות
שמורות תחת CONFIGMAP
ואפשר לשנות
אותן בכל עת,
מבלי להכנס
לאפליקציה
עצמה, וזה מכל
מקום בקלאסטר
ROLLING DEPLOYMENT
BLUE GREEN STRATEGY
מצב שבו יש לנו 2 ישויות של פיתוח/הפקה/הפצה שלמה אחת שהיא ONLINE בחוץ והכחולה נמצאת בשלבי פיתוח תמידיים, וכל פעם מחליפים ביניהם
יתרונות:
אין
DOWNTIME, TEST WHILE PROD, FAST UNDO, RELEASE
צפוי
חסרונות:
יקר פי 2, DATABASE
דורש המון
עבודה ותזמון,
זמן פיתוח
CANARY STRATEGY
מצב
שבו חושפים
עדכון,
ומרימים
יישות חדשה למעט
משתמשים בקנה
מידה קטנה
יחסית.
בד"כ ידני.
בהתקנת
traefik
אפשר להקצות
אחוזים
מהתעבורה של הINGRESS לCANARY כדי
לאפשר
סימולציה של
קנרי בזמן
אמת.
זה
לא אפשרי בNGINX
OPERATOR
מה
זה ?
האפשרות
להרים משאב
שלא קיים
בברירת מחדל
של הקוברנטיס.
האופרטור מלמד את הקוברנטיס להרים משאבים CRD- costume resource definition
דוגמאות
לCRD
זה גם cert manager
שמביא ISSUER
שזה משאב
שיוצר עבור הCERT MANAGER
שלבי
הרמת
אפליקציה:
לוקחים
IMAGE
מרימים DEPLOYMENT
על פי הפורט
והIMAGE
מרימים
SERVICE
שמייצג את הDEPLOY, כדי
שתהיה גישה
לאפליקציה
ואז
INGRESS
שמקשר בין הSERVICE ל LOAD BALANCER-
מוסיפים
בHOSTS
את הIP של הBALANCER. עם
שם
האתר/אפליקציה
שקבענו. כדי
שיהיה אפשר לפנות
מהדפדפן.
הקוברנטיס
יכול להפנות
לאותה כתובת
ואותו פורט, ובזכות
הBALANCER -INGRESS הוא
מנתב לשם
שהגדרנו בSERVICE וב INGRESS.
אפילו
אם יש לנו כמה
אפליקציות על
אותו הIP ואותו
PORT
כל PORTFORWARD שעושים
זה הLOCALHOST 127.0.0.1, שמדבר עם
האפליקציה.
לדוגמא אם
האפליקציה
עובדת ב20001, אז:
Kubectl port-forward svc/kiali 80:20001
80
מייצג את
הפורט שאליו
ננתב את
האפליקציה כדי
לראות אותה
בדפדפן/LOCALHOST
למעשה
PACKAGE MANAGER
מאפשר בניית YAML בבת אחת של הכל – DEPLOY, SERVICE, או כל RESOURCE אחר, באמצעות TEMPLATEים שכתובים בGO.
סוג
של TERRAFORM עבור
קוברנטיס
לכן
אי אפשר לעשות
APPLY
לצ'ארט של HELM.כי הערכים
צריכים להיות
קודם מוגדרים
לכן נוצר הHELM.
למעשה
לוקח DEPLOYMENT
ושם לו משתנים
שאותם אנחנו
נגדיר בקובץ VALUES.
סד"פ:
מעתיקים את הVALUES המקורים
לשם חדש ואז
מגדירים מחדש ערכים
שלנו, בד"כ
שמים בתיקיית TEMPLATE את
הקבצי DEPLOYMENT SERVICE
וכולי
עם כל
המשתנים, ובPARENT את הVALUES עם הCHART,
Helm create <name of folder/app>:
מייצר TEMPLATES
ג'נרים של
צ'ארט. ללא כל
ערכים. זו
התחלה של בניית
צ'ארט
לאפליקציה
מוכנה
helm pull bitnami/redis –untar:
מושך ופותח REPO
לתוך HELM .
Helm ls : מראה
רשימת
אפליקציות
שיוצרו בHELM
helm install my-redis -f my-values.yaml
bitnami/redis :
מתקין
אפליקציה בשם my-redis עם
הערכים בקובץ my-values.yaml
מתוף הREPO
שמצוין בסוף
Helm lint <yaml deployment FOLDER> : עושה
בדיקת SYNTAX
Helm template <yaml>:
עושה בדיקת TEMPLATE-מראה
אם המשאבים
שאמורים
להפרש -אכן
נפרסים.
helm upgrade –install <app name> -f
<folder path>/app-values.yaml -n
<namespace> <path of deployment>
Example:
helm upgrade –install my-app -f application-demo/app-values.yaml -n staging application-demo/.
אני
חושב שהחלק
האחרון- זה שם
הREPO
לא PATH OF DEPLOYMENT
<<
הפקודה הזאת
עובדת טוב
באוטמציה, לכן
לא עושים INSTALL, כי אפשר
תמיד להריץ
אותה.
kubectl describe ingress
my-app-application-demo -n staging : מציג
את הINGRESS
של האפליקציה
ולא את הפוד(?)
פקודות
HELM
helm ls : מראה
התקנות של HELM
Helm repo list
:
מציג רשימת REPO של HELM
helm repo update:
מעדכן אחרי שמשכנו(בהנחה
שמשמכנו)
helm lint <chart name>
בדיקת שגיאות SYNTAX
Helm create <name of folder/app>:
מייצר TEMPLATES
ג'נרים של
צ'ארט. ללא כל
ערכים. זו
התחלה של בניית
צ'ארט
לאפליקציה
מוכנה
Helm template <yaml>:
עושה בדיקת TEMPLATE-מראה
אם המשאבים
שאמורים
להפרש -אכן
נפרסים.
helm upgrade –install my-app -f
application-demo/app-values.yaml -n staging application-demo/. :
מעדכן גרסאת
צ'ראט עם VALUES
חדשים
טוב
לאוטומציה.
ראה סקריפט הסבר עבור שימוש בVALUES על פי פקודות DECLARATIVE של HELM TEMPLATE
Helm pull <url repo> מוריד
את הצ'ארט
למקומי
Helm get values argocd -n argocd נותנים את VALUES לפי הHELM צ'ארט שמותקן כבר בקלאסטר(וחושף KEYS אם לא הותקנו מאובטח).
Helm template -f values.yaml
. (שאתה
במיקום של
הצ'ארט), מראה
איזה דברים
ייפרשו לך בHELM,
מעולה לTROUBLESHOOTING
שרואים
לדוגמא שNGINX לא נפרש,
למרות שENABLED
Helm upgrade <name of repo> -f <file of values> -n <namespace> <name of folder of charts>
Embedding secrets into values
Usually charts values has this key pair:
envFrom
which it means it can take it from a secret or a configmap.
Pay attention to these in charts.
כתיבת
CHART –
פקודות בGO
-range
אומר כמו LOOP,
עובר על
אובייקט
אובייקט מכל
הטווח.
המשתנים
שלפני
מוגדרים כKEY VALUE
ונלקחים מה VALUES,
לדוגמא
{{- range $repo_cred_key, $repo_cred_value := .Values.configs.credentialTemplates }}
המשתנים
בCHART REPO CRED KEY ו REPO CRED VALUE,
יקבלו כל אחד
את הערך שלו
בהתאמה מהKEY VALUE שיש
בVALUES.
TROUBLESHOOTING HELM/K8s
why I can’t uninstall or upgrade my helm chart?
Helm uses secrets called to sh.release.<repo name>.<version number> to manage release versions
If this secret is deleted, the helm chart cannot be upgraded.
Problem of getting connection refused from
pulling images from docker, including busybox.
Attempts to resolve DNS:
Changing the /etc/NetworkManager/NetworkManager.conf
[main]
section:
dns=none
rc-manager=unmanaged
which will not update /etc/resolv.conf and let
me manually resolve dns’s
#
Generated by NetworkManager
#nameserver
2a06:c701:9ee4:d00::1
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
kubectl get events --sort-by
.metadata.creationTimestamp
perhaps a containerd problem:
crictl pull busybox
showed that it expects docker.
I’ve changed the end points socket via:
export CRIO_ENDPOINT=unix:///run/containerd/containerd.sock
and also on the
/etc/systemd/system/multi-user.target.wants/kubelet.service
Add the --container-runtime=containerd flag to
the ExecStart line. The line might look something like this:
javascript
ExecStart=/usr/bin/kubelet
--container-runtime=containerd
WE see that the endpoint for crictl images or
crictl ps -a is always dockershim.sock, so we change
the endpoint of crictl:
export
CONTAINER_RUNTIME_ENDPOINT=unix:///run/containerd/containerd.sock
export
IMAGE_SERVICE_ENDPOINT=unix:///run/containerd/containerd.sock
more
problems:
client
for DHCPv6 was down, so it can’t confirm address via ipv6 protocols.
--probably
not the problem
Unable
to pull images via k8s
Docker hub prevents pulling more than 100
images per six hours.
Check
if docker hub pull limits exceeded:
TOKEN=$(curl
"https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull"
| jq -r .token)
curl --head -H "Authorization: Bearer
$TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest
solution
The coreDNS were deployed on worker nodes-
which didn’t have proper resolv.conf ip’s
After updating them to 8.8.8.8 and 8.8.4.4 they
appear to be working, after restarting all problematic pods
To make networkmanager NOT reset these settings
of resolv.conf:
Vi /etc/NetworkManager/NetworkManager.conf
Add to [main]
Dns=none
How to know cluster is talking with services/apps from the inside?
Kubectl run -it busybox –image=busybox
– bin/sh
And then inside
Wget <name of the service> :<port
number>
Check the file downloaded
TROUBLESHOOTING ISTIO-KIALI
Curl -v localhost or curl -v <ingress ext.ip>
DELETING RESOURCES WITHOUT NAMESPACING
kubectl delete all -n default --selector=app.kubernetes.io/part-of=argocd
explanation on deployment.yaml
spec>replicaset:1/selector>matchLabels>app:helloworld
חובה כדי לSELECT לDEPLOYMENT מה
לנהל.
template>labels>app: helloworld
problem: ingress doesn’t deploy even after enabled in helm(argocd example)
kubectl get networkpolicies --all-namespaces
ייתכן שישנן
מידניות
שחוסמות
ייצירת המשאב של
INGRESS
Ingress Controller
Listens to ourside and decides what comes
in. (ingress – inbound connection)
Suppose you have a Kubernetes cluster, and you've deployed
two web applications: app1
and app2
. You want to make these applications accessible from the internet. app1
should be accessible at http://www.example.com/app1
and app2
at http://www.example.com/app2
.
1.
Deploy
Applications: You deploy app1
and app2
in
your cluster, each running in its own set of pods.
2.
Create
Services: You create a Kubernetes Service for
each application. These Services are of type ClusterIP
(default type), which
means they are only reachable within the cluster.
1. Deploy Ingress Controller: You deploy an Ingress Controller in your cluster (e.g., NGINX Ingress Controller). The Ingress Controller will listen for incoming HTTP requests.
2. Create an Ingress Resource: You define an Ingress resource with rules for how traffic should be routed to your services.
yaml
2.
apiVersion:
networking.k8s.io/v1
3.
kind:
Ingress
4.
metadata:
5.
name:
example-ingress
6.
spec:
7.
rules:
8.
-
host:
www.example.com
9.
http:
10.
paths:
11.
-
path:
/app1
12.
pathType:
Prefix
13.
backend:
14.
service:
15.
name:
app1-service
16.
port:
17.
number:
80
18.
-
path:
/app2
19.
pathType:
Prefix
20.
backend:
21.
service:
22.
name:
app2-service
23.
port:
24.
number:
80
25. This Ingress resource tells the Ingress
Controller to route traffic based on the URL path: requests to /app1
go
to app1-service
, and requests to /app2
go to app2-service
.
1. Load Balancer: Your cloud provider assigns a public IP address to the Ingress Controller through a Load Balancer service. This Load Balancer is what makes the Ingress Controller accessible from the internet.
2.
DNS
Configuration: You configure a DNS record for www.example.com
to point to the public IP address of the Load Balancer.
· When a user navigates to http://www.example.com/app1
, the DNS resolves www.example.com
to the Load Balancer's IP, which forwards the request to the
Ingress Controller. The Ingress Controller then routes the request to app1
based
on the defined Ingress rules.
· Similarly, a request to http://www.example.com/app2
is routed to app2
.
In this example, the Ingress Controller and its rules
define how traffic to www.example.com/app1
and www.example.com/app2
is managed. The actual public exposure and IP address come from the
Load Balancer provided by the cloud platform. The Ingress itself doesn’t
provide the public IP but orchestrates the traffic flow based on the URL paths.
Properties: on-demand, broad
network access, rapid elasticity, measured service, resource pooling
Without
these properties- they can’t be called cloud, but “cloud
carriers”/ex. Nimbus
Cloud
brokers aren’t cloud. Ex. Cloud zone automatic.
3
kinds of cloud like: cloud
carrier, cloud consumer(us), cloud broker
service models:
IaaS:
Infra stracture as service, allows to create
machines and all the modern cloud computing. AWS, AZURE, ORACLE, GOOGLE CLOUD
COMPUTING
PaaS:
platform as service, google as ex. Allowing to run
codes on their servers
SaaS: software as service.ex:pay per seat. Ex2:salesforce:service is
closed env. Can’t be customized.
Differences:
Paas you bring the
code, you pay what you run
SaaS: the provider is responsible, for the health of
cloud+applications+data
IaaS: 90% is on the client
Deployment Model:
Private cloud(real one): only the client has it, VMware, private
completely, costs millions. Only I can manage it.sometimes
banks consume private cloud.
Public
Cloud(most clouds are): azure, google, amazon, IBM,
VMware. That the public can go in.
Maintaining private cloud is not just IT, mostly software and more than devops.
Community Cloud: NIMBUS, github uses this cloud.
Hybrid cloud: Azure, you have active directory, disaster recorvery. Public+ private
But very expensive.
Aws=used by devops and developer
Azure=used by IT
Simple reference:
Public= credit card number
Private= 6-10 million NIS
Elastic computing
can
automatically create servers, 500 for example, without real person involved.
All automatic
Regions
and Availability Zones:
Regions: כמו US-west או euro-frankfurt
AZ(availability zones): Data Centers in the region. Which have DR(disaster
recovery), and to allow HA for servers
COMPONENTS:
IAM:identity access management
כל
מה שקשור
להרשאות, USERS, POLICES, ROLES.
3S: SIMPLE STORAGE
SERVICE, בחירה של GP(GENERAL PURPOSE) או
מהירים יותר
2EC: ELASTIC CLOUD COMPUTING,
יצירת הINSTANCE
להקמת מכונה.
כל
הוירטואליזציה.
SECURITY GROUPS:
סוג של FIREWALL
VPC: virtual private cloud, מה
שמאפשר IP
חיצוני. וגם
רשתות
פנימיות.
מאפשר NAT(network address translation).
בזכות הROUTE
TABLES.
לא
עולה כסף, VPN עולה .
למעשה ענן
פרטי שבתוך
הענן הציבורי
בו אני שומר
את המשאבים
שלי.
Elastic Block Storage(EBS)
Not
only online.
Gives
persistent file system for ec2
No
need to be plugged to instance
Can
backup while connected or disconnected from machine
Can
transfer to different AZ or regions
Snapshots
Glacier: very cheap
storage like bucket(0.01 per giga), like backuptapes,
only for emergencies, takes 4-6 hours to use, costs a lot of money to restore
ECS: Elastic container service לא כמו קוברנטיס, יותר כמו דוקר.
ECR: Elastic Container Regitery
בדומה לDOCKERHUB,
REPO של IMAGE/CONTAINERS
ROUTE53:
מאפשר ניתוב DOMAIN NAME מאחד קיים(PUBLIC)
ולהעביר אותו
לשרתי AWS(HOSTED ZONES).
LAMBDA: סקריפט שיכול לרוץ בכל פעם שנפעיל שירות של AWS או ע"פ EVENT, אם זה INSTANCE או אחר
CODE DEPLOY:
מאפשר CONTINUOUS
DEPLOYMENT ע"י
עבודה
אוטמטית עם GITHUB או אחר(אוטמציה
של DEPLOYMENT)
CODE PIPELINE:
בדומה
לג'נקינס, וגם
מאפשר חיבור
לג'נקינס
ELASTIC BEANSTALK: הרמת
סביבת עבודה
בקלות
ובמהירות
למפתחים או QA,
כאפשרות במצב
של עומס עבודה
עבור הרמת
סביבת עבודה
שמרים DEVOPS.
RDS: relational database service
מאפשר מגוון
סוגים של DB בשילוב עם
שירות אמאזון.עובד
רק עם SQL,
מטפל ואחראי
בכל הגיבויי,
סקיילינג,
עדכון ושכפול
של המסד
נתונים.
DynamoDB: מאפשר
גיבויי
ושירותי DB עבור NON SQL.
LOAD BALANCER
סוגים:
ALB: APPLICATION LB. עובד רק HTTP, לא מתאים לSTREAMING, רק WEB REQUESTS. Layer 7, אין UDP.
NLB: NETWORK LOAD BALANCER,
עובד גם על TCP UDP ןTLS
(TCP מאובטח) . HIGH PERFORMANCE,
מתאים לSTREAMING. Layer
4(transport), היחיד
שנותן STATIC IP
GWLB: GATEWAY LB, ?חדש
CLASSIC LB:
גרסא ישנה של
הLB,
כולל בתוכו גם
HTTP וגם TCP,
אמזון פחות
מעדיפה
שנתשמש.
IAM
יצירת
ROLE : IAM>ROLES>
אפשרות
לייצור AGENT
של
SSM
שמאפשר גישת ADMIN
למכונה ללא SSH
וללא SG.
רק באמצעות הROLE
2EC
פתיחת
LB:
עבור
LISTENER
פותחים 80 או 8080 TCP, אם
אנחנו בNETWORK
LB.
80
זה HTTP,
אבל TCP 8080
זה לא.
המכונות
חייבות לרשום
בדיקת
LB:
לוחצים על DNS NAME RECORD COPY
TARGET GROUPS
חייבים
לרשום את הINSTANCES לTARGET GROUP
אחרת הוא לא
יפעיל עליהן LOAD BALANCER
TARGET GROUP יכול
לקבל רק
פרוטוקול אחד-
במקרה של PORT -רק
פורט יחיד. כך
שצריך עוד TG כדי
להביא עוד
פורטים.
ELASTIC IP
נותן
כתובת
חיצונית(באינטרנט)
לINSTANCE שלי.
מגיע לי אחד
חינם על כל
מכונה, אם רוצים
יותר אז זה
עולה כסף.עד
5-ומעבר לזה
צריך לבקש
מהתמיכת
אמאזון. זה
נקרא ELASTIC
כי זה פר שעה
ולא לחודש.
משתמשים בALLOCATE כדי
לשייך לINSTANCE
PLACEMENT GROUP
אם
נרצה
שהמכונות
ישבו קרוב אחד
לשני. כלומר 2 מכונות
שיושבות תחת
אותו PLACEMENT GROUP
מאפשר שיהיו
קרובות פיזית.
זו רמת פיזור
ברמת CLUSTER.
CLUSTER:
שלא יהיה מצב
שהם עוברים ל SWITCH אחר או
מעבירים מידע
דרך נתב.
ואם
נרצה
הפוך-לפזר,
נבחר :SPREAD.
וגם באיזה רמה
-RACK או HOST.
רמת פיזור: PARTITION, אפשר להגיד שכולם ישבו באותן מחיצות.
כדי
לייצר מכונות
שפתוחות
לאינטרנט יש
לעשות את
השלבים הבאים:
מייצרים
אינסטנס,
פותחים LB
שרוצים,
פותחים security
group שמותאם
לפורט של
השירות, נניח NGINX אז
נוסיף INBOUND
ל8080.
מקשרים
בין הSECURITY GROUP
לLB,
פותחים גם TARGET GROUP שבו
מיוצגים
האינסטנסים
שלנו, ואז
מקשרים בLB עם הTG
הרצוי.
כעת
אמורים לראות IP
למכונות. משם אפשר
לפתוח את
המכונות דרך
הכתובת של הLB
פתיחת
SECURITY GROUP
INBOUND RULES:
HTTP אם
צריך
או
TCP מה
שפתחנו.
PORT לפי
האפליקציה/שימוש
ALLOW – אם
נרצה שכולם
ישתמשו מבחוץ
OUTBOUND לא
נוגעים
-חוזרים
לLB
EDIT SECURITY GROUP:
Load Balancer חייב security group – אפשר
לצרף אותו
אח"כ לINSTANCE
יש
לציין ENABLE
PUBHLIC IP ביצירת הINSTANCE
BUCKET
זה מייצר לך
קונטיינר או
מע, הפעלה
שאנחנו בוחרים.
עבור
כל INSTANCE מומלץ
לייצר SECURITY
GROUP.
AUTOSCALING
יצירת AMI:amazon machine
image, מייצרים
קודם כל
רפליקה של
אינסטנס שלו
נרצה לעשות AUTOSCALING-שם
תיוג GOLDEN
AUTOSCALING GROUP,
בוחרים שם
ומוסיפים גם ASG,
שנדע מה זה.
מפעילים
LAUNCH CONFIGURATION
שזה ההגדרות
של (ממליצים
על AUNCH TEMPLATE מבחינת
אמזון)
ובוחרים את הAMI שלי,
בוחרים איזה
מכונה שעבדנו
איתה(לא לשנות
מהקודם עדיף)
משתמשים
באותו SECURITY
GROUP שכבר
אנחנו עובדים
עם האינסטנס
ששכפלנו.
אותו
KEY-
מסיימים LAUNCH CONFIGURATION.
חוזרים
לAUTOSCALING-
בוחרים
LB
קיים. ובוחרים
את מה
שהשתמשנו
למכונה
מאפשרים
V ELASTIC LOADBALANING HEALTH CHECKS
כדי שהLB
יגיד לנו שעבר
הבדיקת
בריאות.
בוחרים
DYNAMIC SCALING (PREDICTIVE לא
הצלחנו) ולפי
רמת העומס
נניח 60% CPU.
User data
:
אפשרות להריץ
סקריפט רק
בפעם הראשונה
שהוא עולה-אם
רוצים שירוץ
כל פעם יש
לסמן שירוץ כל
פעם.
VPC
VPC is Like a local private network
Subnets are the range of ip addresses, and if private or public
We mark private ip’s with single or 2 digits, while public have 3 digits. For example: 10.0.1.0 =private, 10.0.101.0=public
This is to better differentiate when selecting subnet groups or other settings that don’t show public/private
Components:
GATEWAY
-IGW-internet Gateway, via ingress & egress:
מאפשר
אינטרנט לכל
המכונות
- VPG: Virtual Private Gateway-
מאפשר חיבור
לטכנולוגיות
פיירוול
ונתבים כמו
סיסקו
וצ'קפויננט.
-:CGW costumer
GateWay –
איך הראוטר
שלי מיוחצן בAWS
VPN
Direct-Connect:
יקר. מהווה
חיבור ישיר
לאמזון
מהמשרד. מבודד
מהאינטרנט
לחלוטין.
Hardware-Based VPN: גם
יקר מאוד.
Region של VPC מורכב
מPUBLIC subnet, וגם PRIVATE subnet
VPC SECURITY
Security groups:
פיירוול, ingress and egress, stateful: מאפשר
תנועה TRAFFIC
בחזרה.
Access Control Groups: מורכב,
כל דבר צריך
להגדיר.
VPC PEERING:
קישור בין שני
VPC
שונים
ישנה
הכנה אוטמטית
של VPC דרך VPC & MORE
יצירת
VPC ידנית
פותחים
VPC
בלבד, עם נניח
רשת פנימית
שלנו 192.168.0.0/16 כטווח
בCIDR
פותחים
subnet public
, עם כתובת 192.168.101.0
עבור אזור 1a וכל
השאר בהתאמה
(אם יש 3 אזורים)
וגם
private subnet עם כתובת
192.168.1.0/24 וכל
השאר בהתאמה
לפי הREGION
פותחים
IGW)internet gateway( , ומשייכים
אותו דרך ACTIONS לVPC , במקרה
זה הידני-אין
לשייך את הIGW לPRIVATE SUBNETS!!
רואים ייצוג
של PUBLIC בSUBNETS כאשר זה לא PRIVATE.
ROUTE
TABLES
פותחים
ומתחילים
לשייך subnet ע"י EDIT ROUTE. WITH EXPLICIT ASSOCIATION>>PUBLIC שייצרנו
קודם לכן.
לייצר
NAT GATEWAY: בוחרים SUBNET איפה
שיישב הNAT GATEWAY.. לכן זה רק
אחד מה-+PUBLIC ALLOCATE ELASTIC IP
DB זה
דוגמא שאנחנו לא
רוצים שיהיה IP
חיצוני, אלא
רק PRIVATE
המשמעות
של: NAT GATEWAY
נותן לנו את
הכתובות דרכו,
ולא דרך הLB. כדי שמה שPRIVATE
יהיה לו
אפשרות
להעביר כתובת
חיצונית
ללקוח. נניח
אפליקציה בPRIVATE
שתהיה זמינה
ללקוח מבלי
לחשוף את
הכתובת הפרטית
שלו לעולם.
Internet gateway הוא התשתית ו NAT הוא הספק.
איך
לחבר שרתי PRIVATE(
מסאבנט PRIVATE)
לVPC?
יש ליצור:
Aws service> filter type = gateway > assign route table(the private)>create
Make sure the private route tables are connected to vpce
התחברות
לשרתים
פרטיים- לא
ציבוריים!
אפשרויות:
- NAT GATEWAY: עדיף כשהלקוח צריך להכנס לPRIVATE דרך האפליקציה, ולא שום דרך אחרת.
- OPEN VPN: אפשרות שADMIN יכנס לPRIVATE, דבר שלא אפשרי דרך NAT. עולה כסף
- TUNNLING WITH BASTION: כמו OpenVPN, לא עולה כסף(כמו INSTANCE) אבל פחות מאובטח, ראה SCRIPT
BASTION TUTORIAL
https://aws.amazon.com/solutions/implementations/linux-bastion/
command for tunnling bastion.
-use on *local dir* not bastion machine console:
-make sure same key pair is assigned for BOTH the private and the bastion instance!
ssh -o ProxyCommand="ssh -W %h:%p -i ariel-key2.pem ec2-user@13.48.73.84" -i ariel-key2.pem ubuntu@10.0.2.127
what it does is jumping.
connects to the bastion, and then jumps to the private subnet/machine with the same key.(the key that is in the local client)
configuring bastion inside CloudFormation-Stack:
-after using link- make sure on correct region.
- the yaml is the S3 url, that should be automatically pasted from the link. if not- download it, and upload it.
->(next page)apply right VPC, and the right subnet publics, that are related to that vpn.
- 0.0.0.0/0 or your own IP that you connect in "allowed bastion external access CIDR)
- key pair name: just the name of the file of the key in your client machine(local). ariel-key (no file extension)
- bastion banner, TCP forwarding(to allow tunnling), X11 forwarding, all true.
-next page>perserve resources. > apply/mark the box> complete
---
after installing the instance: go to EC2
- goto linuxBastion instance(this is th ebastion instance we created now with CloudFormations),
check the security groups.
- allow in the ec2 instance to connect+update
- connect with ssh -i ariel-key.pem ec2-user@<bastion instance address>
bastion address:51.20.244.25
OPEN VPN TUTORIAL
ec2 instance>launch
select AMI marketplace>marketplace tab>openvpn> free tier only(o fees on desc.)> select>check pricing tabs
edit network:
public IP
enable ip public
Launch
login using ssh but user= openvpnas
in the setting :
yes>eula
yes>stand alone
listen on all network interface>1
rsa
size of cert> 2048
default>rsa, 2048, 943, 443
should client traffic be routed by default through VPN>NO! (if yes-clients can abuse traffic for illegal activity!!)
no-for dns traffic of client
access to private subnet: yes! this is why we put the vpn-to access private servers
user: openvpn
password:
>didnt use activation key> leave blank
DONE
access via the browser on the logs after fininsh installing: example:
Admin UI: https://13.48.127.63:943/admin
because it is risk via browser/shows “risky website warning”, use advanced on the browser> agree to continue
login
in the UI:
can add users for other to use
we will use client ip granted from after the installation.
after login(can be same as admin), we download openvpn access server for windows
download and install
use same user + password
should be running a window of openVPN with network bar/graph
now to connect to private servers
------------------------
make simple windows instance. create password: connect>rdp client>get password>upload pem key>copy password
for windows,
user: administrator
password
now open RDP on your local machine, enter private IP as the host.
----
to connect to mysql checkout MYSQL init
RDS-relational
Database Service
RDS זה DB לכל
דבר שמנפיקים
מאמזון ועולה
כסף. הם
מנהלים את הכל
ודואגים
לעמידות שלו.
עדיף
להתחבר לRDS דרך OPENVPN
מאשר BASTION
יצירה: COSTUME>free tier>save password/db name/user> NO ec2 connection> connectivity:choose VPC>
Before creating DB, create subnet group(under subnet group)>name+desc>all AZ+ip of privates>fiunish
>go back to RDS creation>refresh connectivity>create DB
View
credentials for db password/user
***BEFORE all that must install OPEN VPN.must be running on machine while connecting to private server ***
save password, amster username, db name:
ariel-db
admin
qwerty1234
use mysql workbench(windows) to connect via UI.
click + for new connection setup:
type any name
paste host from amazon endpoint
paste user+password>>store in vault
open connection-use mysql
LAMBDA
Serveless application, like a function. That can manage scalability, use event cases, integration with aws services and have its own script
In javascript or python
Pricing is per usage of the function-which is milliseconds, but if lots of requests can be more costy.
Layers: adding virtual env.
Running/uploading your own code: it includes the dependencies, zipping it all and uploading to S3/upload from computer.
Then lambda can use it.
+add trigger: can use aws services as triggers to execute the lambda function
Test: running it shows the output or log of the function
Lambda Has lambda_handler(event, context) –
the lambda_handler is the name of the function which aws calls to -and it must match the name aws expects.
Event – the data passed to the function once it’s executed. It holds a bunch records in json format as well.
Context – methods to be used to provide information about the execution env.
Read more here
Example1:
לידור
סיפר שעבד
בחברת מדפסות
של תרשימי בניינים.
שרצו להמיר את
המדפסות
למדפסות
חכמות-שניתן
להדפיס בכל
מקום.דרך CLOUD
LAMBDA
סיפקה
פונקציה
שמנטרת אם יש
עומס מתח על
המדפסת אז
שתעצור את
הפעולה שלה
כדי שלא תהרוס
את התוף.
Example2:
אם
נריץ מכונה
שעולה כסף,
נראה רק אחרי 7
שעות בברירת
מחדל שלך
באמזון את
הדו"ח.
אז
אפש/ר לבנות LAMBDA
שתתן BILLING
מיידי, נניח
אחרי כל שעה.
או כמה זה עלה
עד עכשיו.
Example 3:
כיבויי
מכונות בערב
או בסופ"ש.
BEANSTALK
אפשרות
פשוטה
למפתחים
להריץ סביבות
עבודה ושפות
מבלי ידע
מקדים
בתשתיות. יושב
בין PaaS ל IaaS . נניח שDEVOPS
מאוד עסוקים,
אבל
לQA
אין סביבת
עבודה בנתיים
והם מבזבזים
זמן בשיחות
מסדרון>>BEANSTALK נותן את
המענה הזה.
עובד בצורה שוטפת עם שאר השירותים של אמזון.
בדומה
לNETLIFY
Application:
tutorial
can get Domain name on its own or one that we have
platform is automatically installed
high availability-depends on your resources to allow for HA
can use DB to connect via VPC-enable a database-it creates a NEW one.erasing beanstalk will erase the DB
completely run via amazon and everything we do to the servers/instances is via beanstalk.
Environment:
ניתן
לשייך סביבות
לתוך
האפליקציה.
כשמייצרים
אפליקציה גם
מייצרים
סביבה(ENV).
אז לכן אם כבר
יש סביבה עדיף
לשייך
אפליקציות
נוספות לאותה
סביבה. או
שאפשר לעשות
כמה סביבות
שאותה
אפליקציה
עובדת על כל
אחת מהסביבות.
ROUTE 53
מאפשר
ניתוב, כמו
שרת DNS,
כל פעם שניגש
לDOMAIN
השירות הזה
ינתב לאן
שנרצה.
PUBLIC:
אומר
שהדומיין
צריך להיות
כבר קיים.
PRIVATE:
דומיין
שאנחנו בונים
Tutorial
מייצרים
HOSTED ZONES
RECORD:
זה לדוגמא WWW, או A RECORD
נבחר
LB.
שיפנה רק מהDOMAIN שהגדרנו
ב ROUTE 53.
ALIAS: שירותי אמאזון שיכולים להפנות אליהם. לדוגמא למכונה, או לDB או כל דבר של אמאזון.
עולה
כסף אבל מעט.
לוקליזציה:ניתן
להפנות גם
מאיזורים
שונים בעולם-
כדי לייצר
לוקליזציה
לאפליקציות
ולPROXY
ללקוחות
רחוקים.
או אנטי לוקליזציה-שנתאים שפות לפי האזורים שמהם מגיע הלקוח/מדינה. נפנה אותו לRECORD של אתר אחר.
CDN – content
delivery network/ CloudFront
מאפשר
CACHE
לאזורים
מרוחקים,
במקרה של
בקשות
מרוחקות, השירות
יוריד את
התכנים קרוב
יותר ללקוח,
ואז יהיה מהיר
ונגיש יותר
בעתיד.
INVALIDATION-
מאפשר REFRSH
לשרתים/אתרים
שעוברים
עדכון, ויעדכן
את הCACHE
במקרה הצורך.
עובד
בד"כ עם נתוני
אחסון-תמונות
סרטונים.
לדוגמא טלגרם
או וואצפ.
CLOUDFLARE,
שירותי CDN
לא של אמאזון
אבל אמאזון
יודעת לעבוד
איתם ולהיפך.
AKAMAI
אותו דבר.
ואז
צריך לדעת
לפצל את התשלומים
שלי.
CODE DEPLOY
( לעומת continuos delivery שבה יש MANUAL בשלב שלפני הPRODUCTION. שעוברים על הכל ידנית.)
CD elements-
Unti test>platform test>deliver to staging > application acceptance tests> deploy to production >post deploy
Code deploy creates agent on an instance that will allow interaction with other services. And can update the app inside too.
הAGENT שמשתילים
בINSTANCE
מתקשר עם APPSPEC ומנתב
לאוטומציה עם
הCODE DEPLOY
Tutorial
Todo:
Create CodeDeploy application.
create roles(EC2+codeDeploy).
Create agent in EC2+attach roles.
Create deployment group
1) ייצורfor IAM ROLE של 2EC:
a. >Aws service>ec2>next>codedploy>aws tool for code deploy>name>finish
2) ייצור ROLE עבור ה CODE DEPLOY
a. IAM>Role>codedeploy>next…>next>name>finish
3) מייצרים CODE DEPLOY
a. >code deploy>application> create app>ec2/on premise>create app
4) Building instance for code deploy
a. 4 instances named web-ariel->aws linux 2> +tag : ariel-deply, value:true
b. Vpc on public subnet+enable security group+ ssh+http
c. Advanced details>Select IAM role of ec2 we create on phase 1!
d. Install agent -one time run, advanced details>user data
i. Via guide on internet : install codedeploy agent on user data:take only formal script of aws
ii. יש לשנות REGION שיותאם לשלנו בתוך הסקריפט-ראה סקריפט.
iii. בודקים בSSH שהמכונה אכן מריצה CODEDEPLOY: sudo systemctl status codedeploy-agent.service
5) מייצרים DEPLOYMENT GROUP בתוך CODE DEPLOY שיצרנו,
i. Name>role of code deploy(NOT ec2!)>in place>EC2 instance>tag: ariel-deploy:true(what we put in tag)
ii. מוודאים שיש את המכונות של הINSTANCE שיצרנו מקודם כאופציה בתוך הDEPLOYMENT GROUP
iii. Install AWS agent>NEVER(because we installed via that script)>all at once> X no load balancer>create
b. אפשר לבדוק בתוך הDEPLOYMENT GROUP, אם הTAG אכן נמצא כENVIRONMENT CONFIGURATION
6) נפרוש קוד לאפליקציה דרך create deployment(in the application)-GITHUB
a. קובץ שחייב להיות בשם ובפורמט:appspec.yml שאומר איך CODEDEPLOY יפרוס את הקוד בשרתים
b. Create deployment>stored in GitHub>token:give name(ariel-github-token)>connect to github>account+repo name(meditator3/codedeploy)
i. Last commit ID, get through github>under Sync Fork, click on clock icon and commits>get last commit ID
ii. Paste into AWS commit ID>description>nothing else>create deploy
iii. Check your app is deployed by copying public ip to http(not https!)
Code Deploy משתמש בBUCKET של 3S כדי
להעביר או
למשוך גרסאות
ישנות/חדשות
או ארטיפקטים. באופן
כללי לCI CD
מפעיל
אוטומטית על
ידי טריגר של COMMIT את הDEPLOYMENT.
מחבר
את כל הPRE
REQUISITS, ובסוף
מנקה את כל
השלבים.
עולה
מעט כסף יחסית-
לכל PIPELINE
1$ לחודש.
הכנת
PIPELINE
V2>new role>allow awes to create role>NEXT
Source:github v2>connecting to github-allow everything to give aws access to all commits!>repo name we want to allow>
Trigger>push(whenever we want)>branch name(master)>default>NEXT
No build>SKIP>deploy:app deployment name+deployment group>finish
ועכשיו
ברגע שנעשה
נניח שינוי
באפליקציה, נניח
בריפו של meditator3/codedeploy
נשנה לצבע רקע
אחר, זה אוטומטית
יריץ את
הפייפליין
ECR: elastic container registery
סוג
של DOCKERHUB,
יש REPOSITORIES.
אבל משלב עם SERIVCES של AWS.
זה
לא קוברנטיס,
רק CLUSTER
של DOCKER.
AWS
Cloud Formation זה הIaaS כמו Terraform
רק של AWS.
AWS Cloudfront =
שירות CDN
ECS- elastic container
service
בניית CLUSTER: name>EC2>linux2/win>machine size>scale>no need for ssh because everything is run via amazon>root volume(just root!)>VPC>all private subnets, because LB can lead you to them. Can’t be public for production level>sec.grp: allow from anywhere>finish
בדיקה: We see autoscaling group of ECS. We see instances run by ECS as cluster
הרמת
אפליקציה בCLUSTER
בניית
NEW TASK:
Task definition: זה כמו DOCKER COMPOSE או DOCKER RUN בתוך
שירות של ECS
Create task definition for the app:
Bridge means-the containers can talk to themselves via their names
Host: they can only talk to themselves without outside link
None: can’t talk with anyone
Awsvpc: can talk with subnets of the vpc
Task definitions>new>EC2>change from awsvpcàbridge>task role:none
Container -1> name + image name+version
IMAGE URI is the image name from the pull request(not URL)
Deploy/service
Name of cluster>tasks, create new task> launch type:EC2> service/task, which will resuscitate if down>
Task placement>one task per host
יצירת
security group:
עם INBOUND
שיקשיב לPORT של
האפליקציה,
מעבר לSG
הרגיל
יצירת
target group
עבור ה NLB(network
load balancer)
יצירת LB: NLB, לבחור את כל הPUBLIC כי מתחברים מבחוץ לCLUSTER.
בדיקה: לקחת מתוך ה LB את הDNS שלוף להוסיף את מספר הפורט בדפדפן, ולבדוק שזה רץ.
הרמת
אפליקציית WORDPRESS + MYSQL DB של RDS
אותו תהליך עם הtask definition לוקחים IMAGE מתוך DOCKER HUB.
ייצור
קבוצת SUBNET:RDS>subnet groups>create> choose only private
מרימים DB של אמזון:50gb storage RDS>standard create>mysql>free tier>name:wordpress-db>engine version: (according to yaml of image)5.7>
>disable autoscaling for storage>
התחברות לDB:
אפשרות 1:
להתחבר
דרך MYSQL WORKBENCH
ועם OPENVPN.
יש להעתיק ENDPOINT
מתוך הפרטים
של הDB-ל MYSQL WORKBENCH
מחיקת INSTANCE ששייך לCLUSTER שלו: אפשר להוריד את ASG ל0, או למחוק דרך CLOUD FORMATION
אפשרות 2:
להרים
INSTANCE
רגיל של
אובונטו, עם
כתובת
חיצונית.
לוודא
שאנחנו גם בSECURITY GROUP שעבדנו
עם הRDS,
אחרת אנחנו לא
באותו VPC
כביכול. וגם
שיש חיבור לSSH
ככה
מוודאים שהINSTANCE
מתקשר עם הRDS (כי
הם אמורים
להיות באותו SEC של
אותוהVPC): telnet <endpoint of mysql RDS> 3306
sudo apt search mysql
sudo apt install mysql-client-8.0
mysql -h dblidor.cxwjnmc8j0ya.eu-central-1.rds.amazonaws.com -u admin -p
create database wp2; כדוגמא לזה שזה עובד
CREATE USER 'wordpress_user'@'%' IDENTIFIED BY 'a1a1a1'; האחוז מאפשר להתחבר מתוך המסד נתונים עצמו, אחרת לא ניתן כלל להתחבר
לבדיקה:
SELECT * FROM mysql.user WHERE user = 'ariel' AND host
= '%';
GRANT ALL PRIVILEGES ON wp2.* TO 'wordpress_user'@'%' IDENTIFIED BY 'a1a1a1';
FLUSH PRIVILEGES;
ייצור
הWORDPRESS:
Task definition: wordpress>image:wordpress>80:80>add ENV variables, according to
https://hub.docker.com/_/wordpress
using the word press ENV. (wrodpress user, wordpress DB etc)
create Volume:
השתמש ה SOURCE כשם שנבחר בYAML של הIMAGE שבDOCKERHUB, ואז MOUNT POINTS העתק את הPATH מתוך הYAML כ בCONTAINER PATH
ייצור
SERVICE:
רגיל,
לשים TARGET GROUP
מתאים עם
הפורט המתאים,
ולבדוק שאכן
המכונות בHEALTHY תחת
הTG.
חסרון
גדול לVOLUME ב ECS: הVOLUME נעלם
אם המכונה
מושמדת. זה לא
כמו קוברנטיס
שזה נשמר בצד.
TIPS
Migration of instance between regions:
You can copy instances to OTHER regions: EC2>create AMI from instance>AMI> right click+name of instance>copy>destination
On new region>AMI> launch instance from AMI
No public IP?
Attach
elastic ip to an instance
בעיות
בAWS CLI
להכניס תחת ~/.aws/config:
[default]
region = Global
output = json
[profile aws4]
region = eu-west-2
output = json
aws_access_key_id = AKIAU77SCMU3KD52NRNP
aws_secret_access_key = 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
כל
פעם שנשנה את
הCONFIGURE
-סיסמה וSECRET,
נעבור בהתאם
למשתמש הCORRESPONDING(ש-לו
משוייכת
המפתח+סוד)
אם
לא נכנס השם
לפרופיל:
$env:AWS_PROFILE=”aws4”
עבור POWERSHELL
קוברנטיס כשירות של אמזון.
משמש כ PaaS יותר
מאשר IaaS כי
אמאזון מנהלת
את הMASTER NODES,
וגם אי אפשר
להתקין כל דבר
כי המערכת
נעולה יחסית,
לדוגמא אי
אפשר להתקין openEBS
יצירת NODE: compute>node group>add node group>IAM
ROLE
Create
IAM role>EC2!
אחרי
היצירה יש
להצמיד עוד POLICIES
CNI, amazon work NODE,EC2 containerRegistery read only, EBSSCSI policy
עבודה
עם AWS CLI
לוודא
שאני זה אני: aws sts
get-caller-identity
Troubleshooting : למחוק ACCESS ישן
ולעשות חדש.
aws
eks --region eu-west-2 update-kubeconfig --name ariel-eks-cluster
^^ כדי להחיל את
הריגן העדכני
בהקשר של
הקלאסטר הזה
Kubectl config
get-contexts
כדי לבדוק אם
אנחנו
בקלאסטר
הנכון
Kubectl
config use-context <name of cluster> כדי
לבחור עבודה
מול הקלאסטר
הספציפי
AWS gp2 sc
problem:
Doesn’t
provision volume, and thus pods won’t be created.
For that we
need EBS storage class. That will provision volumes, it is a newer SC implanted
in the last few years(2022-2023?)
See below.
** must enable addons :CSI Snapshot Controler + Amazon EBS CSI Driver
– to allow volume managments ***
Kubectl
get sc – לא מראה SC, אבל כן
מראה פודים
חדשים של
התוספים האלה
^^
See
how-to EBS-CSI script/guide
EKS-volume-Az-Problem
+ svc + volume-conflict-problem.txt
Kubectl get sc
: יראה
לנו gp2
שזה אחסון
שאמזון מאפשר
ומקצה לנו כל
פעם.
הבעיה
באמאזון היא
בהקצאת VOLUMES בAZ אחרים.
הVOLUME לא
יעבור לAZ אחר אם
יתרומם פוד
חדש בAZ
אחר. ואז כל הDATA
ימחק
פתרון
1: מוסיפים
NODEGROUP
Kubectl get
nodes -o wide –show-labels : מציג את כל
הלייבלים שיש.
אפשר גם פקודה
יותר ברורה
שמראה את
הלייבלים: kubectl get nodes -o wide
--show-labels | awk 'NR>1{gsub(/,/, "\n\t")}1’
שם
נראה איזה AZ יש לכל NODE, נניח 1a
או 2b, עבור EU WEST
וכולי.
Kubectl
label node <name of node> zone=<wanted Availability Zone, for
example=1a>: שזה
ניסיון
לפתרון לשמור
על AZ
אחד כדי שיקום
הVOLUME
באותו AZ שלא ימחק
לנו שעוברים AZ אחר.
אבל
הפתרון לא
טוב, כי אם
נופל הDATA CENTER של הAZ הזה, הלך
כל הCLUSTER.
כי עבדנו רק
עם AZ
אחד.
מגבלות
PODS
לכל NODE של AWS
AWS שם
מגבלות לכל NODE,
בהתאם לכוח
המכונה.
לדוגמא t2.medium
יכול
להכיל 17 POD.
T3a.large
מכיל 35.
אזהרה:
זה המקסימום.
יש להיזהר
מפתיחת פודים
כמו בCRONJOB
שפותח וסוגר,
ואז הNODE
יהיה סתום ולא
יוכל לפרוש PODים
חדשים בכלל!
כי לדוגמא כל מה שנשאר ב PENDING יש לו תפוסה של POD!
EKS ניהול
אבטחת פורטים:
EKS
פותח ENI שהוא
נוצר עם SECURITY
GROUP שמחוברות
לENI הזה, וכך
מאפשר מעבר
מבודד רק בין
מה שמחובר לSG ולCONTROL PLANE, הSG
האלו מנוהלים
על ידי AWS
ולכן,
אם רוצים
לשנות זה
לשנות דברים
שיכולים להתנגש
עם הניהול של AWS(לא
סגור על זה). מתועד
כאן בDOC
של AWS
הוספת
ADMIN ACCESS ל EKS
to add admin user to EKS(in case more devops need to work on it)
check who's authorized:
kubectl -n kube-system get configmap aws-auth -o yaml
should display like this, and rolearn is the user/s that are registered as admin.
apiVersion: v1
data:
mapRoles: |
- groups:
- system:bootstrappers
- system:nodes
rolearn: arn:aws:iam::343568180534:role/ariel-EKS-nodeGroup
username: system:node:{{EC2PrivateDNSName}}
kind: ConfigMap
metadata:
creationTimestamp: "2023-11-28T09:12:59Z"
name: aws-auth
namespace: kube-system
resourceVersion: "1128575"
uid: 462f5626-136f-4e8e-92f4-b8400b935fa8
to edit the configmap :
kubectl -n kube-system edit configmap aws-auth
<will open a notepad edit, can copy paste to VS code>
to get the user ARN:
go to users>ARN(copy)
and add under mapRoles: | <<<<<<<<<<<<<DANGEROUS CAN DESTROY CLUSTER!!!!!
mapRoles: |
- groups:
:
:
:
mapUsers: |
- userarn: <copy here the ARN of the added user>
username: <username of added>
groups: <<<<<<<<<<<<<<<<<<THIS IS MOST CRUCIAL, because it gives the role of admin! >>>>
- system: masters
**now copy back to the notepad if worked on VS code
no need to reboot anything, it should be
applied immedietly.
EBS – Volumes persistence
ebs storage class is newer storage class that creates new volumes
the default gp2 doesn't create new volumes automatically by amazon
git clone https://github.com/kubernetes-sigs/aws-ebs-csi-driver.git
cd aws-ebs-csi-driver/examples/kubernetes/dynamic-provisioning/
can be used for gp3(newer HD):
echo "parameters:
type: gp3" >>manifests/storageclass.yaml
kubectl apply -f /manifests/storageclass.yaml
test:
kubectl get sc
kubectl get pods
kubectl get pvc
the pvc should be BOUND
another command ??
kubectl patch storageclass ebs-sc -p
'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
SEE:
scripts for deploy and PV/EKS DEMO
Service
account/ serviceAccount in k8s in conjunction with cloud provisioning:
If the
cluster needs to use resources from aws, it needs proper permissions. In the
form of roles of aws.
To
attach it to make the cluster identifiable to aws, we use service account
annotation. So what we added in annotation, which is
the role reference, is now present in the cluster’s service account
With the
proper role of the aws resource.
kubectl
annotate serviceaccount sns-publisher \
-n default \
eks.amazonaws.com/role-arn=arn:aws:iam::<amazon id>:role/access-sns-cronjob
The Persistance Volume
Bug/Problem
the problem is that volumes on different AZ of the pod will not revive. because there's no volume on that AZ.
Possible solutions:
- openEBS: having access to disk from anywhere(since openEBS gives you more storage on the SCSi level)
- back up of volume/disk over another AZ(availability zone) and raise a snapshot or AMI of the most recent.
- Newer sort of volume (EFS?) which operates on any AZ.
As long as you have the pvc(pv claim) you can revive/rescue the volume with the new data.
EKS- AutoScaler
Serves in general for scaling NODES number/availability, rather than the HPA(horizontal Pod Autoscaler), which serves pods inside the cluster.
Installation:
AUTO-DISCOVERY INSTALL OF ASG:
# Method 1 - Using Autodiscovery
$ helm install my-release autoscaler/cluster-autoscaler \
--set 'autoDiscovery.clusterName'=<CLUSTER NAME>
new values of helm:
cat ariel-values
awsRegion: eu-west-2
autoDiscovery:
tags:
- k8s.io/cluster-autoscaler/enabled
- k8s.io/cluster-autoscaler/ariel-eks-cluster
extraArgs:
skip-nodes-with-local-storage: false
balance-similar-node-groups: false
skip-nodes-with-system-pods: false
--
helm install my-release2 autoscaler/cluster-autoscaler \
--set autoDiscovery.clusterName=ariel-eks-cluster \
--set awsRegion=eu-west-2
EKS-CTL
A CLI TOOL of EKS service, closer to kubectl. Working on the cluster with eksctl sometimes, instead of kubectl, to apply various services.
Warning: Eks-ctl does not! Work with the portal of AWS, meaning any changes of EKS portal services will be OVERWRITTEN by eksctl, later on.
So only work over EKSCTL and not parallel to eks portal/aws dashboard.
Installation:
aws cli installed and verified. check access keys or new, and delete old ones if troubleshoot.
download eksctl and add to ENV PATH.
install this yaml called config.yaml
via this command:
> eksctl create cluster -f config.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: cluster-in-existing-vpc
region: eu-west-2
vpc:
subnets:
private:
eu-west-2a: { id: subnet-03fc0359221d6359e }
eu-west-2b: { id: subnet-07f8f2e18d600b9f8 }
eu-west-2c: { id: subnet-07cdef86020d2af0b }
nodeGroups:
- name: ng-1-workers
labels: { role: workers }
instanceType: t3.xlarge
desiredCapacity: 1
privateNetworking: true
- name: ng-2-builders
labels: { role: builders }
instanceType: t3.2xlarge
desiredCapacity: 1
privateNetworking: true
iam:
withAddonPolicies:
imageBuilder: true
to delete:
check you're in right cluster-
kubectl config get-contexts
switch if needed:
kubectl config use-context aws4@cluster-in-existing-vpc.eu-west-2.eksctl.io
eksctl delete nodegroup --config-file=dev-cluster.yaml --include=ng-2-builders --approve
eksctl upgrade cluster -f config.yaml --approve
eksctl delete cluster --name=<name> [--region=<region>]
make sure the name is like the one appearing on amazon portal.
IAM (identity & Access Management)
Example: use of IAM role to attach to EC2 instance for allowing access to aws services, without aws identity/configure.
ENI )elastic network
interface)
הגדרת
AWS
לחיבורי רשת
ArgoCD
Automation and visualization of continuous deployment. It allows automatic update of either cluster/pod/container via commit push from github changes to the code. Version re-rolling etc.
Installation:
1)argocd via github >create ns argocd
install via:
1.5) install.yaml: change line 21711 under containers :
args:
- --insecure
because this is local, no certificate.
2)kubectl apply -n argocd -f install.yaml <file in this folder
3)ingress rule:
kubectl get secret -n argocd
4) kubectl get ingress -n argocd
5) get ip of LB to put into the local: ping LB domain, copy IP.
paste into etc/hosts of machine>> kubectl exec -it <pod> /bin/bash
ingress installation: change to host accordingly
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argo-cd-ui
namespace: argocd
annotations:
ingress.kubernetes.io/proxy-body-size: 100M
ingress.kubernetes.io/app-root: "/"
spec:
ingressClassName: nginx
tls:
- hosts:
- argocd.local
secretName: argocd-secret
rules:
- host: argocd.local
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: argocd-server
port:
name: http
get admin and pasword
user: admin
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
password: dfkhcO7xdhfABi5t
check application works and see automated CD in action:
repo: https://github.com/argoproj/argocd-example-apps.git
>sync policy-auto
>git repo path as above(for repo)
> path: guestbook (according to PRIMARY/guestbook)
> self heal
> auto create namespace!
> default k8s cluster
cert-manager is free, and automates purchasing of new TLS certs, (newer version of SSL certs) and also renewing them.
versus for example, wild card certificate which you need to pay 300$ ~ for every subdomain name under the host-zone.
as in either pay per service for a cert. or pay for all of them(wild card certs are valid for 5 years).
so cert manager automates everything regarding certs. and for free.
Script and files to install cert-manager
https://cert-manager.io/docs/getting-started/
need a domain name(hostinger for me)
get LB name from k8s:
kubectl get svc -n ingress-nginx
check the LB has 443 open, because we need https for the certificate
-open new hosted zone with my domain name(route53)
-copy the NS to the registar of my domain(hostinger)
- use the LB address as an A record in route 53
CHANGE to ALIAS! that why you can protocol it from aws resources
choose LoadBalancer + region+ the k8s LB from ingress
that way the domain name will route to the LB and whatever we have(which is k8s!) will show.
used this guide:
https://cert-manager.io/docs/tutorials/acme/nginx-ingress/
stage 4
install ingress deployment
edit the ingress service:
name: arieldevops.tech
api.arieldevops.tech
apply the links on stage 4
check the kuard app is working on the domain api.arieldevops.tech
tehn go to helm guide install link
update repos and install the cert-manager
+issuer/yaml
ArgoCD is k8s deployment, that can deploy apps into k8s, in helm or other, via github or other, using ssh connection. It’s a GitOps tool.
It’s a gitOps tool because it adheres to a single source of truth, as in that git repo. That once it updates it can re-deploy.
ArgoCD is indeed a CD tool, and not CI, but the process is that CI triggered by code changes, updates the registery,
And a script/kustomize updates the image to the current version in the argoCD manifests-which are on git repo.
Once they are updated, argoCD pulls the new image of the new version and re-deploys automatically, which is a Continuous Deployment pipeline.
Convert helm chart/templates to an argocd manifest:
helm template <release-name> <chart-path> --values <values-file> > output-manifest.yaml
Terraform is an Infrastructure as Code (IaC) tool that enables users to define and provision infrastructure resources in a declarative configuration language. While it's commonly used to quickly establish and manage environments, its capabilities extend beyond just creating resources.
Key aspects of Terraform include:
1. Declarative Configuration: Terraform uses a declarative syntax to define the desired state of your infrastructure. Users specify what resources they want, and Terraform figures out how to create and manage them.
2. Multi-Cloud Support: Terraform is cloud-agnostic, meaning it can be used to manage infrastructure across various cloud providers (AWS, Azure, Google Cloud, etc.) as well as on-premises environments.
3. Resource Provisioning: Terraform can provision and manage a wide range of infrastructure resources, such as virtual machines, storage accounts, networks, databases, and more.
4. Dependency Management: Terraform understands the dependencies between resources and ensures that resources are created and configured in the correct order.
5. State Management: Terraform keeps track of the current state of your infrastructure in a state file. This file is used to plan and apply changes, helping Terraform to understand the differences between the desired state and the current state.
6. Modularity and Reusability: Terraform configurations are modular, allowing you to reuse code and share infrastructure patterns across projects.
7. Versioning and Collaboration: Terraform configurations can be versioned, allowing teams to collaborate on infrastructure changes and roll back to previous versions if needed.
While Terraform is often used for quickly establishing and managing environments, it's also a tool for maintaining and evolving infrastructure over time. This includes making changes, scaling resources, and managing the entire lifecycle of infrastructure components.
In summary, Terraform is a versatile tool that simplifies infrastructure management, providing a consistent and reproducible way to define, create, and modify infrastructure across different environments.
Terraform language is HCL, HashiCorp Language (form of DSL [Domain Specific Language]). Form of declarative language to define infrastructure.
To start terraform:
Terraform init (in the specific folder for terraform installation files to be downloaded)
Terraform plan – after you’ve wrote the IaaS code
Terraform Apply – to apply the resources in the cloud
Components:
- Main.tf : what resources to create
- Provider.tf : data for which user/region/keys
- Provisioner.tf
Other .tf files are:
· Variables.tf : define what variables to be used, for example- provider.tf will use var.region, which was defined in variables, either as a default or another.
· Terraform.tfstate : gives all the info about the planned terraform
· Terraform.tfvars: keeps the creds, like main.tf
· Ami.tf : inside selector of the ami ID for the kind of OS/year/version/type(hyper VM-hvm)/architecture:x86_64
Terraform windows
- Need special script, and also take the ami ID from amazon, change every ferw months on amazon.
- See scripts on terraform
- Open ports for RDP, on winRM of the default security group of the default vpc (if we didn’t declared a vpc variable!)in amazon: winRM + from anywhere ipv4(port is 5985), and winRM https
Working with
AWS as terraform launch machine instance:
- Open a new instance, but first create role for terraform separately
- Attach in advanced>IAM role the - terraform role.
The common practice is to work on an instance, without ami credentials. But with the terraform role that is being used.
That means deleting AWS CREDS inside the .tf files
Ingress(inbound rules)/egress(outbound rules)
Expected values: From_port, to_port, protocol(tcp/udp/https), cidr_blocks = [“0.0.0.0/0”] << expects list of strings
Syntax
Structure/formatting
Script for expressions, script for conditionals
Resource “<type of resource>” “<name in terraform>” { ex. “aws_key_pair” “mykey”
<attribute/variable name> = “<value>” , ex. : key_name = “mykey” is the key pair value of key(mykey).
Giving terraform permissions to access aws
resources
Bad practice: Insert access/secret key into variables which later be exposed in terraform.tfvars
Better/secure practice:
-either use aws cli and terraform will recognize it, or-
Attach in advanced>IAM role the - terraform role.
Otherwise we would need to specify vulnerable access/secret keys in the .tf provider file. Which is bad practice.
Provider.tf is the one responsible for allowing access to terraform on the cloud.
The role is to the remote instance which runs terraforms init/apply
The credentials after you have configured aws cli, are in: > cat ~/.aws/credentials
Generating keys for instances to be used by either local/terraform
Locally:
To generate public and private keys via .pem:
ssh-keygen -y -f /path/to/your/private_key.pem > /path/to/projectDir/private_key.pub
*same key pair name in aws_key_pair block, and in aws_instance block, will ensure the instance will be using the key I tell him.
Example: resource “aws_key_pair” “mykey” {
Key_name = “key”
}
Resource “aws_instance” “ec2_instance" {
Key_name = aws_key_pair.mykey.key_name # this uses the key from the key-pair block
}
Creating an instance resource
Count = <number of instances>
Ami = <the ami ID, which is the OS[ubuntu/centos/windows etc]> example: ami = “${var.AMIS[var.region]}” >> which calls from the variable AMIS, and then calls to
The ID from the map of AMIS via the region, on var.region (default)
**make sure the ami is current. use the ami finder
Type = <t2.micro or other>
SSH/creating key-pairs for later use to connect to an Instance
We need private key in local , and the public key (from our local) to be in the remote.
Using file(“<path to pub key>”) we upload to aws the public key to the instance for later ssh.
To just create key pair, terraform and aws will extract it from a regular ssh.
Ssh-keygen -t rsa >>> then type name of key
Calling values of resources/variables
Resource “aws_instance” , or resource “aws_key_pair”, is calling for these resources in aws.
You can call the values of resources from inside the aws.
Public_id, id are values from inside the aws. So by Using output block, you call these values.
For example- resource “aws_instance” “example” {
#some configuration for instance
}
Output “instance_id” {
Value = aws_instance.example.id
}
Output “public_id” {
Value = aws_instance.example.public_id
}
You can’t call something that hasn’t been established.
For example: aws_instance.example.count , won’t call for count value, but –
output “count” {
value = length(aws_instance.example)
}
These will be displayed in terraform outputs, after terraform apply, or using terraform outputs only.
Every reference/reserved name is shown in the attributes inside of terraform.tfstate
Establishing connection to instance
To run any script on the instance, you would need to establish
connection first.
Connection block- Inside the block of the resource.
Self.XXXX is a reference to the instance block you are in,
Self.public_ip and self.private_ip are aws references, using coalesce will determine which one is not null, and return the value of the non-null:
Connection {
Host = coalesce(self.public_ip, self.private_ip)
Type = ssh
User = “${var.INSTANCE_USERNAME}”
Private_key = file(“${var.PATH_TO_PRIVATE _KEY}”)
}
Files in terraform
Can name files according to resources, for example key.tf, default_vpc.tf, ec2.tf, and TF will know to call upon these resources by name
Even though they are not in the files(but are in the folder)
Modules
A way to encapsulate resources and other TF components, for more arranged access.
For example- vpc, instances, s3 etc to be raised and configured separately. also it allows modular changes to be made
, example- in customized cidr blocks, different AZ.
TF calls the module using source = “<path/to/module>” and treats it like any other folder of TF.
Any Variables can be passed from parent to child. But the passed variables from parent, should be defined also in child’s.
Defaults are the goto for modular usage of modules. The value that can be put in variables.tf will override the defaults, allowing modularity.
OUTPUTS in module: write outputs as usual on the module, and pass the defined output name to the outputs in root. To view them on TF apply.
Terraforming from CLOUD
Attach IAM role for the instance that use terraform. This will allow aws access without aws configure.
VERSIONING
in TerraForm
Why?
As an example, When multiple teams make changes to a terraform template, because of deployment changes or development necessities, they plan and apply, but versioning should be common practice, to prevent loss of backups
The backup/state/version of template is stored in an S3 bucket of aws, and also via a table in DynamoDB(aws DB).
Also it allows for locking of a state while the plan is applied- to prevent conflicts. So another team cannot apply while the other is.
Also, very important- it doesn’t save the state locally(!), since remote is what the current version should be, in case someone updated-non-locally.
Remote backup/ BACKEND
The backend(in the script of demo-8 provider.tf) block, is writing configuration to top level configuration(using terraform block)
In a file backend.tf and knows to apply it to the tfstate, and save the state remotely.
See scripts of demo-8
We use DynamoDB to organize the states of TF, and S3 to save the states. Backend is a block in TF and in TerraGrunt
TAINT
צורה
של סימון של
משאב שנרצה
שיבנה מחדש
בטרפורם
אפליי.
Case where you’d want to “destroy” or rebuild a resource, without ruining everything.
Terraform taint <resource> will “defect” that resource, while terraform apply will rebuild it.
Terraform Untaint <resource> unmarking the taint. In case we
are satisfied with the resource.
העברת
PUBLIC KEY לREMOTE INSTANCE
resource "null_resource" "add_ssh_key" {
depends_on = [aws_instance.example]
# Provisioner to copy SSH key
provisioner "remote-exec" {
connection {
type = "ssh"
user = "ubuntu"
private_key = file("${path.module}/private_key")
host = aws_instance.example.public_ip
}
inline = [
"echo '${file("${path.module}/public_key.pub")}' >> ~/.ssh/authorized_keys"
]
}
}
בפקודת הINLINE ניתן לשפוך את הPUBLIC KEY ישירות לAUTHORIZED_KEYS כדי לאפשר אוטומציה בהרשאות מכונות אחת עם השניה.
TERRAGRUNT מאפשר מעטפת WRAPPER, על TERRAFORM שדרכה מריצים-
בדיקה על יבש איכותית יותר מPLAN, בTERRAGRUNT הWORKSPACE רץ הכל דרך הGIT ,
לעומת
הWROKSPACE
שהוא לוקאלי בTERRAFORM – ואז
אין צורך
שבעבודת צוות
כולם
יהיו שותפים לWORKSPACE, אם
עובדים בREMOTE.
אפשר
שיהיה REMOTE
STATE עבור כל
סביבה.
ניתן ממקור אחד להרים את כל הסביבה במקום שיהיה חזרתיות של קבצים לכל סביבה. זה השמירה על ה- (Don’t Repeat Yourself)DRY, כי TG עוטף את TF.
כתיבת
TG:
עובדים בBLOCKS-
סוגי הבלוקים: terraform, include, locals, dependencies, remote, generate
Terraform block:
איפה נמצא המודול, ומה אנחנו מרשים לעשות מבחינת terraform, HOOK שלפני ואחרי.
Remote blocks:
מאיפה לוקחים את הREMOTE STATE , שבתוך DynamoDB+s3, ואת הקונפיגורציה שלו. ומושכים את הקונפיג, חשבונות וכולי ע"י find_in_parent_folders()
***VARIABLE של
מפתח בBACKEND
של TERRAFORM
לא יעבוד. TF לא מרשה
לקרוא VARIABLE
מתוך BACKEND BLOCK.
INCLUDE BLOCK:
הTG
קורא מתוך
קבצי HCL
ומשם מפעיל TERRAFORM.
בבלוק הזה
אנחנו יכולים
"לרשת" מHCL אחרים
ולציין מאיפה
לקחת את
"הירושה".
מחפש
בעזרת find_in..
כדי למצוא עוד
הגדרות
שקשורות לREGION במקום
שנגדיר אותו
שוב מחדש.
LOCALS BLOCK
משתנים
או קבועים
שנשתמש בהם
לאורך כל
ההרמה, כמה
פעמים, כדי
שלא נצטרך
להגדיר אותם
שוב מחדש.
הINPUTS הם BLOCK של TERRAGRUNT שהוא
כמו vars.tf
לעומת
זאת בTF:
locals {
service_name =
"my-service"
owner =
"team-name"
}
resource "aws_instance" "example" {
tags = {
Name =
local.service_name
Owner = local.owner
}
}
DEPENDNCIES BLOCK
לדוגמא
אם צריך להרים
VPC,אז
קודם להרים SUBNET GROUPS ואז VPC
ועליו לפרוש
עוד משאב, אז
נצטרך לתזמן
ולסנכרן אותם
לפי סדר.
**אחד
אחרי השני הוא
יריץ/ירים,
ובפקודת run-all יהיה
אפשר להרים את
זה. יש שימוש בPATH
בד"כ.
GENERATE BLOCK
מייצר
קבצי TF
איפה שHCL נמצאים,
עבור כל קוד
של TF
או להשתמש
בנתון, לדוגמא
עבור PROVIDER:
אם
נרצה להשתמש בPROVIDER קיים: if_exists=
“ignore” ואז
טרהגרנט לא
ידרוס את
הקיים.
דוגמא
לMULTI ENV של terraGrunt ש-מרים
גם PROD, DEV וגם STAGING
(תחת ENV)
Name of file(hcl) in terragrunt are always terragrunt.hcl
what is ansible?
ansible is sort of script wrapper after we have resources. Without an agent in the server.
using modules, which are declarative blocks over yaml files-the playbooks, or roles, which are basically meant to replace scripts.
These can be wrapped over the instances.
THE POWER of Ansible is the ability to wrap “scripts” in the form of playbooks, over multiple servers without going in one by one.
For example to update a version of an app in a container/server, you would add all host’s ips into the inventory/hosts of ansible
And deploy the playbook over them, not needing to enter each server. And also no need to install agents on each server.
check:
ansible --version
raising 2 ubuntu(web) + 1 aws linux(db) on same vpc and sec.group+ sec make sure SSH from anywhere
the ssh from gitbash is to the remote-controller machine.(ubuntu user)
on remote ansible machine mkdir ansible>inventory>
>vi hosts
----------
[remote-controller]
ansible ansible_host=127.0.0.1 ansible_connection=local ansible_become=true
[web]
web1 ansible_host=10.0.101.250 anisble_connection=ssh ansible_user=ubuntu ansible_become=true
web2 ansible_host=10.0.101.156 anisble_connection=ssh ansible_user=ubuntu ansible_become=true
[db]
db ansible_host=10.0.101.37 anisble_connection=ssh ansible_user=ec2-user ansible_become=true
ansible become true means I allow root access to perform the tasks of a playbook or anisble communication.
ניתן
להגדיר בHOSTS , RANGE
של IP,
לדוגמא כך: 205.168.20.[11:14]
במקום
לכתוב כל אחד.
CREATION OF PLAYBOOK
Define name(name:playbook1)
Define host(which server we apply the tasks, for ex. hosts: web)
Define tasks (tasks: )
If we want to apt install in ubuntu it’ll be-(apt: next line in block of apt etc.. see example here –
---
- name: playbook1
host: web
tasks:
- name: install apache web Package
apt:
name: apache2
state: present
- name: start Apache service
service:
name: apache2
state: started
enabled: yes
- name: validate status of apache
shell:
cmd: "systemctl status apache2"
but to ssh from the remote-controller to the other servers we need the private key hash:
we copy it from the local machine (windows) where i use it to authenticate with ariel-key.pem
, we copy this, into the remote controller.
copy ariel-key.pem from your local windows machine to the remote-controller, and then change the name to id_rsa inside
~/.ssh
check ping for remote with ansible:
ansible -i inventory/hosts -m ping remote-controller
ansible -i inventory/hosts -m ping web
ansible -i inventory/hosts -m ping db
ansible -i inventory/hosts -m ping all (checks all machines)
----
but we need ssh from of aws key... of the remote machine?
create a config for ansible to know where is inventory to load from
>ls
inventory (pwd=ubuntu/home/ansible)
>vi ansible.cfg
[defaults]
inventory=./inventory/hosts
now, we can use the command without -i
anisble -m ping web (and other checks
-----
create file to all servers:
>ansible all -m file -a "path=/tmp/adhoc1 state=touch mode=700"
---
if we want telnet on db
change in hosts for sudo permission to get telnet permission/elvated/.escalate permission:
after... ansible_user=ec2-user ansible_become=true
>ansible db -m yum -a "name=telnet state=present"
if not present it will install a telnet (yum install)
----
to install apache onto ubuntu web machines(both)
>ansible web -m apt -a "name=apach2 present=true"
Install ansible + scripts/playbooks of ansible
handlers:
a condition (usually if something has changed on server) to apply an action.
we use if something has change, and for example apache needs to be restarted,
like changing the index.html
file/ariel-index.html can be mkdir files >> ariel-index.html
handler must have notify before it, in the yaml notify indicates handler- it basically notifies the handler for ANY change.
and then we can call the handler via handlers: block
HANDLERS only activates when something has changed in the server(notify tells it when it changed), to maintain idempotency.
If the server changed, for example index.html in the following example, the handler will activate and run
Which will cause restart of apache, also it will be indicated when applying the playbook.
---
- name: play1
hosts: web
become: yes
tasks:
- name: install Apache web Package
apt:
name: apache2
state: present
- name: start Apache service
service:
name: apache2
state: started
enabled: yes
- name: validate status of apache service
shell:
cmd: "systemctl status apache2"
- name: copy website
copy:
src: ../files/ariel-index.html
dest: /var/www/html/index.html
owner: www-data
group: www-data
mode: '0644'
backup : true
notify: <<<<<<<<<<< THIS IS THE HANDLER
- restart Apache
handlers:
- name: restart Apache
service:
name: apache2
state: restarted
the output of this playbook with the handler, is that it will only run the handlers block, when index.html has CHANGED.
- name: play2
hosts: db
become: yes
tasks:
- name: download rpm file
shell:
cmd: "curl -sSLO https://dev.mysql.com/get/mysql80-community-release-el9-3.noarch.rpm"
- name: install rpm file
yum:
name: mysql80-community-release-el9-3.noarch.rpm
state: present
disable_gpg_check: true
- name: install mysql package
yum:
name: mysql-community-server
state: present
update_cache: true
- name: start Mysql Server service
service:
name: mysqld
state: started
enabled: yes
- name: validate status of Mysql Server service
shell:
cmd: "systemctl status mysqld"
----
line in file
simply add a line into any file we want. in this case we changed max_connection in my.cfg to mysql configuration
---
- name: play1
hosts: web
tasks:
- name: install Apache web Package
apt:
name: apache2
state: present
- name: start Apache service
service:
name: apache2
state: started
enabled: yes
- name: validate status of apache service
shell:
cmd: "systemctl status apache2"
- name: copy website
copy:
src: ../files/index-lidor.html
dest: /var/www/html/index.html
owner: www-data
group: www-data
mode: '0644'
backup : true
notify:
- restart Apache
handlers:
- name: restart Apache
service:
name: apache2
state: restarted
- name: play2
hosts: db
tasks:
- name: download rpm file
shell:
cmd: "curl -sSLO https://dev.mysql.com/get/mysql80-community-release-el9-3.noarch.rpm"
- name: install rpm file
yum:
name: mysql80-community-release-el9-3.noarch.rpm
state: present
disable_gpg_check: true
- name: install mysql package
yum:
name: mysql-community-server
state: present
update_cache: true
- name: start Mysql Server service
service:
name: mysqld
state: started
enabled: yes
- name: validate status of Mysql Server service
shell:
cmd: "systemctl status mysqld"
- name: add or change config file line
lineinfile:
path: /etc/my.cnf
line: max_connections = 100
create: yes
notify:
- restart Mysql
handlers:
- name: restart Mysql
service:
name: mysqld
state: restarted
-----
hosts updated: with become true, that allow root access
-==========
[remote-controller]
ansible ansible_host=127.0.0.1 ansible_connection=local ansible_become=true
[web]
web-1 ansible_host=10.0.101.250 anisble_connection=ssh ansible_user=ubuntu ansib
le_become=true
web-2 ansible_host=10.0.101.156 anisble_connection=ssh ansible_user=ubuntu ansib
le_become=true
[db]
db-1 ansible_host=10.0.101.37 anisble_connection=ssh ansible_user=ec2-user ansib
le_become=true
======
but we can also create variables for all of them which repeat:
[remote-controller]
ansible ansible_host=127.0.0.1 ansible_connection=local ansible_become=true
[windows]
iis-server ansible_host=18.170.97.30 ansible_connection=winrm ansible_port=5985 ansible_user=ansible ansible_password=(what we put in windows user)
[web]
web-1 ansible_host=10.0.101.250
web-2 ansible_host=10.0.101.156
[db]
db-1 ansible_host=10.0.101.37
le_become=true
[servers:children]
remote-controller
web
db
[web:vars]
anisble_connection=ssh
ansible_user=ubuntu
ansible_become=true
[db:vars]
anisble_connection=ssh
ansible_user=ec2-user
ansible_become=true
---------------
to enable windows we create instance of windows t2.xlarge, using winRM-http and winRM-https open to all or to specific ip.
and we also need to open ports of firewall
firwall settings(inside the windows machine-check how to get in in windows_pass.txt) >
add ports 5985, 443 5986
but even though we tell it to use port 5985 and give him the user password (we created on windwos) :
windows rdp will reject it, because its still from txt(unsecure).
so we need to use
VAULT
----
ansible-vault encrypt inventory/hosts (inside ansible folder)
will encrypt ALL the hosts file, which isn't good for us.
so we have:
ansible-vault encrypt_string <password we want to encrypt>
then we get:
!vault |
dkjslfkjdlvncxm,vnx
and some encrypted stuff, we copy into the hosts part of : ansible_password= <copied encrypted password>
then we use the password we know, into the ping that connects to the windows:
anisble windows -m ping --ask-vault-pass
<feed password(normal one)>
but it didn't work because the hosts isnt a formatted yaml file
so we need to convert it to hosts.yaml and change the syntaxs:
preparing IIS windows server:(web-server and common http)
playbook-windows
---
- name: IIS playbook
hosts: windows
tasks:
- name: Install WEB SERVER IIS
ansible.windows.win_feature:
name: Web-Server
state: present
include_sub_features: true
include_management_tools: true
register: win_feature
register is an ansible feature-read on it. something about tasking outputs.
need to add --ask-vault-pass to ansible command, because it has the access there:
ansible windows -m win_pink --ask-vault-pass
also add inbound rule port 80/http to everywhere in sec.group of instance, to see the sindows server via browser.
according to the inventory- hosts has to run on something that is already in the hosts/inventory. so windows runs on the windows hosts/server we defined on hosts/inventory.
VAULT
Like secrets, it has a process, the vault is indicated in hosts file, and that allows a secure connection/authentication,
For example, if we would put the password as text in the hosts, instead of ansible_password=!vault
The accepting server will reject it because its plain text, and not a secure way of access the password-which should be
Vault.
ROLES
--------
roles are NOT like hosts. that has to be pre-defined with servers of hosts. Roles are generic. And do not provide hosts.
Encapsulated.
So we can assume roles that are pre-defined:
- hosts:
webservers
roles:
- nginx
- php
And in our hosts file we can assume the roles indicated according to what we want:
[webservers]
server1.example.com
server2.example.com
[dbservers]
db1.example.com
roles are tasks of group related-like something only for hosts:windows, or just for db.
we have roles in :
galaxy.ansible.com
which can raise wordpress/windows etc anything.
but role ISN'T a playbook. we use the role to have it on the playbook.
to install a role, we take the link from the "repo" in galaxy.ansible.com
for example docker, should NOTE filter VIA download count/popularity.
<**DIDNT WORK**>
there's a command also to create role for yourself:
anisble-galaxy init ariel-role
this will create all the structures of the roles/inv+files, a generic/defaultive.
Summery:
Roles are moduler, with their own folder structure, and can be called upon in the playbook, in any playbook.
While playbooks are invoked on specific groups, roles aren’t, unless indicated in the playbook.
Example:
- hosts:
appservers
roles:
- webserver
- database
VARS(variables)
Allow the use of variables, for example to change paths, or naming of certain objects in the hosts file.
Usage:
Can be used in Roles as variables under /vars, or roles default variables under /defaults, and can be in tasks or in runtime.
Example:
---------
[webservers]
server1 ansible_host=192.168.1.10
max_clients=100
[dbservers]
server2 ansible_host=192.168.1.11
[all:vars]
max_clients=200 # Default
value for all hosts unless overridden
this applies max_clients to 200 to all hosts/servers.
לדוגמא
אם SSH
לא עובד, אפשר
לראות בJOURNALCTL,
שזה לוגים של SYSTEMCTL, מה
קרה
אולי
פורט 22 לא עובד,
או תפוס, שזה
אומר שהקונפיגורציה
שגויה.
בWINDOWS יש EVENT VIEWER
בJAVA גם
יש לוגים
שנקרא j4LOG
רמות
לוגים
בג'אווה:
Off>fatal>error>warn>info
רמה
גבוהה: >
debug>trace
SYSLOG:
שירות
לוגים חינמי
בלינוקס
לא עובד עם SNMP , לא יכול לתשאל DEVICE, SYSLOG מקבל EVENTS אליו לשרת SYSLOG
למעשה
רק מעביר
לוגים קיימים
ולא מתשאל
בעצמו
עובד
UDP לכן
אין HANDSHAKE,
חסרון.
לוגים
יכולים ללכת
לאיבוד לא
בטוח שאספו
אותם.
Syslog without DB has no organizing of logging, with large network you have to go over individual files with bash scripts to find.
Syslog is open source.
SYSLOG
לבד לא מספיק,
כי אם שרת
נופל ולא
מקבלים לוגים,
לא יודעים
בכלל שהוא נפל
אין
בכלל ניטור,
צריך מערכת
שעושה פינג
לשרתים שבכלל
יודעים שהם
אונליין
אחרת
אפשר לחשוב
שהשרת עדיין
מורם.
בטח
שלא בזמן אמת.
לכן חייבים
מערכת ניטור
שמתריאה
ובודקת
SYS LOG
הוא לא פתרון
מלא בכלל,
בגלל שיכולות
לעבור שעות,
בזמן שהייתה
תקלה.
זה
יעיל במובן
שאפשר לחקור
מה הייתה
התקלה- אבל לא
בזמן אמת!
REGEX
Logs usually use regex(regular expression) as a method of identifying/parsing/filtering/blocking certain types of messages.
The pattern in the regex matches RESPECTIVELY to the pattern of the text to referenced.
For example Can, Ban, Aan
The regex can be [A-C][an]
Examples:
Match:
cat.
896.
?=+.
Skip:
abc1
regex fits :
[a-z1-9\?\+\.\=][^abc1]
Match:
abc123xyz
|
define
"123" |
var g = 123;
regex fits:
[a-z1-3 \"=;]
Example3:
Ana
Bob
Cpc
Skip:
aax, bby, ccz
regex:
[A-C][n-p[a-c][^x-z]
Example4:
wazzzzzup
wazzzup
skip:
wazup
regex:
(waz{3,5}up)
Example
5:
aaaabbcc
aabbbbc
aacc
skip:
a
Regex:
(a{2,4}b{0,4}c{1,2})
Example 6:
1 file found?
2 files found?
24 files found?
Skip: No files found.
Regex:
\d* files? found\?
1. abc
2. abc
3. abc
4.abc
Regex:
\d\.\s+abc
See more and practice via regex101 and examples by regexOne
ELASTIK SEARCH CLUSTER)ELK(
מנוע
חיפוש של טקסט
מלא, גם עם WEB INTERFACE
וגם פולט
כמסמך JSON
זה
NOSQL
שומר
מסמכים בתוך הDB שלו (NO SQL)
בתור FULL TEXT
לפי התוצאות
הכי טובות.
של
חברת ELASTIK
שלושה
מוצרים באחד:
LOGSTASH, KIBANA, ELASTIC
בELK יש SHARD שזה
סוג של הפניה
לאינדקס שמראה
היכן המסמך,
וגם מאפשרת
חיפוש בתוך הSHARD
SHARD
הוא היחידה
הבסיסית של
ההפצה של ELK שעוזר
בפרישת העומס
בקלאסטר
הNODE
מתאמים בינהם
ומדברים
בינהם איך
לחלק את הSHARDS
יש
בכל אחד לפחות
אחד.
יש
גם REPLICA
שזה עותק של הSHARD
במצב שSHARD
נפגם/נעלם.
פרישת
העומס- הNODE
מדברים בינהם
ומעבירים REPLICA אם
נעלם לNODE
אחר הSHARD
ELK COMPONENTS:
-data nodes
-Master nodes (3, because that way 1 leads the many, instead of 2 fighting off leadership)
-Client node ----behind Load Balancer
Capacity planning-best practice:
- 4 Data Nodes(64GB MEM, 4CPU, 4*1 TB SSD, RAID 0)
- 3 dedicated Master Nodes(32 GB MEM, 2CPU)- only 1 is elected
- 2 client nodes(32 GB MEM, 2CPU)
ELK cluster to purchase from ELK is VERY expensive, but you get BEST practice.
ELK מחזיק את המידע בJSON, ולכן כדי לVISIBILITY, יש לנו את KIBANA שהיא התצוגה של כל פלט הJSON של ELK. מאפשרת פילטורים וגם לראות את הלוגים.
index can be thought of as an optimized collection of documents and each
document is a collection of fields, which are the key-value pairs that contain
your data
LOG
STASH
הרבה
מהלוגים לא
מגיעים
בפורמט JSON,
וELK
צריך לפלוט בJSON,
כלומר LOGSTASH
עושה PARSE
מהפורמט של
הלוגים
ולפרמט אותו לELK כJSON.
LOGSTASH
זה גם מה
שאוסף את
הלוגים. מעביר
לELK שאחר
כך יכול לסדר
אותם באינדקס
הנכון.
לסיכום-
ELASTIC SEARCH
מאפשר חיפוש
בתוך הSHARDS,
שזה פוינטרים
למקבץ מסמכים
שמאונדקסים, הSHARDS
קיימים בכל NODE
ומפוזרים
אוטומטית ע"י ELK
ועוברים
אופטימיזיציה
וגיבויי REPLICA.
LOGSTASH
זה מה שאוסף
את הלוגים
ועושה להם
פירמוט לJSON שצריך.
ניתן להתקין
רכיב נוסף שנקרא
BEATS
שהוא AGENT
שאוסף את
הלוגים. ושולח
אותם לLOGSTASH
KIBANA
זה
הויזולאליזציה
של הלוגים
והקלאסטר עם
פילטרים
שצריך, וגם
תצוגה של
הלוגים עצמם.
GRAYLOG-
עוד
מערכת איסוף
לוגים, שמכילה
גם את ELK
וגם MONGODB
עם KAFKA
LOGZ.IO –
חברה
ישראלית
שאוספת לוגים
עבור הלקוחות,
היא מחזיקה את
ELK על
שלושת
הרכיבים שלה
ומתקינים את הAGENT שלה
על הלקוחות
והם מראים
ללקוחות את הKIBANA, סוג
של ענן של
לוגים.
לא
חינמי, עלות
כנראה על פי
כמות לוגים.
SPLUNK-
דומה לCORALOGIX או ELK, זה DB שבמרום ELK, עושה קורולציה בזמן אמת ומראה גרפים וכולי. נחשב לא פשוט להתקנה ולשימוש. מורכב, כי הכל צריך להכין בעצמך.
CoraLogix+FluentD –
FLUENTD
עושה SCRAPING
לLOGS
שיש אבל CORALOGIX מספק
ויזיבליות,
דרך מסננים וSERVICE.
שיטות3 סוגים:
AGENT PUSH
שיטה
שעובדת עם AGENT שנדחף/PUSH על
השרת כדי
לאסוף
מטריקות
וביצועיות של
המערכת
המארחת
QUERY
תקופתי ששולף
את המידע,
מאפשר מידע
מפורט על המערכת
מבחינת
משאבים
MONITOR POLL
שיטה
ללא AGENT,
אלא על ידי
שימוש
בפרוטוקלים
כמו SNMP, WMI או
SSH כדי
לשלוף מידע REMOTELY
מקבלים
פחות פירוט
בשיטה זו
למעשה
הוא דוחף את
המידע למערכת
הלוגים.
HYBRID
מידע שנאסף חלק בשיטה של PUSH וחלק בשיטת POLL
APM: application performance management, monitoringand management of performance and availability of software apps.
APM strives to detect and diagnose complex application performance problems to maintain an expected level of service.
It is the translation of IT metrics into business meaning.
APM includes all problems in the application, or the DB, or cpu usage, memory demands, and other services that show how they are affecting each other. Examples: NewRELIC, Datadog
KPI: key performance indicators- measurable value that demonstrates how effectively a company
(40% up time is not good, and 90% uptime can be good, hard call)
After installation, there should be Prometheus, alertmanager and Grafana.
To get more graphs from Grafana, use explore>query> cpu<node in seconds>>namespaces>name of name space duplicate query change ns> add to dashboard
Can get dashboards from Grafana dashboard website.
Components:
- Prometheus Server – scrapes and stores time series data
- Client libraries – instrumenting application code
- Push gateway - for supporting short lived jobs
- Exporters – of special purpose for services like HAProxy, StatsD, Graphite, etc.
- AlertManager – for alerts
- Other support tools
Node_exporter is the component collecting from kubernetes. It gets metrics from services, pods etc.
Methods of collecting the metrics(in general for monitoring, not just prometheus):
- Scraping endpoints: services we want to expose metrics, for example could use /metrics endpoint
- Configuring jobs in Prometheus, and service discovery
- Formatting metrics is line based with metric name, optional labels in curly braces, a value and maybe a timestamp
o The services can natively export the metrics, or use node_exporter or other exporters to export the metrics.
- Exporters: agents that Prometheus deploys to collect.if the application doesn’t provide.
- Via annotations: can tell annotation to pass metrics to Prometheus.
-
In some
cases usage of CRD(costume resource definition) , via
Prometheus operator, to manage the prometheus resources by k8s.
kubectl get prometheusrules -n monitoring: shows all rules defined by prom. Operator
TSDB: Prometheus uses Time Series DataBase, storing and managing time stamped data. Well optimized for high performance.
Prometheus+Alert manager in more detail
Prometheus uses PromQL
Instant vector: a set of labeled time series, with one sample for each series-at that same timestamp. Like node_cpu_seconds_total(a selector or any function can return instant.v)
Example: kube_pod_container_status_restarts_total{namespace="production"} << will show a single sample
Range vector: set of labeled time series, with range of samples over a time frame for each series. Which can be by adding the [5m]. the function before the query determines the manner.
increase(kube_pod_container_status_restarts_total{namespace="production"}[1h]) > 1 Example:
will show if there’s an increase in restarting pods for the last hour, over a 1 limit.
To know ALL METRICS –
CLICK THE EARTH PLANET ICON IN SEARCH BAR.
Alerts will fire from Prometheus to alertmanager according to the rules. Each rules can be applied to a target. See targets section in Prometheus.
Watchdog alert is an always firing alert, to impose on alertmanager in case it fails. If watchdog fails to fire, it means alertmanager has failed somehow. And need to be checked.
More examples:
rate(container_cpu_cfs_periods_total{container="by-core-ms"}[5m]) << shows cpu flacuations over 5m. cfs= completely fair scheduler. But not real time cpu usage
rate(container_cpu_usage_seconds_total{container="by-core-ms"}[5m]) * 100 << shows realtime cpu usage
In graphs/Prometheus type any letter or keyword to get metrics queries.
Use table to know how to filter, which type/pod/instance etc using operators !=/=
Ex. instance:node_cpu:ratio{instance!="10.10.24.65:9100"}
Clicking
the planet earth near “execute” shows ALL metrics you can
harvest/scrape from(no need to guess). The play button
is test formatting.
Metrics ex: node_cpu_seconds_total
user: The time spent in userland
system: The time spent in the kernel
iowait: Time spent waiting for I/O
idle: Time the CPU had nothing to do
irq&softirq: Time servicing interrupts
guest: If you are running VMs, the CPU they use
steal: If you are a VM, time other
VMs "stole" from your CPUs
fdf
MongoDB
Transactions: in the case of multiple write occasions-onto the DB(not a single object write), transactions are collections of data to be written(not read) as a single “atomic” unit
It provides consistency of data, if all fail or all succeed(to write).
Transactions in MongoDB are only available via ReplicaSet install, and not a stand alone server install.
ReplicaSet: in mongo, it allows quicker pulling of data(high availability), and backups incase data falls(fault tolerance) . By using primary node, and a replication of it as secondary nodes.
If primary falls, secondary is a backup of it.
Commands in mongo:
Mongod – interacts with the daemon of mongo, the database itself.
Mongosh – interacts with the server of mongo, if you place a script in docker using mongosh, it will stop the container, after script is done.
Mongosh runs scripts of mongo, but scripts exit(ruins container runtime)
אסטרטגיה
לגילויי
בעיות בהרמת קונטיינרים DOCKER
:
אם
מנסים להרים DB אבל
מרוב הודעות בLOG לא
מצליחים לאתר
את התקלה,
מומל. להרים
קונטיינר
שיעשה את
בדיקת האתחול
של ה
DB,
מספר פעמים
ואז כל שגיאה
שתעלה יהיה
ניתן לצפות בה
בקלות בגלל
שהיא לא
מפוצצת
בלוגים של הDB.
/var/log/auth.log
SSH: key pair are always identical. When transferring them, they must be exactly the same. As long as the public key on the hosting machine won’t match
The private key of the ssh’ing machine, you’d be denied.
To check “pairness” use your private key name here:
ssh-keygen -y -f <path+keyname > ~/.ssh/id_rsa.pub
LOGS: any /var/log
לדעת
את הכתובת של
כל NODE: kubectl get nodes -o wide
בדיקת
קישוריות/תקשורת
בין פודים בCLUSTER:
נכנסים לPOD ועושים CURL לפי הSVC שלו. לדוגמא
Kubectl exec -it <frontend pod> -n react -- /bin/bash
Curl http://backend:80
מאחר ורואים
שהכתובת
הפנימיתצ של הCLUSTER לפי
הSVC: backend.react.svc.cluster.local:80
לפי זה: <name of svc>.<namespace>.cluster.local:80
To see how ingress interacts with application routes/paths use : kubectl logs <ingress pod name>
גילויי קבצי
קונפיגורציה : cat /etc/systemd/system/kubelet.service
או systemctl cat kubelet
Kubectl config view : מציג מידע על הקלאסטר
הצגת לוג מאתמול: journalctl -u <service name> --since “yesterday”
Journalctl -p err -b -o verbose
בכל
אוטומציה
אפשר לשים set -e שיעצור
את ההתקנה כל
פעם שיש ERROR
DOCKER: check version always. Otherwise dockerfile won’t build
Tip- לדעת איזה גרסאות של REQUIREMENTS TXT, pip list מציג
Shutdown Vmmem
process of docker desktop: (in powershell: wsl –shutdown)
In Linux instances, you can install the
'stress' package and run stress to load the system for certain period of time and see if ASG kicks in by adding additional
capacity (= more instances).
For example: sudo stress --cpu 100
--timeout 20
DEBUGGING DOCKER or Angular
Use ng serve – it allows debugging mode
Instead of ng build -which is suited for production