DevOps Bootcamp Notes 2023 Edition
DevOps Bootcamp Notes 2023 Edition
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
2
https://insights.stackoverflow.com/survey/2019
Why Linux?
https://docs.ansible.com/ansible/latest/user_guide/windows_faq.html
Kubernetes Documentation
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Linux Basics
• Linux CLI
• VI Editor
• Package Management
• Service Management
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
just enough
LINUX
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Shell Types
echo $SHELL Broune Shell (Sh Shell)
/bin/bash
Z Shell (zsh)
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Basic Commands
echo Hi
Print to screen
Hi
ls
List files & folders
File.txt my_dir1 file2.conf
pwd
Present Working Directory
/home/my_dir1
mkdir –p /tmp/asia/india/bangalore
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Commands - Files
touch new_file.txt
Create a new file (no contents)
Hi
cat new_file.txt
View contents of file
This is some sample contents
© Copyright KodeKloud
just a bit more
LINUX
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
User Accounts
whoami
matthew
matthew
id
uid=1001(matthew) gid=1001(matthew) groups=1001(matthew)
su aparna
Password:
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
14
User Accounts
ls /root
ls: cannot open directory /root: Permission denied
matthew root
sudo ls /root SUDO
anaconda-ks.cfg initial-setup-ks.cfg /etc/sudoers
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
15
Download Files
curl http://www.some-site.com/some-file.txt -O
some-file.txt
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check OS Version
ls /etc/*release*
/etc/centos-release /etc/os-release /etc/system-release
/etc/centos-release-upstream /etc/redhat-release /etc/system-release-cpe
cat /etc/*release*
CentOS Linux release 7.7.1908 (Core)
Derived from Red Hat Enterprise Linux 7.7 (Source)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
• Wget
• Curl
• Cat /etc/*release*
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
18
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
Package Managers
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
RPM (Red Hat Package Manager)
rpm –i telnet.rpm Install Package
?
?
? RPM
? telnet.rpm
ansible
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
YUM
yum install ansible Install Package
/etc/yum.repos.d
PyYAML
YUM
python RPM
ansible
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
sshpass
YUM Repos
yum repolist
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10097
extras/7/x86_64 CentOS-7 - Extras 341
mongodb-org-4.2/7 MongoDB Repository 25
mysql-connectors-community/x86_64 MySQL Connectors Community 141
mysql-tools-community/x86_64 MySQL Tools Community 105
mysql80-community/x86_64 MySQL 8.0 Community Server 161
updates/7/x86_64 CentOS-7 - Updates 1787
ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Media.repo mysql-community.repo
CentOS-CR.repo CentOS-Sources.repo mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-fasttrack.repo mongodb-org-4.2.repo
cat /etc/yum.repos.d/CentOS-Base.repo
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
YUM
yum list ansible
Installed Packages
ansible.noarch 2.9.6-1.el7 @epel
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Labs
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
service httpd start Start HTTPD service
Or
systemctl start httpd Start HTTPD service
/etc/systemd/system
curl http://localhost:5000
Hello, World!
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
/usr/bin/python3 /opt/code/my_app.py
/usr/bin/python3 /opt/code/my_app.py my_app.service
* Serving Flask app "my_app" (lazy loading)
* Environment: production [Service]
WARNING: This is a development server. Do not use it in a production deployment. ExecStart=
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
systemctl daemon-reload
curl http://localhost:5000
Hello, World!
systemctl start my_app
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
curl http://localhost:5000
Hello, World!
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
Networking Basics
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Networking Pre-Requisite
• Switching
• Routing
• Default Gateway
• DNS Configuration on Linux
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Switching ??
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ip link ip link
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
fq_codel state UP mode DEFAULT group default qlen 1000 fq_codel state UP mode DEFAULT group default qlen 1000
ip addr add 192.168.1.10/24 dev eth0 ip addr add 192.168.1.11/24 dev eth0
ping 192.168.1.11
© Copyright KodeKloud
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Routing ??
192.168.1.1 192.168.2.1
192.168.1.1 192.168.2.1
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.1 192.168.2.1
172.217.194.0
INTERNET
216.134.45.0
INTERNET
16.44.53.0
192.168.1.1 192.168.2.1
ip
iproute
routeadd
add172.217.194.0/24 via 192.168.2.1
default via 192.168.2.1
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
© Copyright KodeKloud
172.217.194.0
0.0.0.0 192.168.2.1
192.168.2.1 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
default
192.168.2.0 192.168.2.1
0.0.0.0 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
Default Gateway INTERNET
172.217.194.0
INTERNET
216.134.45.0
INTERNET
16.44.53.0
192.168.2.1
192.168.1.1
192.168.2.2
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0
default 192.168.2.1
192.168.2.1 255.255.255.0
255.255.255.0 UG 0 0 0 eth0
© Copyright K odeK l oud 192.168.1.0 192.168.2.2 255.255.255.0 UG 0 0 0 eth0
??
192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5
ping 192.168.2.5
Connect: Network is unreachable
ip route add 192.168.2.0/24 via 192.168.1.6 ip route add 192.168.1.0/24 via 192.168.2.6
ping 192.168.2.5
© Copyright K odeK l oud
A eth0 192.168.1.0 eth0 B eth1
192.168.2.0
eth0 C
192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5
cat /proc/sys/net/ipv4/ip_forward
0
/etc/sysctl.conf
.6 echo 1 > /proc/sys/net/ipv4/ip_forward …
net.ipv4.ip_forward = 1
1 …
ping 192.168.2.5
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
© Copyright KodeKloud
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Take Aways
ip link
ip addr
ip route route
cat /proc/sys/net/ipv4/ip_forward
1
© Copyright KodeKloud
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
Introduction
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
About Java
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Install Java
wget https://download.java.net....
openjdk-13.0.2_linux-x64_bin.tar.gz
java
ls jdk-13.0.2/bin
jaotc javadoc jdeprscan jinfo jps jstatd rmiregistry
jar javap jdeps jjs jrunscript keytool serialver
jarsigner jcmd jfr jlink jshell pack200 unpack200
java jconsole jhsdb jmap jstack rmic
javac
© Copyright jdb
KodeKloud jimage. jmod jstat rmid Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Before v9
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
After v9
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
Build
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Compile
MyClass.java
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Compile
MyClass.java Machine Code
public class MyClass { 01101000 10111100 10000001
public static void main(String[] args) { 01100100 01011100 00010111
System.out.println("Hello World"); 00001010 00001110 11111010
}
10110001 01101000 10111100
} Compiler
10000001 01100100 01011100
00010111 00001010 00001110
11111010 10110001 10110001
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Java Virtual Machine
Dependency 1 Service1.class
Dependency 2 Service2.class
Dependency 3
Utility.class
Tools.class
Java Archive
(JAR)
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Package
META-INF/MANIFEST.MF
MyClass.class
Dependency 3
Utility.class
Tools.class
Image 1
Java Archive Web Archive
Image 2 HTML 1 (JAR) (WAR)
HTML 2
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Build Process
javac MyClass.java
jar cf MyClass.jar ..
javadoc MyClass.java
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Build Process
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Build Tools
2.Package
3.Document
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
ant compile jar
ANT
BUILD SUCCESSFUL build.xml
Total time: 2 seconds
<?xml version="1.0"?>
<project name="Ant" default="main" basedir=".">
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile">
javac MyClass.java <javac srcdir="/app/src" destdir="/app/build">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="/app/src" destdir="/app/docs">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="/app/src">
javadoc MyClass.java <include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar basedir="/app/build" destfile="/app/dist/MyClass.jar" >
<manifest>
jar cf MyClass.jar .. <attribute name="Main-Class" value="MyClass" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
© Copyright KodeKloud </target>
Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
</project>
Maven
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://github.com/shopizer-ecommerce/shopizer
Gradle
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://github.com/arun-gupta/docker-java-sample
Summary
• Java
• Java Runtime Environment
• Java Development Kit
• Compiling a Java application
• Packaging a given application to JARs
• What are Build Tools?
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
JavaScript
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://enonic.com/blog/websites-past-and-present
NodeJS
const a = 10, b = 5;
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Node Package Manager (NPM)
• Files
• Web Servers
• Databases
• Security
• Many More
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://www.npmjs.com/
NPM Commands
npm -v
6.13.7
app.js my_application
var file = require("file");
node_modules
file.mkdirs("/tmp/dir1") file
LICENSE
README.md
node -e "console.log(module.paths)"
package.json
[ '/app/node_modules', '/node_modules' ]
lib
npm install file -g app.js
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Common Modules
ls /usr/lib/node_modules/npm/node_modules/ ls /usr/lib/node_modules/
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
package.json
Application Dependencies
{
"name": "example-contentful-theExampleApp-js",
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "^1.18.2",
"contentful": "^6.0.0",
"cookie-parser": "~1.4.3",
"dotenv": "^5.0.0",
"execa": "^0.9.0",
"express": "^4.16.2",
"helmet": "^3.11.0",
"lodash": "^4.17.5",
"marked": "^0.3.16",
"morgan": "^1.9.1",
"pug": "~2.0.0-beta6"
}
}
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python
• Free
• Open source
• Cross Platform Compatible
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Download
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://www.python.org/downloads/
Versions
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Install
yum install python2 yum install python36
python2 python3
Python 2.7.16 (default, Nov 17 2019, 00:07:27) Python 3.6.8 (default, Nov 21 2019, 19:31:34)
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux2 [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" Type "help", "copyright", "credits" or "license"
for more information. for more information.
>>> exit() >>> exit()
python2 -V python3 -V
Python 2.7.16 Python 3.6.8
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Commands
Hello World
def print_message():
print("Hello World")
if __name__ == '__main__':
print_message()
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
© Copyright KodeKloud
just enough
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Package Manager (pip)
python2 -V python3 -V
Python 2.7.16 Python 3.6.8
pip2 -V pip3 -V
pip 9.0.3 from /usr/lib/python2.7/site-packages pip 9.0.3 from /usr/lib/python3.6/site-packages
(python 2.7) (python 3.6)
pip -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Package Manager (pip)
pip install flask
usr
lib
python2.7
site-packages
Python3.6
site-packages
lib64
python2.7
site-packages
Flask-1.1.1.dist-info
python3.6
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
site-packages
Python Package Manager (pip)
pip install flask
'/usr/lib/python2.7/site-packages' site-packages
Requirements
requirements.txt
pip install flask
Flask
Flask==0.10.1
pip install jinja2
Jinja2
Jinja2==2.7.3
pip install markupsafe
MarkupSafe
MarkupSafe==0.23
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Upgrade/Uninstall Package
</>
</>
© Copyright KodeKloud
Git
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout
Explore nature
in Canada.
See more
👩🏼💻
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local
👩🏼💻
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local
Explore nature
Explore nature in Canada.
Visit Canada’s lakes and
in Canada. mountains.
👩🏼💻
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local
Explore nature
Explore nature in Canada.
Visit Canada’s lakes and
in Canada. mountains.
🤷🏼
🤦🏼
👩🏼💻
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Git
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Content tracker
Git
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact About
Explore nature
in Canada. New state of your website with
Visit Canada’s lakes and
mountains.
the local changes
See more
Explore nature
Hosted state of your website
in Canada.
See more
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Fixed button CSS
@ma 🙋🏽 12.23AM
x
@ma 🙋🏽
Fixed buttons in navigation x 10.45AM
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout
Explore nature
in Canada.
Visit Canada’s lakes and
mountains.
See more
Change background
Explore nature
in Canada.
Added front page
See more
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout
Explore nature
in Canada.
Visit Canada’s lakes and
mountains.
See more
Change background
Explore nature
in Canada.
Added front page
See more
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout
Explore nature
in Canada.
Visit Canada’s lakes and
mountains.
See more
Change background
Explore nature
in Canada.
Added front page
See more
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com
Explore nature
in Canada.
See more
Explore nature
in Canada.
Visit Canada’s lakes and
Explore nature
in Canada.
mountains.
See more
Change background Fixed button typo See more
Explore nature
in Canada.
Added front page
See more
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com
Explore nature
in Canada.
See more
Explore nature
in Canada.
Visit Canada’s lakes and
Explore nature
in Canada.
mountains.
See more
Change background Fixed button typo See more
Explore nature
in Canada.
Added front page
See more
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository
Local Repository
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Remote Repository
<html>
<body>
<h1>My Website!</h1>
</body>
</html>
Local Repository
Local Repository
👱🏾
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository
<html>
<body>
<h1>My Website!</h1>
</body>
</html>
Local Repository
Local Repository
👱🏾
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository
<html>
<body>
<h1>My Website!</h1>
</body>
</html>
Local Repository
Local Repository
👱🏾
<html>
<body>
👩🏽 <html>
<body>
<h1>My Website!</h1>
<h1>My Website!</h1>
<p>This is some more text!</p>
</body>
</body>
</html>
</html>
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository
<html>
<body>
<h1>My Website!</h1>
</body>
</html>
Local Repository
Local Repository
👱🏾
<html>
<body>
👩🏽 <html>
<html>
<body>
<body>
<h1>My
<h1>MyWebsite!</h1>
Website!</h1>
<h1>My Website!</h1>
<p>This
<p>Thisisissome
somemore
moretext!</p>
text!</p>
</body>
</body>
</body>
</html>
</html>
</html>
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository
<html>
<html>
<body>
<body>
<h1>My Website!</h1>
<h1>My Website!</h1>
<p>This is some more text!</p>
</body>
</body>
</html>
</html>
Local Repository
Local Repository
👱🏾
<html>
<body>
👩🏽 <html>
<html>
<body>
<body>
<h1>My
<h1>MyWebsite!</h1>
Website!</h1>
<h1>My Website!</h1>
<p>This
<p>Thisisissome
somemore
moretext!</p>
text!</p>
</body>
</body>
</body>
</html>
</html>
</html>
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Fixed button CSS
@ma 🙋🏽 commit
x
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository
story2.txt
story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
$ git init
Initialized empty Git repository in
/Users/lydiahallie/Desktop/myproject/.git/
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
$ ls -a
. .. .git
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
$ touch story1.txt
$ echo "This is a beautiful story" >> story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
$ git status
On branch master
No commits yet
Untracked files:
story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
story1.txt
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Added first story
@ 🙋🏼
me
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
$ git log
commit 67c833e3…ecb7df62f (HEAD -> master)
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
https://.../.../[name].git
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
https://.../.../[name].git
Remote Repository
Local Repository
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
$ git remote -v
origin https://.../.../[name].git (fetch)
origin https://.../.../[name].git (push)
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Local Repository
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Added fifth story
@ 🙋🏼
me
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
$ cd remote-repo
$ git log
commit 67c833e3…ecb7df62f (HEAD -> origin/master)
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Pull Request
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
sarah max
@ma
Added second story @sarah 👩🏽💻 Added third story
x 🧔🏻
🧔🏻
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
origin/master
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md fourth_story.md
sarah max
@ma
Started fourth story @sarah 👩🏽💻 Started fourth story
x 🧔🏻
master
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
sarah max
@ma
Started fourth story @sarah 👩🏽💻 Started fourth story
x 🧔🏻
master
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
master sarah max
@ma
Started fourth story @sarah 👩🏽💻 Started fourth story
x 🧔🏻
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md fourth_story.md
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md
## Fourth Story
<<<<<<<< HEAD
This is Sarah’s version
=======
This is Max’s version
>>>>>>> max
of the fourth story!
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md
## Fourth Story
<<<<<<<< HEAD
This is Sarah’s version
=======
This is Max’s version
>>>>>>> max
of the fourth story!
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash
@ma
Merge max into master
x 🧔🏻
master sarah max
@ma
Started fourth story @sarah 👩🏽💻 Started fourth story
x 🧔🏻
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Why Jenkins?
Challenges
• Slower Releases
• Manual Builds Manual Builds
• Non-repeatable processes
• No Automations
Non-repeatable No automations
processes
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Why Jenkins?
Solution
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Free!
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Plugins
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Enterprise Options
Support
Managed
Service
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn
Continuous Deployment
Continuous Deployment is an automated process in which the
code is taken from the repository and deployed to the system.
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Continuous Integration and
Continuous Delivery/Deployment (CICD)
• CI – Continuous Integration
• CD – Continuous Delivery
• CD – Continuous Deployment
CI CD CD
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
The Key Pieces of CI
Unit tests
Integration tests
CD CD
CI CI
CD process
System
CD
Ubuntu 20.04
https://www.jenkins.io/doc/book/installing/linux/
© Copyright K odeK l oud
Install Jenkins on Ubuntu
Step 1: Install Java on Ubuntu Step 3: Once the key is added with no
errors, append the Debian package
$ sudo apt update repository address
$ sudo apt sudo apt install openjdk-8-jdk
$ sudo sh -c 'echo deb
Alternatively, install version 11: http://pkg.jenkins.io/debian-stable
$ sudo apt install openjdk-11-jdk binary/ >
/etc/apt/sources.list.d/jenkins.list’
Confirm the download by pressing Y and
Enter Step 4: Run update to use new repository
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Plugins
For example, you want to connect to Azure from Jenkins you would need to download Azure Plugin which
will allow you to connect to Azure at a programmatic level.
Similarly, we can have other integrations with AWS, GitHub, etc using plugins.
Azure Plugin
AWS Plugin
Jenkins
To restart Jenkins
$ sudo systemctl restart jenkins
OR
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Update Plugins
To update any existing plugin in Jenkins
1) Go to Manage Jenkins -> Manager Plugins
2) Click Updates and search for the desired plugin.
3) Select the desired plugin and Install.
Note: Few plugins may need a restart
To restart Jenkins
$ sudo systemctl restart jenkins
OR
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Delete Plugins
To delete any plugin in Jenkins
1) Go to Manage Jenkins -> Manager Plugins
2) Go to Installed and search for the desired plugin.
3) Click on uninstall button for the plugin you want to delete.
Click yes to proceed with the deletion.
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn
2) Pipeline
This is used to create a pipeline
3) Multi-configuration project
This is great if you need a large number of Jenkins configurations if you need multiple environments
like Dev/ UAT.
4) Folder
This creates containers and stores nested items. It is useful in grouping, creating a namespace, etc.
5) Organisation folder
Creates a multibranch project for all different subfolders that are available.
6) Multibranch Pipeline
It sets up pipeline projects for different repositories.
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Administering Jenkins
Scale Manage
© Copyright K odeK l oud
Backup and Restore
Full
Snapshots
Backup
$JENKINS_HOME
1) Using Plugins
2) Using custom shell script
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Backup Jenkins
To backup Jenkins using a plugin, you will first need to install a backup plugin.
Some of the most commonly used plugins are ThinBackup, Periodic Backup,
Google cloud Backup.
For backing up using any of these plugins there are a few general steps that
must be followed:
1) Creating a backup directory with read and write access
2) Selecting files that need backup
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn
Components of Jenkinsfile:
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
What Is A Jenkinsfile?
Instructions
Templates
Jenkinsfile
Instructions
Templates
Jenkinsfile
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Dev Staging Prod
Jenkinsfile
Jenkinsfile
© Copyright K odeK l oud
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn
➢ Docker Swarm
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
➢ Docker vs Kubernetes
docker
overview
• Compatibility/Dependency
• Long setup time
• Different Dev/Test/Prod
environments
The Matrix from Hell !!
Libraries Dependencies
OS
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What can it do?
Container Container Container Container
Applications
• Run each service with its
own dependencies in
separate containers
Docker
?
OS
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What are containers?
Docker
OS Kernel
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Operating System
OS
OS Kernel
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Sharing the kernel
Docker
OS - Ubuntu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Containers vs Virtual Machines
✓
✓
GB ✓
✓ MB
✓ ✓
Utilization Size Boot up Utilization Size Boot up
Docker
Hypervisor
OS
Docker Docker
OS OS
Hypervisor
OS
Hardware Infrastructure
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
How is it done? Public Docker registry - dockerhub
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Container vs image
Docker Container #1
Docker Image
App.war
Docker Image
Guide
DockerFile
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
Getting Started
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition
Linux Cloud
MAC Windows
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
d e m o
Install Docker
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
ps – list containers
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
STOP – stop a container
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Exited (0) 3 seconds ago silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Rm – Remove a container
docker rm silly_sammet
silly_sammet
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
images – List images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f68d6e55e065 4 days ago 109MB
redis latest 4760dc956b2d 15 months ago 107MB
ubuntu latest f975c5035748 16 months ago 112MB
alpine latest 3fd9065eaf02 18 months ago 4.14MB
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
rmi – Remove images
docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Deleted: sha256:f68d6e55e06520f152403e6d96d0de5c9790a89b4cfc99f4626f68146fa1dbdc
Deleted: sha256:1b0c768769e2bb66e74a205317ba531473781a78b77feef8ea6fd7be7f4044e1
Deleted: sha256:34138fb60020a180e512485fb96fd42e286fb0d86cf1fa2506b11ff6b945b03f
Deleted: sha256:cf5b3c6798f77b1f78bf4e297b27cfa5b6caa982f04caeb5de7d13c255fd7a1e
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Pull – download an image
docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
fc7181108d40: Already exists
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest
docker ps
docker ps -a
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu
docker ps
docker ps -a
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Append a command
docker run ubuntu
5
4
3
2
1
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Exec – execute a command
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
538d037f94a7 ubuntu "sleep 100“ 6 seconds ago Up 4 seconds distracted_mcclintock
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – attach and detach
docker run kodekloud/simple-webapp
This is a sample web application that displays a colored background.
* Serving Flask app "app" (lazy loading)
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
run
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – tag
docker run ubuntu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – attach and detach
docker run mmumshad/simple-webapp
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
RUN - STDIN
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – PORT mapping
docker run mmumshad/simple-webapp
http://192.168.1.5:80
80 8000 8001
IP: 192.168.1.5
http://172.17.0.2:5000 Internal IP
5000 5000 5000
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
RUN – Volume mapping
docker run mysql
Data
docker run –v /opt/datadir:/var/lib/mysql mysql /var/lib/mysql
/opt/datadir
MYSQL
Docker Container
Docker Host
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
images
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What am I containerizing?
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
How to create my own image?
Dockerfile
COPY . /opt/source-code
4. Install Python dependencies using pip
INSTRUCTION ARGUMENT
Dockerfile
Start from a base OS or
FROM Ubuntu another image
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Docker build output
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
failure
docker build Dockerfile –t mmumshad/my-custom-app
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What can you containerize?
Containerize Everything!!!
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py
import os
from flask import Flask
app = Flask(__name__)
…
…
color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)
if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")
python app.py
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py
import os
from flask import Flask
app = Flask(__name__)
…
…
color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)
if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py
import os
from flask import Flask
app = Flask(__name__)
…
…
color = os.environ.get('APP_COLOR')
"red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)
if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")
app.py
import os
from flask import Flask
app = Flask(__name__)
…
…
os.environ.get('APP_COLOR')
color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)
if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")
simple-webapp-color
docker run -e APP_COLOR=blue
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
ENV Variables in Docker
docker run -e APP_COLOR=blue simple-webapp-color
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
CMD
vs
ENT RYPOINT
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
??
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu [COMMAND]
5
4
3
2
1
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu
CMD sleep 5
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu
docker run ubuntu-sleeper sleep 10
CMD sleep 5
Command at Startup: sleep 10
FROM Ubuntu
docker run ubuntu-sleeper 10
10
sleep
ENTRYPOINT [“sleep”]
Command at Startup:
docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.
Command at Startup:
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.
ENTRYPOINT [“sleep”]
CMD [“5”]
Command at Startup:
Command at Startup:
sleep2.0
docker run --entrypoint sleep2.0 ubuntu-sleeper 10 10
© Copyright K odeK l oud Command at Startup: Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
engine
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Docker Engine
Docker Engine Laptop
Docker CLI
REST API
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
containerization
Unix
Process ID
Timesharing
InterProcess
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Namespace - PID
Linux System
PID : 1
PID : 2
PID : 3
Child System (Container)
PID : 4
PID : 5 PID : 1
PID : 6 PID : 2
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
cgroups
Linux System
CPU Memory
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
storage
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
File system
/var/lib/docker
aufs
containers
image
volumes
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Layered architecture
Dockerfile Dockerfile2
FROM Ubuntu FROM Ubuntu
RUN apt-get update && apt-get –y install python RUN apt-get update && apt-get –y install python
RUN pip install flask flask-mysql RUN pip install flask flask-mysql
Read Write
Container Layer
Layer 6. Container Layer
Read Only
Layer 5. Update Entrypoint with “flask” command
Layer 4. Source code
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker build Dockerfile –t mmumshad/my-custom-app
COPY-ON-WRITE
Read Write
Container Layer
temp.txt
Read Only
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
volumes docker run –v data_volume:/var/lib/mysql mysql
/var/lib/mysql /var/lib/mysql
data_volum
e mysql
/var/lib/docker/volumes /data
Read Only
mysql – image layer
© Copyright K odeK l oud Docker Host Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Storage drivers
• AUFS
• ZFS
• BTRFS
• Device Mapper
• Overlay
• Overlay2
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
networking
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Default networks
Bridge none host
docker run ubuntu docker run Ubuntu –-network=none docker run Ubuntu --network=host
5000 5000
Web Web
Container Container
172.17.0.4 172.17.0.5
182.18.0.2 docker network ls
Web Web
Container Container
Docker Host
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Network Inspect
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Embedded DNS
Host IP
mysql.connect( 172.17.0.3
mysql ) web mysql web 172.17.0.2
Container Container
172.17.0.2 172.17.0.3 mysql 172.17.0.3
docker0
DNS
Server
127.0.0.11
Docker Host
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
registry
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image
image: nginx
Image/
Repository
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image
image: nginx/nginx
User/ Image/
Account Repository
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker.io
Docker Hub
Image
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Private Registry
docker login private-registry.io
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com to create one.
Username: registry-user
Password:
WARNING! Your password will be stored unencrypted in /home/vagrant/.docker/config.json.
Login Succeeded
© Copyright KodeKloud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Deploy Private Registry
docker run -d -p 5000:5000 --name registry registry:2
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Course Structure
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
How to attend this course?
Lectures
Demos
Quizzes
Lab Exercises
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Labs
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Objectives
⮚Kubernetes Overview
⮚Containers – Docker
⮚Container Orchestration?
⮚Demo - Setup Kubernetes
⮚Kubernetes Concepts – PODs | ReplicaSets | Deployment | Services
⮚Networking in Kubernetes
⮚Kubernetes Management - Kubectl
⮚Kubernetes Definition Files - YAML
⮚Kubernetes on Cloud – AWS/GCP
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubernetes or K8s
Container + Orchestration
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Containers
mumshad mannambeth
Why do you need containers?
Web Server Database Messaging Orchestration
Compatibility/Dependency
Long setup time
Different Dev/Test/Prod
environments
OS
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
What can it do?
Containe Containe Containe Containe
Containerize Applications r r r
r
Web Server Database Messaging Orchestration
Run each service with its own
dependencies in separate containers
Docker
?
OS
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
What are containers?
OS Kernel
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Operating system
OS
OS Kernel
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Sharing the kernel
Docker
OS - Ubuntu
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Containers vs Virtual Machines
✔
✔
GB ✔ ✔
✔ ✔
MB
✔ ✔
Utilizatio Size Boot Utilizatio Size Boot
n up n up
Virtual Virtual
Containe Containe
Machine Machine
Application Application r r
Application Application
Libs Deps Libs Deps
OS OS Libs Deps Libs Deps
Hypervisor Docker
OS OS
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container vs image
Docker Container #1
Docker
Image
Package
Docker Container #2
Templat
e
Plan
Docker Container #3
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container Advantage
App.wa
r
Docker Image
Guide
DockerFile
Developer Operations
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
More about containers
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container
Orchestration
mumshad mannambeth
Container Orchestration
Orchestration
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container orchestration
Orchestration
MySQL
Container
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Orchestration Technologies
Docker Swarm
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Kubernetes Advantage
Orchestration
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
And that is kubernetes..
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Architecture
mumshad mannambeth
Nodes (Minions)
Node
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Master
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Components
Container
API Key-value
Controller
Scheduler
kubelet
Kube
etcd store
Runtime
Server
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Master vs Worker Nodes
etcd
controller
scheduler
Container Runtime
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubectl
kubectl run hello-minikube
kubectl cluster-info
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
mumshad mannambeth
Minikube Google Cloud Platform play-with-k8s.com
MicroK8s Amazon Web Services
Kubeadm
Microsoft Azure
Setup Kubernetes
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Minikube
</> kube-apiserver </> kubelet
etcd
node-controller
replica-controller
Container Runtime
Minikube
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Minikube
Minikube.exe
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
minikube
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD
mumshad mannambeth
Assumptions
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD
Node Node
Kubernetes Cluster
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Multi-Container PODs
Network Helper
Containers
POD
Node
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
PODs Again!
docker run python-app
POD
Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
POD
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
YAML
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
YAML in Kubernetes
pod-definition.yml
apiVersion: v1 String Kind Version
kind: Pod String
metadata:
POD v1
metadata:
name: myapp-pod Service v1
name: myapp-pod
labels:
labels: Dictionary ReplicaSet apps/v1
app: myapp
app: myapp
type: front-end Deploymen apps/v1
spec: t
containers: List/Arra
- name: nginx-container
y
image: nginx
© Copyright KodeKloud
Replication
Controller
mumshad mannambeth
High Availability
Node Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Load Balancing & Scaling
Node Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Replication Controller Replica Set
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
rc-definition.yml pod-definition.yml
apiVersion: v1 apiVersion: v1
kind: ReplicationController kind: Pod
metadata: Replication Controller
name: myapp-rc metadata:
labels: name: myapp-pod
app: myapp labels:
type: front-end app: myapp
type: front-end
spec: Replication Controller
template: spec:
containers:
POD - name: nginx-container
image: nginx
POD
> kubectl create –f rc-definition.yml
POD replicationcontroller “myapp-rc” created
POD
> kubectl create –f replicaset-definition.yml
replicaset "myapp-replicaset" created
POD POD
POD POD
POD POD
POD
POD
POD
POD POD
POD
POD
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
replicaset-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp POD tier: front-end
type: front-end
spec:
template:
metadata:
name: myapp-pod
POD POD
labels: tier: front-end tier: front-end
app: myapp
Template
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
replicaset-definition.yml
> kubectl delete replicaset myapp-replicaset *Also deletes all underlying PODs
> kubectl replace -f replicaset-definition.yml
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
ReplicaSet
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
ReplicaSet as an Horizontal Pod Autoscaler Target
https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#replicaset-as-an-
horizontal-pod-autoscaler-target
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Deployment
mumshad mannambeth
Deployment v1 v2
Replica Set
Deployment
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
deployment-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
Deployment
metadata:
Definition name: myapp-deployment
labels:
app: myapp
> kubectl create –f deployment-definition.yml type: front-end
deployment "myapp-deployment" created spec:
template:
> kubectl get deployments metadata:
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE name: myapp-pod
myapp-deployment 3 3 3 3 21s labels:
app: myapp
> kubectl get replicaset type: front-end
NAME DESIRED CURRENT READY AGE spec:
containers:
myapp-deployment-6795844b58 3 3 3 2m
- name: nginx-container
image: nginx
> kubectl get pods
NAME READY STATUS RESTARTS AGE
replicas: 3
myapp-deployment-6795844b58-5rbjl 1/1 Running 0 2m selector:
myapp-deployment-6795844b58-h4w55 1/1 Running 0 2m matchLabels:
myapp-deployment-6795844b58-lfjhv 1/1 Running 0 2m
type: front-end
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
commands
> kubectl get all
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/myapp-deployment 3 3 3 3 9h
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Deployment
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Deployment
Updates and Rollback
mumshad mannambeth
Rollout and Versioning
Revision 1
nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0
Revision 2
nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Rollout Command
> kubectl rollout status deployment/myapp-deployment
Waiting for rollout to finish: 0 of 10 updated replicas are available...
Waiting for rollout to finish: 1 of 10 updated replicas are available...
Waiting for rollout to finish: 2 of 10 updated replicas are available...
Waiting for rollout to finish: 3 of 10 updated replicas are available...
Waiting for rollout to finish: 4 of 10 updated replicas are available...
Waiting for rollout to finish: 5 of 10 updated replicas are available...
Waiting for rollout to finish: 6 of 10 updated replicas are available...
Waiting for rollout to finish: 7 of 10 updated replicas are available...
Waiting for rollout to finish: 8 of 10 updated replicas are available...
Waiting for rollout to finish: 9 of 10 updated replicas are available...
deployment "myapp-deployment" successfully rolled out
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Deployment Strategy
nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1
Recreat
e Application
Down
Rolling nginx:1.7.1
nginx:1.7.0 nginx:1.7.1 nginx:1.7.0 nginx:1.7.1 nginx:1.7.0 nginx:1.7.1 nginx:1.7.0
Updat nginx:1.7.0 nginx:1.7.1
e
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
deployment-definition.yml
apiVersion: apps/v1
kind: Deployment
metadata:
Kubectl apply name: myapp-deployment
labels:
app: myapp
> kubectl apply –f deployment-definition.yml type: front-end
deployment "myapp-deployment" configured spec:
template:
metadata:
> kubectl set image deployment/myapp-deployment \ name: myapp-pod
nginx-container=nginx:1.9.1 labels:
deployment "myapp-deployment" image is updated app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx:1.7.1
replicas: 3
selector:
matchLabels:
type: front-end
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Recreate RollingUpdate
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Upgrades
POD POD POD POD POD POD POD POD POD POD
Deployment
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Rollback
> kubectl get replicasets > kubectl get replicasets
NAME DESIRED CURRENT READY AGE NAME DESIRED CURRENT READY AGE
myapp-deployment-67c749c58c 0 0 0 22m myapp-deployment-67c749c58c 5 5 5 22m
myapp-deployment-7d57dbdb8d 5 5 5 20m myapp-deployment-7d57dbdb8d 0 0 0 20m
POD POD POD POD POD POD POD POD POD POD
Deployment
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubectl run
> kubectl run nginx --image=nginx
deployment "nginx" created
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Summarize Commands
Create > kubectl create –f deployment-definition.yml
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Deployment
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
mumshad mannambeth
Kubernetes Networking - 101
192.168.1.10
• IP Address is assigned to a POD
192.168.1.2 192.168.1.2
10.244.0.0
10.244.0.2 10.244.0.2
POD POD
Node Node
Kubernetes Cluster
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster Networking Setup
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster Networking
192.168.1.2 192.168.1.3
10.244.1.2 10.244.2.2
POD POD
Node Node
Kubernetes Cluster
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Networking
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Services
mumshad mannambeth
Services
Services
Services
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
192.168.1.2
10.244.0.0
SSH
>curl http://10.244.0.2
>curl http://192.168.1.2 :30008
3000
Hello World!
Service
?
8
Hello World!
10.244.0.2
192.168.1.10
POD
Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Services Types
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
10.244.0.0
>curl http://192.168.1.2:30008
3000
Service
?
8
Hello World!
10.244.0.2
192.168.1.10
POD
Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
2 Port
10.106.1.1
1 TargetPort
3000
3 NodePort Service
80
8
2
Range: 80
30000 - 32767 10.244.0.2
POD
Node
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
service-definition.yml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
2 Port
10.106.1.1
1 TargetPort
3000
3 NodePort Service
80
spec:
8
POD
Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind: Pod
service "myapp-service" created
metadata:
> kubectl get services
name: myapp-service metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name:
ClusterIP
myapp-pod
10.96.0.1 <none> 443/TCP 16d
spec: labels:
myapp-service
NodePort 10.106.127.123 <none> 80:30008/TCP 5m
type: NodePort app: myapp
ports: type: front-end
> curl http://192.168.1.2:30008
- targetPort: 80 spec:
port: 80 containers:
nodePort: 30008 - name: nginx-container
selector: image: nginx
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
3000
192.168.1.2 8
selector:
Service
app: myapp
Algorithm: Random
SessionAffinity: Yes
labels:
app: myapp
POD POD POD
Node
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
>curl http://192.168.1.2:30008
>curl http://192.168.1.3:30008
>curl http://192.168.1.4:30008
Service
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Service - NodePort
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
ClusterIP
mumshad mannambeth
ClusterIP
10.244.0.3 10.244.0.2 10.244.0.4
back-end
back-end
POD POD POD
redis
10.244.0.8
10.244.0.5 10.244.0.9 10.244.0.10
redis
POD POD POD
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind:
service “back-end" Pod
created
metadata:
> kubectl get services
name: back-end metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name: myapp-pod
ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: back-end labels:
ClusterIP 10.106.127.123 <none> 80/TCP 2m
type: ClusterIP app: myapp
ports: type: back-end
- targetPort: 80 spec:
port: 80 containers:
- name: nginx-container
selector: image: nginx
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
8080
Voting-app-Pod
Not specified in source code.
Default 6379 assumed
6379 apiVersion: v1
Redis kind: Service
Service metadata:
name: redis
spec:
ports:
6379 - port: 6379
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
8080
Voting-app-Pod
7000 apiVersion: v1
Redis kind: Service
Service metadata:
name: some-redis-service
spec:
ports:
6379 - port: 7000
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Service - NodePort
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
References
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Service -
LoadBalancer
mumshad mannambeth
>curl http://192.168.1.2:30008
>curl http://192.168.1.4:30008
Load
Native Balancer
Load Balancer
Service - NodePort
Service - ClusterIP
metadata:
> kubectl get services
name: front-end
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: front-end LoaBalancer 10.106.127.123 <Pending> 80/TCP 2m
type: NodePort
LoadBalancer
ports:
- targetPort: 80
port: 80
selector:
app: myapp
type: front-end
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Microservices
mumshad mannambeth
Example voting app
app.py
80 server.js 80
Service Service
POD POD
Goals:
voting-app result-app
1. Deploy Containers
2. Enable Connectivity
3. External Access
POD POD
redis postgres
Service
Service
Steps:
1. Deploy PODs 6379 5432
2. Create Services (ClusterIP)
1. redis
2. db
3. Create Services (NodePort)
program.cs POD
1. voting-app worker
2. result-app
POD POD
voting-app result-app
kodekloud/examplevotingapp_vote:v1 kodekloud/examplevotingapp_result:v1
Service
Service
Steps:
1. Deploy PODs
2. Create Services (ClusterIP)
1. redis
2. db
3. Create Services (NodePort) POD
1. voting-app worker
2. result-app
kodekloud/examplevotingapp_worker:v1
Example voting app
Service Service
POD POD
voting-app result-app
POD POD
redis db
Service
Service
POD
worker
Example voting app
Service Service
Deployment Deployment
POD POD
Service
Service
redis db
Deployment Deployment
POD
worker
Deployment
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud
Ansible
For the
Absolute Beginner
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
The
RedHat Ansible for Beginners
Curriculum
Introduction to Ansible
Inventory Files
Playbooks
Variables
Conditionals
Loops
Roles
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Hands-On Exercises
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Ansible
Introduction
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Why Ansible?
• Time • Simple
• Coding Skills • Powerful
• Maintenance • Agentless
Scripts
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Scripts vs Ansible Playbook
#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
- hosts: all_my_db_servers
all_my_web_servers_in_DR
all_my_web_servers_on_cloud
localhost
$username=johndoe tasks:
read -s -p "Enter password : " password - user:
egrep "^$username" /etc/passwd >/dev/null name: johndoe
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
useradd -m -p $password $username
[ $? -eq 0 ] && echo "User has been added
to system!" || echo "Failed to add a user!"
fi
fi
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - Simple
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - complex
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - complex
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Ansible
Install
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Control Node
Redhat or CentOS – $ sudo yum install ansible
https://docs.ansible.com/ansible/latest/installation_guide/
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Install Control Node on Redhat or CentOS
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Install via PIP
Install pip if not present
$ sudo yum install epel-release
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Ansible
Inventory
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
inventory
server1.company.com
server2.company.com
[mail]
server3.company.com
server4.company.com
[db]
server5.company.com
server6.company.com
[web]
server7.company.com
server8.company.com
Linux – SSH
Windows – Powershell Remoting
inventory
/etc/ansible/hosts Agentless
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
More on inventory files
#Sample Inventory File
web
server1.company.com
ansible_host= ansible_connection=ssh ansible_user=root
db
server2.company.com
ansible_host= ansible_connection=winrm ansible_user=admin
mail
server3.company.com
ansible_host= ansible_connection=ssh ansible_ssh_pass=P@#
web2
server4.company.com
ansible_host= ansible_connection=winrm
localhost ansible_connection=localhost
Playbooks
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Ansible playbooks
# Simple Ansible Playbook # Complex Ansible Playbook
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Playbook
YAML format
-
name: Play 1
hosts: localhost
tasks:
- name: Execute command ‘date’
command: date
-
name: Play 2
hosts: localhost
tasks:
- name: Install web service
yum:
name: httpd
state: present
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
module
playbook.yml
- ansible-doc -l
name: Play 1
hosts: localhost
tasks:
- name: Execute command ‘date’
command: date
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Run
ansible-playbook playbook.yml
• Execute Ansible Playbook
ansible-playbook --help
• Syntax: ansible-playbook <playbook file name>
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Modules
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
modules
• System - Win_copy
User
Command
Acl
Mongodb
Amazon
- Group
Expect
Archive
Mssql
Win_command
Atomic
• Commands - Hostname
Raw
Copy
Mysql
Win_domain
Azure
- Iptables
Script
File
Postgresql
Win_file
Centrylink
• Files - Lvg
Shell
Find
Proxysql
Win_iis_website
Cloudscale
• Database -
-
Lvol
Lineinfile
vertica
Win_msg
Cloudstack
Make Ocean
Replace
Win_msi
Digital
• Cloud -
-
Mount
Stat
Win_package
Docker
Ping
Template
Win_ping
Google
• Windows - Timezone
Unarchive
Win_path
Linode
- Systemd
Win_robocopy
Openstack
• More.. - Service
Win_regedit
Rackspace
- Win_shell
Smartos
- Win_service
Softlayer
- Win_user
VMware
- And more
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
command
Executes a command on a remote node
playbook.yml
parameter comments -
chdir cd into this directory before running the command name: Play 1
hosts: localhost
creates a filename or (since 2.0) glob pattern, when it already exists, this step tasks:
will not be run. - name: Execute command ‘date’
command: date
executable change the shell used to execute the command. Should be an absolute
path to the executable.
- name: Display resolv.conf contents
free_form the command module takes a free form command to run. There is no command: cat /etc/resolv.conf
parameter actually named 'free form'. See the examples!
- name: Display resolv.conf contents
command: cat resolv.conf chdir=/etc
removes a filename or (since 2.0) glob pattern, when it does not exist, this step
will not be run. - name: Display resolv.conf contents
command: mkdir /folder creates=/folder
warn if command warnings are on in ansible.cfg, do not warn about this
(added in 1.8) particular line if set to no/false.
playbook.yml
-
name: Play 1
hosts: localhost
1. Copy script to remote systems tasks:
2. Execute script on remote systems - name: Run a script on remote server
script: /some/local/script.sh -arg1 -arg2
© Copyright KodeKloud Scripts Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Service
• Manage Services – Start, Stop, Restart
playbook.yml playbook.yml
- -
name: Start Services in order name: Start Services in order
hosts: localhost hosts: localhost
tasks: tasks:
- name: Start the database service - name: Start the database service
service: name=postgresql state=started service:
name: postgresql
state: started
- name: Start the httpd service
service: name=httpd state=started
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
idempotency
Why “started” and not “start”?
“Start” the service httpd ”Started” the service httpd
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
lineinfile
• Search for a line in a file and replace it or add it if it doesn’t exist.
/etc/resolv.conf
nameserver 10.1.250.1 nameserver 10.1.250.10
nameserver 10.1.250.2
playbook.yml script.sh
- #Sample script
name: Add DNS server to resolv.conf
hosts: localhost echo “nameserver 10.1.250.10” >> /etc/resolv.conf
tasks:
- lineinfile:
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'
/etc/resolv.conf
© Copyright KodeKloud
Ansible
Variables
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Variable
• Stores information that varies with each host
inventory
Web1 ansible_host=server1.company.com ansible_connection=ssh ansible_shh_pass=P@ssW
db ansible_host=server2.company.com ansible_connection=winrm ansible_shh_pass=P@s
Web2 ansible_host=server3.company.com ansible_connection=ssh ansible_shh_pass=P@ssW
Playbook.yml variables
- variable1: value1
name: Add DNS server to resolv.conf variable2: value2
hosts: localhost
tasks:
vars:
- lineinfile:
dns_server: 10.1.250.10
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Using variables
Playbook.yml
-
name: Add DNS server to resolv.conf
hosts: localhost
vars:
dns_server: 10.1.250.10
tasks:
- lineinfile:
path: /etc/resolv.conf
line: 'nameserver {{ dns_server }}’
10.1.250.10'
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- #Sample Inventory File
name: Set Firewall Configurations
hosts: web
Web http_port= snmp_port= inter_ip_range=
tasks:
- firewalld:
service: https
permanent: true #Sample variable File – web.yml
state: enabled
http_port: 8081
- firewalld: snmp_port: 161-162
port: 8081
‘{{/tcp
http_port }}’/tcp inter_ip_range: 192.0.2.0
permanent: true
state: disabled
- firewalld:
161-162
port: ‘{{ snmp_port
/udp }}’/udp
permanent: true
state: disabled {{ }}
- firewalld: Jinja2 Templating
source: 192.0.2.0
‘{{ inter_ip_range
/24 }}’/24
Zone: internal
state: enabled source: {{ inter_ip_range }}
Loops
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
LOOPS
- - var: item=joe
name: Create
user: users
name= “{{ item }}” state=present
hosts: localhost
tasks:
- user: name= joe
‘{{ item }}’ state=present
- loop:
user: name=george state=present
- user:
- joename=ravi state=present
- user: name=mani
- george state=present
- user: name=kiran
- ravi state=present
- user: name=jazlan
- mani state=present
- user: name=emaan
- kiran state=present
- user: name=mazin
- jazlan state=present
- user: name=izaan
- emaan state=present
- user: name=mike
- mazin state=present
- user: name=menaal
- izaan state=present
- user: name=shoeb
- mike state=present
- user: name=rani
- menaal state=present
- shoeb
- rani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present
loop: - var: item=
- joe user: name= “{{ item }}” state=present
- george
- ravi - var: item=
- mani user: name= “{{ item }}” state=present
- kiran - var: item=
- jazlan user: name= “{{ item }}” state=present
- emaan
- var: item=
- mazin
user: name= “{{ item }}” state=present
- izaan
- mike - var: item=
- menaal user: name= “{{ item }}” state=present
- shoeb - var: item=
- rani user: name= “{{ item }}” state=present
- var: item=
user: name= “{{ item }}” state=present
- var: item=
© Copyright KodeKloud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
- var: item=
user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present
loop: - var: item=joe
- joe user: name= “{{ item }}” state=present
- george
- ravi - var: item= george
- mani user: name= “{{ item }}” state=present
- kiran - var: item= ravi
- jazlan user: name= “{{ item }}” state=present
- emaan
- var: item= mani
- mazin
user: name= “{{ item }}” state=present
- izaan
- mike - var: item= kiran
- menaal user: name= “{{ item }}” state=present
- shoeb - var: item= jazlan
- rani user: name= “{{ item }}” state=present
- var: item= emaan
user: name= “{{ item }}” state=present
- var: item= mazin
© Copyright KodeKloud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
- var: item= izaan
user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ ???? item }}’ ‘{{ ? }}’
state=present uid=1010
loop: - var: item=joe
-- name:
joe 1010
joe user: name= “{{ item }}” state=present
- uid:
george 1011
1010
- var: item=george
-- name:
ravi george 1012
- uid:
mani 1011 1013 user: name= “{{ item }}” state=present
-- name:
kiran ravi 1014 - var: item=ravi
- uid:
jazlan 1015
1012 user: name= “{{ item }}” state=present
-- name:
emaan mani 1016
- var: item=mani
- uid:
mazin1013 1017
user: name= “{{ item }}” state=present
-- name:
izaan kiran 1018
- uid:
mike 1014 1019 - var: item=kiran
-- name:
menaaljazlan1020 user: name= “{{ item }}” state=present
- uid:
shoeb1015 1021 - var: item=jazlan
-- name:
rani emaan 1022 user: name= “{{ item }}” state=present
uid: 1016 - var: item=emaan
- name: mazin user: name= “{{ item }}” state=present
uid: 1017 - var: item=mazin
- name: izaan
© Copyright K odeK l oud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
uid: 1018 - var: item=izaan
- name: mike user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
item }}’
- user: name=‘{{ ???? ‘{{ ? }}’
state=present uid=1010 - var:
loop: item:
-- name:
joe joe1010
- uid:
george 10101011
-- name:
ravi george 1012 user: name= “{{ ???? }}” state=present uid=“{?}”
- uid:
mani 10111013 - var:
-- name:
kiran ravi 1014 item:
- uid:
jazlan 10121015
-- name:
emaan mani 1016
- uid:
mazin10131017 user: name= “{{ ???? }}” state=present uid=“{?}”
-- name:
izaan kiran 1018
- uid:
mike 10141019 - var:
-- name:
menaaljazlan 1020 item:
- uid:
shoeb10151021
-- name:
rani emaan 1022
uid: 1016 user: name= “{{ ???? }}” state=present uid=“{?}”
- name: mazin - var:
uid: 1017 item:
- name: izaan
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018
- name: mike user: name= “{{ ???? }}” state=present uid=“{?}”
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ ???? item }}’ ‘{{ ? }}’
state=present uid=1010 - var:
loop: item:
-- name:
joe joe1010 name: joe
- uid:
george 10101011 uid: 1010
-- name:
ravi george 1012 user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid }
- uid:
mani 10111013
- var:
-- name:
kiran ravi 1014
item:
- uid:
jazlan 10121015 name: george
-- name:
emaan mani 1016 uid: 1011
- uid:
mazin10131017
user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid
-- name:
izaan kiran 1018
- uid:
mike 10141019 - var:
-- name:
menaaljazlan 1020 item:
- uid:
shoeb10151021 name: ravi
-- name:
rani emaan 1022 uid: 1012
uid: 1016 user: name= ‘{{ “{{item.name
???? }}” }}’ state=present uid=“{?}” ‘{{ item.uid }
- name: mazin - var:
uid: 1017 item:
- name: izaan name: mani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018 uid: 1013
- name: mike user: name=‘{{ “{{ ???? }}”
item.name }}’ state=present uid=“{?}” ‘{{ item.uid }
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name= ‘{{ item }}’
‘{{item.name
???? ‘{{item.uid
}}’ state=present uid=1010
‘{{ ? }}’ }}’ - var:
loop: item:
1010 name: joe
-- name:
joe joe - { name: joe, uid: 1010 }
- uid:
george 1011 uid: 1010
1010
1012 user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid }
-- name:
ravi george - { name: george, uid: 1011 }
- uid:
mani 1011 1013
- var:
1014
-- name:
kiran ravi - { name: ravi, uid: 1012 } item:
- uid:
jazlan 1015 name: george
1012
1016
-- name:
emaan mani - { name: mani, uid: 1013 } uid: 1011
- uid:
mazin1013 1017
user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid
1018
-- name:
izaan kiran - { name: kiran, uid: 1014 }
- uid:
mike 1014 1019 - var:
1020
-- name:
menaaljazlan - { name: jazlan, uid: 1015 } item:
- uid:
shoeb1015 1021 name: ravi
1022 uid: 1012
-- name:
rani emaan - { name: emaan, uid: 1016 }
uid: 1016 user: name= ‘{{ “{{item.name
???? }}” }}’ state=present uid=“{?}” ‘{{ item.uid }
- name: mazin - { name: mazin, uid: 1017 } - var:
uid: 1017 item:
- name: izaan - { name: izaan, uid: 1018 } name: mani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018 uid: 1013
- name: mike - { name: mike, uid: 1019 } user: name=‘{{ “{{ ???? }}”
item.name }}’ state=present uid=“{?}” ‘{{ item.uid }
With_*
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present - user: name=‘{{ item }}’ state=present
loop: with_items:
- joe - joe
- george - george
- ravi - ravi
- mani - mani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
With_*
- -
name: Create users name: View Config Files
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present - debug: var=item
with_items: with_file:
- joe - “/etc/hosts”
- george - “/etc/resolv.conf”
- ravi - “/etc/ntp.conf”
- mani
- -
name: Get from multiple URLs name: Check multiple mongodbs
hosts: localhost hosts: localhost
tasks: tasks:
- debug: var=item - debug: msg=“DB={{ item.database }} PID={{ item.pid}}”
with_url: with_mongodb:
- “https://site1.com/get-servers” - database: dev
- “https://site2.com/get-servers” connection_string: “mongodb://dev.mongo/”
- “https://site3.com/get-servers” - database: prod
connection_string: “mongodb://prod.mongo/”
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
With_*
with_items With_redis
with_file With_sequence
with_url With_skydive
with_mongodb With_subelements
with_dict With_template
with_etcd With_together
with_env With_varnames
with_filetree
With_ini
With_inventory_hostnames
With_k8s
With_manifold
With_nested
With_nios
With_openshift
With_password
With_pipe
© Copyright KodeKloud
With_rabbitmq Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Ansible
Conditionals
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
--- ---
- name: Install NGINX - name: Install NGINX
hosts: debian_hosts hosts: redhat_hosts
tasks: tasks:
- name: Install NGINX on Debian - name: Install NGINX on Redhat
apt:
apt yum:
yum
name: nginx name: nginx
state: present state: present
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
apt
name: nginx
state: present
when: ansible_os_family
<< condition >> == “Debian”
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Operator - and
---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
apt
name: nginx
state: present
when: ansible_os_family
<< condition >> == “Debian” and
ansible_distribution_version == “16.04”
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Conditionals in Loops
---
- name: Install Softwares
hosts: all
vars:
packages:
- name: nginx
required: True
- name: mysql
required : True
- name: apache
required : False
tasks:
- name:
- name:name: Install
Install “{{
Install “{{ item.name
“{{ item.name
item.name }}” }}”
}}” on
on Debian
Debian
on Debian
vars:
vars:
apt:item:
item:
name:
name:“{{
nginx
name: item.name }}”
nginx
mysql
apache
state: present
required:
required: True
False
apt:
apt:
name: “{{ item.name }}”
state: present
© Copyright KodeKloud
loop: "{{ packages }}" Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- name: Install “{{ item.name }}” on Debian
- mail:
to: [email protected]
subject: Service Alert
body: Httpd Service is down
when: result.stdout.find('down') != -1
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Ansible
Roles
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor
Engineer
Astronaut
Police
Chef
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor mysql
Engineer nginx
Astronaut redis
Police backup
Chef monitor
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor mysql
• Go to medical school
• Installing Pre-requisites
• Earn medical degree
• Installing mysql packages
• Complete Residency Program
• Configuring mysql service
• Obtain License
• Configuring database and users
Engineer nginx
• Installing Pre-requisites
• Go to engineering school • Installing nginx packages
• Earn bachelor’s degree • Configuring nginx service
• Gain field experience • Configuring custom web pages
• Gain postgraduate degree
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- name: Install and Configure MySQL
hosts: db-server
tasks: mysql
- name: Install Pre-Requisites
• Installing Pre-requisites
yum: name=pre-req-packages state=present
• Installing mysql packages
• Configuring mysql service
- name: Install MySQL Packages • Configuring database and users
yum: name=mysql state=present
nginx
- name: Start MySQL Service
service: name=mysql state=started • Installing Pre-requisites
• Installing nginx packages
• Configuring nginx service
- name: Configure Database • Configuring custom web pages
mysql_db: name=db1 state=present
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
mysql
• Installing Pre-requisites
• Installing mysql packages
Re-Use • Configuring mysql service
• Configuring database and users
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
mysql
• Installing Pre-requisites
• Installing mysql packages
Organize Re-Use • Configuring mysql service
• Configuring database and users
MySQL-Role
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share
README.md
templates
tasks
/etc/ansible/ansible.cfg handlers
roles_path = /etc/ansible/roles vars
defaults
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
meta
Organize Re-Use Share
roles
mysql
README.md
templates
tasks
handlers
vars
defaults
© Copyright KodeKloud meta Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Find Roles
$ ansible-galaxy search mysql
Found 1126 roles matching your search. Showing first 1000.
Name Description
---- -----------
0utsider.ansible_zabbix_agent Installing and maintaining zabbix-agent for
1mr.unattended install and configure unattended upgrade
1nfinitum.mysql Simply installs MySQL 5.7 on Xenial.
4linuxdevops.mysql-server Instalacao e Configuracao do servidor MySQL
5KYDEV0P5.skydevops-mysql Install and configure MySQL Database
AAbouZaid.yourls Manage Yourls, a URL shortener web app.
AAROC.AAROC_fg-db your description
aaronpederson.ansible-autodeploy Simple deployment tool with hooks
abednarik.mysqld-exporter Install and configure mysqld_exporter
abelboldu.openstack-glance
abelboldu.openstack-keystone
abelboldu.openstack-neutron-controller OpenStack Neutron controller node
abelboldu.openstack-nova-controller OpenStack Nova controller node
achaussier.mysql-backup configure mysql-backup with xtrabackup and
achaussier.mysql-server Install mysql-server package
achilleskal.ansible_mysql8 your description
adarnimrod.mysql Provision a MySQL server
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use Role
$ ansible-galaxy install geerlingguy.mysql
- downloading role 'mysql', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-mysql/archive/2.9.5.tar.gz
- extracting geerlingguy.mysql to /etc/ansible/roles/geerlingguy.mysql
/etc/ansible/roles/geerlingguy.mysql
- geerlingguy.mysql (2.9.5) was installed successfully
playbook.yml
- -
name: Install and Configure MySQL name: Install and Configure MySQL
hosts: db-server hosts: db-server
roles: roles:
- geerlingguy.mysql - role: geerlingguy.mysql
become: yes
vars:
mysql_user_name: db-user
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use Role
Playbook-all-in-one.yml Playbook-distributed.yml
- -
name: Install and Configure MySQL name: Install and Configure MySQL
hosts: db-and-webserver hosts: db-server
roles: roles:
- geerlingguy.mysql - geerlingguy.mysql
- nginx
-
name: Install and Configure Web Server
hosts: web-server
roles:
- nginx
mysql
mysql
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
© Copyright KodeKloud
Traditional IT &
Challenges
Field Engineers
Procurement
System/ NW
Infrastructure Team
Administrators
Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead
Backup Admins
Application team
Data Center
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Field Engineers
Procurement
System/ NW
Infrastructure Team
Administrators
Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead
Slow Deployment
Expensive
Backup Admins
Limited Automation
System/ NW
Infrastructure Team
Administrators
Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead
Slow Deployment
Expensive
Backup Admins
Limited Automation
System/ NW
Infrastructure Team
Administrators
Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead
Backup Admins
Slow Delivery
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Infrastructure as
Code
Infrastructure as Code
ec2.sh
#!/bin/bash
IP_ADDRESS="10.2.2.1"
EC2_INSTANCE=$(ec2-run-instances --instance-type
t2.micro ami-0edab43b6fa892279)
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code
ec2.sh main.tf
#!/bin/bash
resource "aws_instance" "webserver" {
IP_ADDRESS="10.2.2.1"
ami = "ami-0edab43b6fa892279"
EC2_INSTANCE=$(ec2-run-instances --instance-type instance_type = "t2.micro"
t2.micro ami-0edab43b6fa892279) }
INSTANCE=$(echo ${EC2_INSTANCE} | sed 's/*INSTANCE //'
| sed 's/ .*//')
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code
ec2.yaml main.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools
Configuration Management
Designed to Install and Manage Software
Version Control
Idempotent
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Server Templating Tools
Immutable Infrastructure
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Provisioning Tools
Multiple Providers
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Terraform
Why Terraform?
Physical Machines
VMWare
AWS
GCP
Azure
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers
VMWare CloudFlare
AWS DNS
Azure Infoblox
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HashiCorp Configuration Language
main.tf
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Import
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Cloud and Terraform Enterprise
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
$ terraform version
Terraform v0.13.0
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HCL – Declarative Language
aws.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HCL Basics
>_
$ mkdir /root/terraform-local-file
$ cd /root/terraform-local-file
local.tf
resource "local_file"
<block> <parameters> { "pet" {
filename = "/root/pets.txt"
key1 = value1
key2 = value2
content = "We love pets!"
}}
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local=provider
file=resource
Block Resource Resource
Name Type Name
FILENAME CONTENT
local.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
aws-ec2.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
aws-s3.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf
>_
$ terraform init
Initializing the backend...
To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.
------------------------------------------------------------------------
------------------------------------------------------------------------
$ cat /root/pets.txt
© Copyright KodeKloud We love pets! Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform show
# local_file.pet:
resource "local_file" “pet" {
content = "We love pets!"
directory_permission = "0777"
file_permission = "0777"
filename = "/root/pets.txt"
id = "cba595b7d9f94ba1107a46f3f731912d95fb3d2c"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local=provider
file=resource
Resource
Type
local.tf
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
provider
resource_type
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
https://registry.terraform.io/providers/hashicorp/local/latest/docs
provider Local provider
resource_type local_file
filename (required)
Content (optional)
Arguments file_permission (optional)
directory_permission (optional)
sensitive_content (optional)
content_base64 (optional)
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Update and Destroy
Infrastructure
>_
$ terraform plan
local_file.pet: Refreshing state...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
----------------------------------------------------------------------
local.tf An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
resource "local_file" "pet" { -/+ destroy and then create replacement
----------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so
Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
$ ls -ltr /root/pets.txt
$ terraform apply
-rwx------ 1 root root 30 Aug 17 23:20 pet.txt
# local_file.pet must be replaced
-/+ resource "local_file" "pet" {
content = "We love pets!"
directory_permission = "0777"
~ file_permission = "0777" -> "0700" # forces replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after apply)
}
local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet: Destruction complete after 0s
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Basics
Using Terraform
Providers
>_
$ terraform init
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Official
Verified
Community
© Copyright KodeKloud
registry.terraform.i
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
o
>_ >_
$ terraform init $ ls /root/terraform-local-file/.terraform
Initializing the backend... plugins
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform init
Initializing the backend...
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
To prevent automatic upgrades to new maj
contain breaking
changes, we recommend adding version con
required_providers block
in your configuration, with the constrai
below.
Organizational
Type
Namespace
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
To prevent automatic upgrades to new maj
contain breaking
changes, we recommend adding version con
required_providers block
in your configuration, with the constrai
below.
* registry.terraform.io/ hashicorp/loc
Hostname Organizational
Ty
Namespace
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by Ha
local.tf cat.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf cat.tf
main.tf
File Name Purpose
resource "local_file" "pet" {
Main configuration file containing resource
filename = "/root/pets.txt" main.tf
definition
content = "We love pets!"
} variables.tf Contains variable declarations
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Multiple Providers
main.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform init
Initializing the backend...
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be
persisted to local or remote state storage.
.
.
# random_pet.my-pet will be created
+ resource "random_pet" "my-pet" {
+ id = (known after apply)
+ length = 1
+ prefix = "Mrs"
+ separator = "."
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
local_file.new_file: Refreshing state...
[id=d1a31467f206d6ea8ab1cad382bc106bf46df69e]
random_pet.my-pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mrs.hen]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Define Input
Variables
main.tf
Argument Value
resource "local_file" "pet" {
filename = "/root/pets.txt" filename "/root/pets.txt"
content = "We love pets!"
content "We love pets!"
}
prefix "Mrs"
resource "random_pet" "my-pet" {
prefix = "Mrs" separator "."
separator = "."
length "1"
length = "1"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
# local_file.pet will be created
+ resource "local_file" "pet" {
+ content = “We love pets!"
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pet.txt"
+ id = (known after apply)
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
Terraform will perform the following actions:
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Understanding the
Variable Block
variables.tf
variable "filename" {
default = "/root/pets.txt"
}
variable "content" {
default = "I love pets!"
}
variable "prefix" {
default = "Mrs"
}
variable "separator" {
default = "."
}
variable "length" {
default = "1"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
variable "filename" {
default = "/root/pets.txt"
type = string
description = "the path of local file"
}
variable "content" {
default = "I love pets!"
type = string
description = “the content of the file"
}
variable "prefix" {
default = "Mrs"
type = string
description = "the prefix to be set"
}
variable "separator" {
default = "."
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf Type Example
} variable "password_change" {
variable "separator" { default = true
default = "." type = bool
© Copyright KodeKloud } course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full
Type Example
string "/root/pets.txt"
number 1
bool true/false
pet1 = cat
map
pet2 = dog
Complex Data
object
Structure
Complex Data
tuple
Structure
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
List
variables.tf maint.tf
Index Value
0 Mr
1 Mrs
2 Sir
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Map
variables.tf maint.tf
Key Value
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
List of a Type
variables.tf variables.tf
variables.tf >_
$ terraform plan
variable "prefix" { Error: Invalid default value for variable
variables.tf variables.tf
variable "cats" { variable "pet_count" {
default = { default = {
"color" = "brown" "dogs" = 3
"name" = "bella" "cats" = 1
} "goldfish" = 2
type = map(string) }
} type = map(number)
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Set
variables.tf variables.tf
variable "prefix" { variable "prefix" {
default = ["Mr", "Mrs", "Sir"] default = ["Mr", "Mrs", "Sir", "Sir"]
type = set(string) type = set(string)
} }
variables.tf variables.tf
variable "fruit" { variable "fruit" {
default = ["apple", "banana"] default = ["apple", "banana", "banana"]
type = set(string) type = set(string)
} }
variables.tf variables.tf
variable "age" { variable "age" {
default = [10, 12, 15] default = [10, 12, 15, 10]
type = set(number) type = set(number)
} KodeKloud
© Copyright } full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our
Objects
Key Example Type
variables.tf
name bella string
variable "bella" {
color brown string type = object({
name = string
age 7 number color = string
age = number
food ["fish", "chicken", "turkey"] list
food = list(string)
favorite_pet true bool
favorite_pet = bool
})
default = {
name = "bella"
color = "brown"
age = 7
food = ["fish", "chicken", "turkey"]
favorite_pet = true
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tuples
variables.tf
variable kitty {
type = tuple([string, number, bool])
default = ["cat", 7, true]
variables.tf >_
$ terraform plan
variable kitty { Error: Invalid default value for variable
type = tuple([string, number, bool])
default = ["cat", 7, true, "dog"] on variables.tf line 3, in variable "kitty":
3: default = ["cat", 7, true, "dog"]
} This default value is not compatible with the
variable's type constraint:
tuple required.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Using Variables in
Terraform
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Interactive Mode
>_
$ terraform apply
var.content
Enter a value: We love Pets!
var.filename
Enter a value: /root/pets.txt
var.length
Enter a value: 2
var.prefix
Enter a value: Mrs.
var.separator
Enter a value: .
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Command Line Flags
>_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Environment Variables
>_
$ export TF_VAR_filename="/root/pets.txt"
$ export TF_VAR_content="We love pets!"
$ export TF_VAR_prefix="Mrs"
$ export TF_VAR_separator="."
$ export TF_VAR_length="2"
$ terraform apply
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Files
terraform.tfvars
filename = "/root/pets.txt"
content = "We love pets!"
prefix = "Mrs"
separator = "."
length = "2"
>_
terraform.tfvars | terraform.tfvars.json
Automatically Loaded
*.auto.tfvars | *.auto.tfvars.json
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Precedence
main.tf >_
resource local_file pet {
$ export TF_VAR_filename="/root/cats.txt" ?
filename = var.filename
}
terraform.tfvars
variables.tf
filename = "/root/pets.txt" ?
variable filename {
type = string
} variable.auto.tfvars
filename = "/root/mypet.txt" ?
>_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Precedence
variable.auto.tfvars
filename = "/root/mypet.txt" 3?
>_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource Attribute
Reference
FILENAME CONTENT PREFIX SEPERATOR
main.tf
LENGTH
resource "local_file" "pet" {
filename = var.filename
content = "My favorite pet is Mr.Cat"
}
>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]
main.tf
LENGTH
resource "local_file" "pet" {
filename = var.filename
content = "My favorite pet is Mr.Cat"
}
>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]
main.tf
resource "local_file" "pet" {
filename = var.filename
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat"
}
>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]
om_pet" "my-pet" {
r.prefix
var.separator
r.length
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
.
.
.
# local_file.pet must be replaced
-/+ resource "local_file" "pet" {
~ content = "My favorite pet is Mrs.Cat!" ->
"My favorite pet is Mr.bull" # forces replacement
directory_permission = "0777"
file_permission = "0777"
filename = "/roots/pets.txt"
~ id =
"98af5244e23508cffd4a0c3c46546821c4ccbbd0" -> (known after
apply)
}
.
.
local_file.pet: Destroying...
[id=98af5244e23508cffd4a0c3c46546821c4ccbbd0]
local_file.pet: Destruction complete after 0s
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=e56101d304de7cf1b1001102923c6bdeaa60c523]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource
Dependencies
Implicit Dependency
main.tf
resource "local_file" "pet" {
filename = var.filename 2 1
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Explicit Dependency
main.tf
resource "local_file" "pet" {
filename = var.filename 2 1
content = "My favorite pet is Mr.Cat"
depends_on = [
random_pet.my-pet
]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Output Variables
main.tf variables.tf
resource "local_file" "pet" { variable "filename" {
filename = var.filename default = "/root/pets.txt"
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat" }
} variable "content" {
default = "I love pets!"
resource "random_pet" "my-pet" { }
prefix = var.prefix variable "prefix" {
separator = var.separator default = "Mrs"
length = var.length }
} variable "separator" {
default = "."
output pet-name { }
value = random_pet.my-pet.id variable "length" {
description = "Record the value of pet ID generated by the default = "1"
random_pet resource" }
}
output "<variable_name>" {
value = "<variable_value>"
<arguments>
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
.
.
Outputs:
pet-name = Mrs.gibbon
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform output
pet-name = Mrs.gibbon
>_
$ terraform output pet-name
Mrs.gibbon
Output Variable
SHELL SCRIPTS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Introduction to
Terraform State
>_ >_
$ cd terraform-local-file
$ ls terraform-local-file [terraform-local-file]$ terraform init
main.tf variables.tf
Initializing the backend...
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
[terraform-local-file]$ terraform plan
$ ls terraform-local-file
Refreshing Terraform state in-memory prior to plan...
main.tf variables.tf
The refreshed state will be used to calculate this plan,
persisted to local or remote state storage.
main.tf
--------------------------------------------------------
resource "local_file" "pet" {
filename = var.filename An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbol
content = var.content + create
} Plan
Init
Terraform will perform the following actions:
variables.tf
# local_file.pet will be created
variable "filename" { + resource "local_file" "pet" {
+ content = "I love pets!"
default = "/root/pets.txt" + directory_permission = "0777"
} + file_permission = "0777"
variable "content" { + filename = "/root/pets.txt"
+ id = (known after apply)
default = "I love pets!" }
}
Plan: 1 to add, 0 to change, 0 to destroy.
--------------------------------------------------------
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Note: You didn't specify an "-out" parameter to save thi
>_ >_
[terraform-local-file]$ terraform apply
$ ls terraform-local-file
An execution plan has been generated and is shown below.
main.tf variables.tf
Resource actions are indicated with the following symbol
+ create
main.tf Terraform will perform the following actions:
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
© Copyright KodeKloud [id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
Apply
Plan
Init
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Purpose of State
Real World Infrastructure terraform.tfstate
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata
pet
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "My favorite pet is ${random_pet.my-pet.id}!"
}
resource "random_pet" "my-pet" {
length = 1 my-pet
}
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}
cat
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata
>_
$ terraform apply pet
.
.
.
Plan: 3 to add, 0 to change, 0 to destroy.
local_file.cat: Creating...
random_pet.my-pet: Creating...
local_file.cat: Creation complete after 0s
[id=fe448888891fc40342313bc44a1f1a8986520c89]
random_pet.my-pet: Creation complete after 0s [id=yak] cat
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=28b373c6c1fa3fce132a518eadd0175c98f37f20]
pet
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "My favorite pet is ${random_pet.my-pet.id}!"
}
resource "random_pet" "my-pet" {
length = 1 my-pet
}
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}
cat
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata
pet
main.tf
my-pet
cat
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata
pet
main.tf
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}
my-pet
>_
$ cat terraform.tfstate
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [ cat
{
"schema_version": 0,
"attributes": {
"content": "My favorite pet is yak!",
. },
"private": "bnVsbA==",
"dependencies": [
"random_pet.my-pet"
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
]
Tracking Metadata
pet
main.tf
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}
my-pet
>_
$ terraform apply
Plan: 0 to add, 0 to change, 2 to destroy.
local_file.pet: Destroying...
[id=28b373c6c1fa3fce132a518eadd0175c98f37f20]
local_file.pet: Destruction complete after 0s
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
random_pet.my-pet: Destroying... [id=yak]
Performance
terraform.tfstate
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Performance
terraform.tfstate >_
{ $ terraform plan --refresh=false
"version": 4, An execution plan has been generated and is shown
"terraform_version": "0.13.0", below.
"serial": 4, Resource actions are indicated with the following
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31", symbols:
"outputs": {}, -/+ destroy and then create replacement
"resources": [
{ Terraform will perform the following actions:
"mode": "managed",
"type": "local_file", # local_file.cat must be replaced
"name": "pet", -/+ resource "local_file" "pet" {
"instances": [ ~ content = "I like cats too!" ->
{ "Dogs are awesome!" # forces replacement
"schema_version": 0, directory_permission = "0777"
"attributes": { file_permission = "0777"
"content": "We love pets!", filename = "/root/pets.txt"
"content_base64": null, ~ id =
"directory_permission": "0777", "cba595b7d9f94ba1107a46f3f731912d95fb3d2c" -> (known
... after apply)
}
terraform.tfstate >_
{ $ ls
"version": 4,
"terraform_version": "0.13.0", main.tf variables.tf terraform.tfstate
"serial": 4,
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [
{
"schema_version": 0, terraform.tfstate
"attributes": {
"content": "We love pets!",
"content_base64": null,
"directory_permission": "0777",
...
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
AWS S3 HashiCorp Consul
Collaboration Google Cloud Storage Terraform Cloud
terraform.tfstate
{
"version": 4,
"terraform_version": "0.13.0",
"serial": 4, terraform.tfstate
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [
{
"schema_version": 0,
"attributes": {
"content": "We love pets!",
"content_base64": null,
"directory_permission": "0777",
...
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State
Considerations
Sensitive Data
terraform.tfstate
{
"mode": "managed",
"type": "aws_instance",
"name": "dev-ec2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"ami": "ami-0a634ae95e11c6f91",
.
.
.
"primary_network_interface_id": "eni-0ccd57b1597e633e0",
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
© Copyright KodeKloud "iops": 100, Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State Considerations
Remote State Backends Version
Control
terraform.tfstate main.tf
{ resource "local_file" "pet" {
"mode": "managed",
filename = "/root/pet.txt"
"type": "aws_instance",
"name": "dev-ec2", content = "My favorite pet is Mr.Whiskers!"
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", }
"instances": [ resource "random_pet" "my-pet" {
{
"schema_version": 1,
length = 1
"attributes": { }
"ami": "ami-0a634ae95e11c6f91", resource "local_file" "cat" {
. filename = "/root/cat.txt"
.
. content = "I like cats too!"
"primary_network_interface_id": "eni-0ccd57b1597e633e0", }
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
"iops": 100,
"kms_key_id": "",
© Copyright K odeK"volume_id":
l oud "vol-070720a3636979c22", Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
No Manual Edits
terraform.tfstate
{
"mode": "managed",
"type": "aws_instance",
"name": "dev-ec2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"ami": "ami-0a634ae95e11c6f91",
.
.
.
"primary_network_interface_id": "eni-0ccd57b1597e633e0",
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
© Copyright KodeKloud "iops": 100, Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Commands
terraform validate
main.tf >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform fmt
main.tf >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform fmt
main.tf >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform show
>_ >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform providers
main.tf >_
provider[registry.terraform.io/hashicorp/local]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform output
main.tf >_
}
output pet-name {
value = random_pet.cat.id
sensitive = false
description = "Print the name of the pet"
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform refresh
main.tf >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform graph
main.tf >_
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Mutable vs
Immutable
Infrastructure
terraform validate
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}
local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet: Destruction complete after 0s
v1.19
v1.18
upgrade-nginx.sh
v1.17
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Mutable Infrastructure
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Configuration Drift
v1.19 v1.19
v1.18 v1.18 v1.18
v1.17 v1.17 v1.17
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
v1.17 v1.17 v1.17
1 2 3
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4
v1.17 v1.17 v1.17 v1.18
1 2 3
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4 5
v1.17 v1.17 v1.18 v1.18
2 3
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4 5 6
v1.17 v1.18 v1.18 v1.18
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure
4 5 6
v1.18 v1.18 v1.18
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure
4 5
v1.17 v1.18 v1.18
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}
local_file.pet:
local_file.pet: Destroying...
Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet:
local_file.pet: Destruction
Destruction complete
complete after
after 0s
0s
local_file.pet: Creating...
local_file.pet: Creating...
local_file.pet:
local_file.pet: Creation
Creation complete
complete after
after 0s
0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Lifecycle Rules
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}
local_file.pet:
local_file.pet: Destroying...
Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet:
local_file.pet: Destruction
Destruction complete
complete after
after 0s
0s
local_file.pet: Creating...
local_file.pet: Creating...
local_file.pet:
local_file.pet: Creation
Creation complete
complete after
after 0s
0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
create_before_destroy
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
-/+ resource "local_file" "pet" {
content = "We love pets!"
content = "We love pets!"
file_permission = "0700" directory_permission = "0777"
~ file_permission = "0777" -> "0755" # forces repl
lifecycle { filename = "/root/pet.txt"
create_before_destroy = true ~ id =
} "5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after ap
}
...
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet: Destruction complete after 0s
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
prevent_destroy
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" local_file.my-pet: Refreshing state...
content = "We love pets!" [id=cba595b7d9f94ba1107a46f3f731912d95fb3d2c]
file_permission = "0700"
Error: Instance cannot be destroyed
lifecycle {
create_before_destroy
prevent_destroy = true= true on main.tf line 1:
} 1: resource "local_file" "my-pet" {
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
instance_type = "t2.micro" ...
Terraform will perform the following actions:
tags = {
Name = “ProjectA-Webserver"
# aws_instance.webserver will be created
}
+ resource "aws_instance" "webserver" {
}
+ ami = "ami-0edab43b6fa892279"
+ get_password_data = false
+ host_id = (known after apply)
+ id = (known after apply)
+ instance_state = (known after apply)
+ instance_type = "t2.micro“
+ tags {
+ "Name" = "ProjectA-WebServer"
}
.
aws_instance.webserver: Creation complete after 33s [id=i-
05cd83b221911acd5]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279" aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro" 05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver" An execution plan has been generated and is shown below.
} Resource actions are indicated with the following symbols:
} ~ update in-place
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro"
05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver"
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
}
lifecycle {
ignore_changes = [
tags
]
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro"
05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver"
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
}
lifecycle {
ignore_changes == all
ignore_changes [
tags,ami
]
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Order Option
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Data Sources
Real World Infrastructure terraform.tfstate
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
>_
$ cat /root/dog.txt
Dogs are awesome!
dogs.txt pets.txt
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Data Sources main.tf
dogs.txt pets.txt
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform.tfstate
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Meta Arguments
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Shell Scripts
create_files.sh >_
touch /root/pet${i}
done
Iteration filename
1 /root/pet1
2 /root/pet2
3 /root/pet3
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Meta Arguments
depends_on lifecycle
main.tf main.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Count
count
main.tf variables.tf
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
count
main.tf variables.tf
local_file.pet[2]: Creating...
pet[1] local_file.pet[0]: Creating...
pet[0] pet[2]
local_file.pet[1]: Creating...
local_file.pet[0]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
local_file.pet[2]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
local_file.pet[1]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
main.tf variables.tf
>_
pet[0] pet[1] pet[2]
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
cats.txt
local_file.pet[2]: Creating...
local_file.pet[0]: Creating...
local_file.pet[1]: Creating...
© Copyright KodeKloud local_file.pet[0]: Creation
Check out our full course on Terraform complete
for the Absolute after
Beginners: 0s
https://kode.wiki/3PoScZd
Length Function
main.tf variables.tf
}
pet[0] pet[1] pet[2]
>_
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
© Copyright KodeKloud cats.txt
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet[2]: Creating...
Length Function
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
LengthFunction
main.tf variables.tf
}
pet[0] pet[1] pet[2]
>_
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
© Copyright KodeKloud cats.txt
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet[2]: Creating...
>_ >_
$ terraform apply $ ls /root
. pet.txt
. dogs.txt
Terraform will perform the following actions: cats.txt
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
variable "filename" {
default
default == "/root/pets.txt"
[
main.tf
"/root/pets.txt",
"/root/dogs.txt",
resource "local_file" "pet" { "/root/cats.txt"
filename = var.filename [count.index] ]
count = length(var.filename)
3 }
}
>_
$ terraform plan
...
# local_file.pet[0] must be replaced
-/+ resource "local_file" "pet" {
directory_permission = "0777"
file_permission = "0777"
pet[0] pet[1] pet[2] ~ filename = "/root/pets.txt" -> "/root/dogs.txt" #
forces replacement
}
# local_file.pet[1] must be replaced
-/+ resource "local_file" "pet" {
directory_permission = "0777"
file_permission = "0777"
~ filename = "/root/dogs.txt" -> "/root/cats.txt" #
forces replacement
}
# local_file.pet[2] will be destroyed
Replace
© Copyright KodeKloud Replace Destroy - resource "local_file" "pet" {
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
- directory_permission = "0777" -> null
main.tf >_
$ terraform output
resource "local_file" "pet" { Outputs:
filename = var.filename [count.index] pets = [
{
count = length(var.filename)
3 "directory_permission" = "0777"
} "file_permission" = "0777"
"filename" = "/root/pets.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
output "pets" { },
value = local_file.pet {
} "directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/dogs.txt"
pet[0] pet[1] pet[2] "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
{
"directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
pet[0] pet[1] pet[2] variable "filename" {
default
default == "/root/pets.txt"
[
"/root/pets.txt",
"/root/dogs.txt",
"/root/cats.txt"
]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
pet[0] pet[1] variable "filename" {
default
default == "/root/pets.txt"
[
"/root/pets.txt",
"/root/dogs.txt",
"/root/cats.txt"
]
dogs.txt cats.txt }
© Copyrightpet[2]
KodeKloud Does not Exist Check out our full course onDestroy
Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
for_each
for_each
main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
3var.filename "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]
>_
pet[0] pet[1] pet[2]
$ terraform plan
Error: Invalid for_each argument
main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
type=set(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
3var.filename "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]
>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform
Error: Invalid
will perform
for_eachthe
argument
following actions:
# local_file.pet["/root/cats.txt"] will be created
+
onresource
main.tf "local_file"
line 2, in resource
"pet" {"local_file" "pet":
2: + directory_permission
for_each = var.filename = "0777"
+ file_permission = "0777"
The given
+ filename
"for_each" argument=value "/root/cats.txt"
is unsuitable: the "for_each"
argument
} must be a map, or set of strings, and you have provided a value
...
of type
<output
listtrimmed>
of string.
© Copyright KodeKloud Plan: 3 to
Check out ouradd, 0 to on
full course change, 0 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each
main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
type=set(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]
>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform
Error: Invalid
will perform
for_eachthe
argument
following actions:
# local_file.pet["/root/cats.txt"] will be created
+
onresource
main.tf "local_file"
line 2, in resource
"pet" {"local_file" "pet":
2: + directory_permission
for_each = var.filename = "0777"
+ file_permission = "0777"
The given
+ filename
"for_each" argument=value "/root/cats.txt"
is unsuitable: the "for_each"
argument
} must be a map, or set of strings, and you have provided a value
...
of type
<output
listtrimmed>
of string.
© Copyright KodeKloud Plan: 3 to
Check out ouradd, 0 to on
full course change, 0 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each
main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
output "pets" { ]
value = local_file.pet
}
}
>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform will perform
Error: Invalid for_eachthe following actions:
argument
# local_file.pet["/root/pets.txt"]
local_file.pet["/root/cats.txt"] will be destroyed created
+
onresource
- main.tf "local_file" "pet" {"local_file" "pet":
line 2, in resource
2: +
- directory_permission
for_each = var.filename = "0777" -> null
+
- file_permission = "0777" -> null
+
- filename
The given "for_each" argument=value "/root/pets.txt"
is unsuitable:
"/root/cats.txt" -> null
the "for_each"
}}
argument must be a map, or set of strings, and you have provided a value
... <output
of type listtrimmed>
of string.
© Copyright KodeKloud Plan: 03 to
Check out ouradd, 0 to on
full course change, 10 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each
main.tf >_
$ terraform output
resource "local_file" "pet" { pets = {
var.filename [count.index]
filename = each.value "/root/cats.txt" = {
"directory_permission" = "0777"
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "file_permission" = "0777"
"filename" = "/root/cats.txt"
} "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
output "pets" {
value = local_file.pet "/root/dogs.txt" = {
} "directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/dogs.txt"
pet[0] pet[1] pet[2] "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
count for_each
>_ >_
$ terraform output $ terraform output
pets = [ pets = {
{ "/root/cats.txt" = {
"directory_permission" = "0777" "directory_permission" = "0777"
"file_permission" = "0777" "file_permission" = "0777"
"filename" = "/root/pets.txt" "filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709" "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}, }
{
"directory_permission" = "0777"
"file_permission" = "0777" "/root/dogs.txt" = {
"filename" = "/root/dogs.txt" "directory_permission" = "0777"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709" "file_permission" = "0777"
}, "filename" = "/root/dogs.txt"
{ "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
"directory_permission" = "0777" }
"file_permission" = "0777" }
"filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Version Constraints
main.tf >_
resource "local_file" "pet" { $ terraform init
filename = "/root/pet.txt" Initializing the backend...
content = "We love pets!" Initializing provider plugins...
} - Finding latest version of hashicorp/local...
- Installing hashicorp/local v1.4.0...
- Installed hashicorp/local v1.4.0 (signed by HashiCorp)
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "1.4.0"
}
}
}
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = { Initializing provider plugins...
source = "hashicorp/local" - Finding hashicorp/local versions matching "1.4.0"...
- Installing hashicorp/local v1.4.0...
version = "1.4.0" - Installed hashicorp/local v1.4.0 (signed by HashiCorp)
}
Terraform has been successfully initialized!
}
} You may now begin working with Terraform. Try running
"terraform plan" to see
any changes that are required for your infrastructure. All
resource "local_file" "pet" { Terraform commands
filename = "/root/pet.txt" should now work.
content = "We love pets!" If you ever set or change modules or backend configuration for
} Terraform,
rerun this command to reinitialize your working directory. If
you forget, other
commands will detect it and remind you to do so if necessary.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = {
Initializing provider plugins...
source = "hashicorp/local" - Finding hashicorp/local versions matching "> 1.2.0, <
version
version == "1.4.0"
">
"<
"!=1.2.0,
1.4.0"
1.1.0"
2.0.0"< 2.0.0, != 1.4.0" 2.0.0, != 1.4.0"...
} - Installing hashicorp/local v1.3.0...
} - Installed hashicorp/local v1.3.0 (signed by
HashiCorp)
}
Terraform has been successfully initialized!
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = {
Initializing provider plugins...
source = "hashicorp/local"
- Finding hashicorp/local versions matching "~>
version
version === "1.4.0"
version ">
"!=1.2.0,
"<
"~> 2.0.0"< 2.0.0, != 1.4.0"
1.4.0"
1.1.0"
1.2"
1.2.0" 1.2.0"...
} - Installing hashicorp/local v1.2.2...
} - Installed hashicorp/local v1.2.2 (signed by
HashiCorp)
}
Terraform has been successfully initialized!
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud
Certified Entry-Level Python
Programmer Certification (PCEP)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Basic
Data Types Operators
Concepts
Data
Flow Control Functions
Collections
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Introduction
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Easy and intuitive programming language
Free and Open Source
Can be widely used for a variety of tasks
🐍
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
bash
$ python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>>
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>>
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>> print ( "Hello future Python programmer!" )
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>> print ( "Hello future Python programmer!" )
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py
bash
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py
bash
$ python myfile.py
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py
bash
$ python myfile.py
Hello future Python programmer!
$
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Functions - Print()
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
Functions
>>> print ( " Hello future Python programmer! ")
A part of your code that’s used to
Hello future Python programmer!
cause an effect or evaluate a value.
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
Functions
>>> print ( " Hello future Python programmer! ")
A part of your code that’s used to
Hello future Python programmer!
cause an effect or evaluate a value.
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
Hello future Python programmer!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
Function Execution >>> print ( " Hello future Python programmer! ")
Hello future Python programmer!
Python:
1. Checks function name
2. Checks arguments passed
3. Jumps into the function
4. Executes the function
5. Returns to your code
6. Resumes execution
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print("Hello!" )
print("Python is a great language")
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
print()
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Literals
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
200 "Hello!" "Python" -89
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
200 "Hello!" "Python" -89
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
Literal types:
1. Integers
• Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
Literal types:
1. Integers 0o123
• Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
0o123
Literal types:
1. Integers
•Octal numbers 2 1 0
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
•Octal numbers 82 81 80
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
•Octal numbers 64 8 1
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
•Octal numbers
•Hexadecimal numbers 64 16 3
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers 0x123
•Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
• Octal numbers 2 1 0
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123
Literal types:
1. Integers
• Octal numbers 16 2 161 160
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123
Literal types:
1. Integers
• Octal numbers 256 16 1
•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123
Literal types:
1. Integers
• Octal numbers
•Hexadecimal numbers 256 32 3
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123
Literal types:
1. Integers
•Octal numbers
•Hexadecimal numbers 291
256
32
3
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
•Octal numbers
0.0000000000000000000001
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
1. Integers
•Octal numbers
1e-22
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
Literal types:
"Hello!"
1. Integers
• Octal numbers
•Hexadecimal numbers 'Hello!'
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
Literal types:
1. Integers
• Octal numbers
"Hello! \"Python\" is cool"
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
•Hexadecimal 0x123
• Use quotes 'Hi "hi"' • Numeric false 0
within strings
+ - * / // % **
** 3
2
Exponential
** 2True
** 3
Exponential
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(2 ** 3)
8
Arithmetic Operators >>> print(2. ** 3.)
8.0
>>> print(2. ** 3)
Exponential
8.0
>>> print(2 * 3)
6
Arithmetic Operators >>> print(2. * 3.)
6.0
>>> print(2. * 3)
Multiplication
6.0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(10 / 2)
5.0
Arithmetic Operators >>> print(10. / 2.)
5.0
>>> print(10. / 2)
Division
5.0
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print(10 // 2)
5
Arithmetic Operators >>> print(10. // 2.)
5.0
>>> print(10. // 2)
Floor Division
5.0
>>> print(6. / 4)
1.5
Arithmetic Operators >>> print(6. // 4)
1.0
>>> print(6. / -4)
//
-1.5
>>> print(6. // -4)
Floor Division -2.0
>>> print(4 % 2)
Arithmetic Operators
Modulo
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(4 % 2)
Arithmetic Operators
Modulo
>>> print(4 % 2)
Arithmetic Operators
Modulo
>>> print(4 % 2)
0
Arithmetic Operators
Modulo
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print(5 % 2)
Arithmetic Operators
Modulo
>>> print(5 % 2)
Arithmetic Operators
Modulo
>>> print(5 % 2)
Arithmetic Operators
Modulo
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print(5 % 2)
1
Arithmetic Operators
Modulo
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(5 % 2)
1
Arithmetic Operators
Modulo
>>> print(6 + 4)
10
Arithmetic Operators >>> print(6. + 4)
10.0
>>> print(6. + 4.)
+
10.0
Addition
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(6 - 4)
2
Arithmetic Operators >>> print(6. - 4)
2.0
>>> print(6. - 4.)
-
2.0
Subtraction
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2
Binary Operator
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2
Binary Operator
Binary Operator
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2 - 2
>>> print(-6 - 6)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(-6 - 6)
-12
>>> print(-6 - 6)
-12
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(-6 - 6)
-12
>>> print(10 - 6 ** 7 / 9 * 23 + 1)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Highest Priority + - (unary)
**
* / // %
>>> print(10 - 6 ** 2 / 9 * 10 + 1)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 6 ** 2 / 9 * 10 + 1 )
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 4 * 10 + 1 )
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 40 + 1 )
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 40 + 1 )
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( -29 )
>>> print(10 - 6 ** 7 / 9 * 10 + 1)
-29
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> print(2 * (2 + 3) )
>>> print(2 * 5)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> print(2 * 5)
10
© Copyright KodeKloud
Variables
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> print(2 * 5)
10
>>> amount_of_apples = 2
>>> cost_of_apple = 5
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> amount_of_apples = 2
>>> cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
>>> amount_of_apples = 2
>>> cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
10
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple
2 5
amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names
amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE del
elif
return
amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE del
elif
return
Import import
Del del
Elif elif
Return return
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple
2 5
python3 python3
2 7
python3 python3
2 7
python3 python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple
2 7
python3 python3
2 5
python3
cost_of_apple = cost_of_apple + 2
>>>
>>> print(amount_of_apples * cost_of_apple)
14
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple
2 5
python3
cost_of_apple += 2
>>>
>>> print(amount_of_apples * cost_of_apple)
14
2 5
python3 python3
>>> cost_of_apple += 2
2 7
python3 python3
>>> cost_of_apple += 2
>>> print(amount_of_apples * cost_of_apple)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple
2 7
python3 python3
>>> cost_of_apple += 2
>>> print(amount_of_apples * cost_of_apple)
18
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Without Shortcut Operator With Shortcut Operator
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Variables
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> amount_of_apples = 2
>>> cost_of_apple = 5
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3
>>> amount_of_apples = 2
>>> # cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
>>> amount_of_apples = 2
>>> # cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
NameError: name 'cost_of_apple' is not defined
© Copyright KodeKloud
Input
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3
>>> print("Hello!")
Hello!
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
input()
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
• Integers int()
python3
python3
• Integers int()
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Type Casting
• Integers int()
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
input()
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print(10 + 2)
12
>>> print(10 * 2)
22
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
+
python3
python3
>>> print(10 + 2)
12
>>> print("Hello" + " " + "there!")
"Hello there!"
python3
python3
>>> print(10 * 2)
22
python3
python3
>>> print(10 * 2)
22
>>> print("ha" * 10)
"hahahahahahahahahaha"
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
*
python3
python3
>>> print(int("22"))
22
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> print(int("22"))
22
>>> print(str(22))
"22"
>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)
>>> print("You have to pay: " + str(total_sum))
>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)
>>> print("You have to pay: " + str(total_sum))
You have to pay: 20
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
String Operations
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
>>> print(2 == 2)
True
Comparison Operators >>> print(2 == 4)
False
>>> print("Hello!" == "Hello!")
==
True
>>> print("Hello!" == “Goodbye!")
Equal False
>>> print(4 == (2 * 2))
True
>>> print(2 != 2)
False
Comparison Operators >>> print(2 != 4)
True
>>> print("Hello!" != "Hello!")
!=
False
>>> print("Hello!" != “Goodbye!")
Not Equal True
>>> print(4 != (2 * 2))
False
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Comparison Operators
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition
: False :
print("The condition is true!")
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")
else:
print("The condition is false!”)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if False
condition :
print("The condition is true!")
else:
print("The condition is false!")
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if False
condition :
print("The condition is true!")
elif True
second_condition :
print("Only the second condition is true!")
else:
print("Both conditions are false!”)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if True
condition :
print("The condition is true!")
elif True
second_condition :
print("Only the second condition is true!")
else:
print("Both conditions are false!”)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if age >= 18 :
if age == 18 :
print("You are exactly 18 years old!")
else:
print("You older than 18 years old!")
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Loops - While
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
while condition:
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4
Guess a number: 3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4
Guess a number: 3
>>>
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4
Guess a number: 3
>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4
Guess a number: 3
Congratulations, you got it!
>>>
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
0 1 2 3 4 5 6 7 8 9
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
0 1 2 3 4 5 6 7 8 9
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7
i is: 8
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i
0 1 2 3 4 5 6 7 8 9
python3
python3
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7
i is: 8
i is: 9
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for i in range(2, 5):
2 3 4
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
break
print("i is: ", i)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4
python3
python3
break
print("i is: ", i)
0
0 1 2 3 4
python3
python3
break
print("i is: ", i)
0
1
0 1 2 3 4
python3
python3
break
print("i is: ", i)
0
1
>>>
python3
python3
python3
python3
continue
print("i is: ", i)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i
0 1 2 3 4
python3
python3
continue
print("i is: ", i)
0
0 1 2 3 4
python3
python3
continue
print("i is: ", i)
0
1
0 1 2 3 4
python3
python3
continue
print("i is: ", i)
0
1
0 1 2 3 4
python3
python3
continue
print("i is: ", i)
0
1
3
0 1 2 3 4
python3
python3
continue
print("i is: ", i)
0
1
3
4
• We can execute code for each item in a sequence with a for … in loop
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Operators
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age1 = 24
>>> age1 = 24
>>> age2 = 16
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age1 = 24
>>> age2 = 16
>>> if( Both ages are higher than 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)
>>> age1 = 24
>>> age2 = 16
>>> if( Both ages are higher than 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)
>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)
>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( age1 >= 18 or age2 >= 18 ):
print("One of you is an adult")
else:
print("You are both children”)
>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( age1 >= 18 or age2 >= 18 ):
print("One of you is an adult")
else:
print("You are both children”)
or and not
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Bitwise Operators
& | ~ ^
& | ^
1 & 1 1 | 1 0 ^ 1
0 | 1 1 ^ 0
1 | 0
© Copyright K odeK l oud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> 15 & 22
>>> print(bin(15))
0b1111
>>> print(bin(15))
0b1111
>>> print(bin(22))
0b10110
>>> print(bin(15))
0b1111
>>> print(bin(22))
0b10110
15 0 0 0 0 1 1 1 1
22 0 0 0 1 0 1 1 0
22 0 0 0 1 0 1 1 0
&
22 0 0 0 1 0 1 1 0
Two 1
1 & 1
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1
22 0 0 0 1 0 1 1 0
0 0 0 0 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1
22 0 0 0 1 0 1 1 0
0 0 0 0 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1
22 0 0 0 1 0 1 1 0
6 0 0 0 0 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 | 0 1 1 1 1
At least one 1
22 0 0 0 1 0 1 1 0
1 | 1
0 | 1
1 | 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1
22 0 0 0 1 0 1 1 0
0 0 0 1 1 1 1 1
22 0 0 0 1 0 1 1 0
31 0 0 0 1 1 1 1 1
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
22 0 0 0Exactly 1 1 0 1 1 0
0 ^ 1
1 ^ 0
22 0 0 0 1 0 1 1 0
0 0 0 1 1 1 0 1
22 0 0 0 1 0 1 1 0
25 0 0 0 1 1 0 0 1
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> print(~22)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
22 0 0 0 1 0 1 1 0
1 1 1 0 1 0 0 1
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
22 0 0 0 1 0 1 1 0
-23 1 1 1 0 1 0 0 1
>> <<
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
0 0 0 0
1 0
1 0
1 1 1
0
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
11 0 0 0 0
1 1
0 1
0 1 1
0
22 0 0 0 1 0 1 1 0
11 0 0 0 0
1 0
1 0
1 1 0
1
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
5 0 0 0 0 0
1 1
0 0
1 1
22 0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
0 0 0 1 0 1 1 0
22 0 0 0 1 0 1 1 0
0 0 0 1 0 1 1 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
0 0 0
1 0
1 0
1 1 1
0 0
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
22 0 0 0 1 0 1 1 0
44 0 0 0
1 1
0 1
0 1 1
0 0
22 0 0 0 1 0 1 1 0
44 0 0 0
1 1
0 1
0 1 1
0 0
• Logical operators and not and or return boolean values based on the passed values
• Bitwise operators & | ^ and ~ allow us to manipulate single bits of data, and return
0 or 1 based on the value of the bits that are used
• Bit shifting can be done with the << and >> operators
© Copyright KodeKloud
Lists
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
A
>>> print(countries[1])
Canada
>>> print(countries[2])
India
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
len()
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1
"UK" "India"
python3
python3
python3
python3
0 1 2
python3
python3
0 1 2
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
-3 -2 -1
0 1 2
python3
python3
0 1 2
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
list.insert()
print() list.append()
len() list.insert()
input()
list.insert()
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2
python3
countries[0], countries[1] = countries[1], countries[0]
>>> countries = ["USA", "Canada", "India"]
>>>
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2
python3
python3
python3
python3
list.reverse()
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3
56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3
24 46 56 72
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3
24 46 56 72
python3
python3
56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3
46 24 72 56
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3
46 24 72 56
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
56 72 24 46
python3
python3
0 56 72 24 46
python3
python3
0 56 72 24 46
python3
python3
0 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3
0 56 72 24 46
python3
python3
56 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3
56 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3
128 56 72 24 46
python3
python3
128 56 72 24 46
python3
python3
152 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3
152 56 72 24 46
python3
python3
198 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3
198 56 72 24 46
python3
python3
198 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3
198 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3
198 56 72 24 46
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3
198 56 72 24 46
python3
python3
>>>
name
"Lydia"
python3
python3
name ages
56 72 24 46
"Lydia" <40>
python3
python3
name ages
56 72 24 46
"Lydia" <40>
python3
python3
python3
python3
python3
python3
python3
python3
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 40
python3
python3
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40
python3
python3
© Copyright KodeKloud
Slicing Lists
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
list[start:end]
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 40
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
python3
python3
python3
python3
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Nested Lists - 2D
(Matrix)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>>
student = classroom[2]
>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>>
student = classroom[2]
>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]
>>> print(student)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]
>>> print(student)
"Sara"
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] [1] Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] [1] Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Functions
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Functions Methods
print() list.append()
len() list.insert()
input()
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
def input_number():
return int(input("Enter a number: "))
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
def input_number():
return int(input("Enter a number: "))
© Copyright KodeKloud
Function - Arguments
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
def input_number( ):
return int(input("Enter a number: "))
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
def input_number( num ):
return int(input("Enter a number: ")) * num
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
>>>
def input_number( num ):
return int(input("Enter a number: ")) * num
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2
>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Function - Return
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
if(sum == 0):
return
if(sum == 0):
return
>>> print_sum(4, 2)
if(sum == 0):
return
>>> print_sum(4, 2)
The sum is: 6
if(sum == 0):
return
>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
if(sum == 0):
return
>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
if(sum == 0):
return
>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
if(sum == 0):
return
>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Function - List as Argument
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
return multiplied_values
© Copyright KodeKloud
Scopes
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
© Copyright KodeKloud
Function - Arguments Explained
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)
22
age
22
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1
age num
22 22
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1
age num
22 44
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
age num
22 44
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
age num
22 44
python3
python3
>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)
22
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40
nums
1 2 3
<40>
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40
nums
1 2 3
<40>
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40
nums
1 2 3
<40>
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40
nums
1 2 3
<40>
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 40
nums list
1 2 3
<40> <40>
python3
python3
nums list
9 2 3
<40> <40>
python3
python3
nums list
9 2 3
<40> <40>
python3
python3
nums list
9 2 3
<40> <40>
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Tuples
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
[1, 2, 3]
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
[1, 2, 3]
del myList[1]
myList.append(4)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment
>>> del tuple1[1]
TypeError: 'tuple' object doesn't support item deletion
>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment
>>> del tuple1[1]
TypeError: 'tuple' object doesn't support item deletion
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>> age = 22
>>> tuple1 = (1, "Lydia", age, (1, 2))
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
lydia lydiahallie
sarah sarah123
max
max
_
joe joejoe
>>>
"lydia": "lydiahallie",
usernames ={
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["sarah"])
"sarah123"
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["anotherone"])
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["anotherone"])
KeyError: 'anotherone'
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Methods
dictionary.keys()
dictionary.values()
dictionary.items()
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.keys())
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.keys())
dict_keys(['lydia', 'sarah', 'max', ‘joe'])
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.keys())
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.values())
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.values())
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.items())
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.items())
dict_items([
('lydia', 'lydiahallie'),
('sarah', 'sarah123'),
('max', 'max_')
('joe', 'joejoe')
])
dictionary.keys()
dictionary.values()
dictionary.items()
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames["max"] = "max123"
>>> print(usernames["max"])
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames["max"] = "max123"
>>> print(usernames["max"])
"max123"
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })
>>> print(usernames)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
"chloe": "chloe123"
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]
>>> print(usernames)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"joe": "joejoe"
}
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()
>>> print(usernames)
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()
>>> print(usernames)
{}
>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.popitem()
>>> print(usernames)
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.popitem()
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_"
}
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()
>>> print(usernames_copy)
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3
>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()
>>> print(usernames_copy)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe"
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Learn more about DevOps and Cloud courses with KodeKloud: https://kode.wiki/3N3A4kt
© Copyright KodeKloud