Chekkizhar-assignments
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Day-3
What is POD? define in bullets points
- virtual entity.
- Can not be started. Only can be instantiated
- K8 manages pods
- Pods have unique IP in that particular cluster
- Pods can have multiple container ( not same image) in a single pod
- Pods talk with other pods using pod network which is provided by kubeproxy
- pods are atomic ( either ready or pending )
- they are unique in a cluster they are in
- life cycle : pending–> running–>success or fail at the exit
- pods are used in master plane also to deploy apiserver,scheduler etc
- pods are accessible only inside cluster
- static pod : first instantiated pods in master plane which are not managed by K8
What is the architecture and components of Kubernetes?
Day-2
- benefit of using CMD
- option to run program when docker is attached
- dynamically the default PID-0 pgm can be changed without building image again
- PID-0 pgm can be replaced
- benefit of using ENTRYPOINT
- option to run program when docker is attached
- must to run program , always get run as PID-0. Users can not change
- further program to be run at start, can be added
What happens When i specify 2 CMD in one dockerfile?
last entry CMD got executed
FROM ubuntu
MAINTAINER chekkizhar
ENV APP_HOME=/tmp
RUN apt-get update
RUN apt-get install git -y
RUN touch /tmp/test1.txt && touch /tmp/test2.txt && touch /tmp/test3.txt
COPY sampleText.txt /tmp/sampleText.txt
CMD echo “Hello world”
CMD echo “Hello world again”
_______________________________________________________________________
What happens When i specify 2 ENTRYPOINT in one dockerfile?
last entry got executed
FROM ubuntu
MAINTAINER chekkizhar
ENV APP_HOME=/tmp
RUN touch /tmp/test1.txt && touch /tmp/test2.txt && touch /tmp/test3.txt
COPY sampleText.txt /tmp/sampleText.txt
ENTRYPOINT [“/bin/echo”, “Hello”]
ENTRYPOINT [“/bin/echo”, “Hello again”]
____________________________________________________________________
What happens When i specify 1 ENTRYPOINT & 1 CMD in one dockerfile?
both are executing
FROM ubuntu
MAINTAINER chekkizhar
ENV APP_HOME=/tmp
RUN touch /tmp/test1.txt && touch /tmp/test2.txt && touch /tmp/test3.txt
COPY sampleText.txt /tmp/sampleText.txt
CMD echo “Hello world CMD”
ENTRYPOINT [“/bin/echo”, “Hello entry point”]
Successfully built b91cd489d83d
Successfully tagged chekki-1-cmd-1-entry-point:latest
root@sindhu-Lenovo:/home/slacker/dockerExp# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chekki-1-cmd-1-entry-point latest b91cd489d83d 6 seconds ago 72.8MB
chekki-2-entry-point latest 9f24f501ae34 3 minutes ago 72.8MB
chekki-2-cmd-entry latest d10e00dc7cce 10 minutes ago 204MB
chekki-lh-1 latest c44c86a023dc 13 minutes ago 204MB
ubuntu latest 1318b700e415 3 weeks ago 72.8MB
root@sindhu-Lenovo:/home/slacker/dockerExp# docker run chekki-1-cmd-1-entry-point
Hello entry point /bin/sh -c echo “Hello world CMD”
root@sindhu-Lenovo:/home/slacker/dockerExp#
_________________________________________________________________________
S.no | CMD | ENTRYPOINT |
1 | run time can change the PID-0 w/o building image | Not possible. Rebuild of image needed |
2 | replace the PID-0 | append to start apps list |
sample 1:
Apache running at start
Interactive mode not able to stop. Container exitted
Points about docker images
- selected s/w pieces put together in layered way to cater the need
- light weight , modular s/w tool
- top layer has priority in case of conflict
- identification is done using UUID which is generated using SHA256
- docker image is same as any linux system, which has added s/w layers
- docker image to docker imagedirect copy not possible.
- through port forwarding applications runing inside docker image can be reached
wait: waitingfor container to finish and get the error code
[root@ip-172-31-4-11 ~]# docker wait u1
0
sending stop from other terminal,
sudo su –
Last login: Tue Aug 17 04:59:29 UTC 2021 on pts/0
[root@ip-172-31-4-11 ~]# docker stop u1
u1
Update: to dynmically update container params
before:
docker stats u1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
cb87a82d7de4 u1 0.00% 1.633MiB / 1.793GiB 0.09% 656B / 0B 0B / 0B 3
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
cb87a82d7de4 u1 0.00% 1.633MiB / 1.793GiB 0.09% 656B / 0B 0B / 0B 3
After:
docker update –memory=”1g” –memory-swap=”1g” u1
u1
[root@ip-172-31-4-11 ~]# docker stats u1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
cb87a82d7de4 u1 0.00% 1.633MiB / 1GiB 0.16% 656B / 0B 0B / 0B 3
Day 1 – assignment
Pros & cons of container
1.easy & quick to deploy
2.ready to use containers are available for most use cases
3.modular approach for development
4.seperation of concerns
5. cost saving
1.extra step to take backup ??
2.no GUI
pause vs unpause
command
docker pause 34c06d63dade
Error response from daemon: Cannot pause container 34c06d63dade48e38fd01df747fc29566fb2783e2e2eb8060d2ea254857d796d: OCI runtime pause failed: unable to freeze: unknown
thoughts
pause might keep the container from releasing full resources. Just put the process inside them to pause
Unpause – will resume the processes
Stop vs kill
command:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAM ES
34c06d63dade jenkins/jenkins “/sbin/tini — /usr/…” 18 minutes ago Exited (143) 7 seconds ago ped antic_pare
896c9e81c886 hello-world “/hello” 40 minutes ago Exited (0) 22 minutes ago rev erent_cray
[root@ip-172-31-4-11 ~]# docker start 34c06d63dade
34c06d63dade
[root@ip-172-31-4-11 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34c06d63dade jenkins/jenkins “/sbin/tini — /usr/…” 22 minutes ago Up 3 seconds 8080/tcp, 50000/tcp pedantic_pare
896c9e81c886 hello-world “/hello” 44 minutes ago Exited (0) 26 minutes ago reverent_cray
[root@ip-172-31-4-11 ~]# docker kill 34c06d63dade
34c06d63dade
[root@ip-172-31-4-11 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34c06d63dade jenkins/jenkins “/sbin/tini — /usr/…” 22 minutes ago Exited (137) 2 seconds ago pedantic_pare
896c9e81c886 hello-world “/hello” 44 minutes ago Exited (0) 27 minutes ago reverent_cray
docker stop 34c06d63dade
34c06d63dade
[root@ip-172-31-4-11 ~]# docker kill 34c06d63dade
Error response from daemon: Cannot kill container: 34c06d63dade: Container 34c06d63dade48e38fd01df747fc29566fb2783e2e2eb8060d2ea254857d796d is not running
thoughts
stop can be given to already stopped container. kill can be sent only when container is running
kill and stop recorded 2 different exit codes.
inside the application we can catch the signal delivered to the processes and handle
typically stop is proper shutdown and kill is force shutdown