Understanding the replica set in Kubernetes.
Creating a Pod inside a Namespace
Creating a Pod inside a Namespace
Namespace
How to check all available namespaces?
kubectl get namespaces
NAME STATUS AGE
default Active 2d
kube-public Active 2d
kube-system Active 2d
How to create a namespace
kubectl create namespace test
namespace/test created
kubectl get namespaces
NAME STATUS AGE
default Active 82d
kube-public Active 82d
kube-system Active 82d
test Active 5s
- kube-system: Namespace for objects created by kubernetes system
- default: It's default namespace when you don't specify name then objects will be created in default namespace
- kube-public: This is created automatically and readable by all users. This namespace is mostly reserved for cluster usage.
kubectl run mypod --image=nginx -n test
pod/mypod created
kubectl get pods -n test
NAME READY STATUS RESTARTS AGE
mypod 1/1 Running 0 2m10s
kubectl run mypod --image=nginx -n prod
pod/mypod created
kubectl get pods -n prod
NAME READY STATUS RESTARTS AGE
mypod 1/1 Running 0 14s
Conclusion
Debugging your pod on Kubernetes?
Debugging the pods on Kubernetes
To start with it, we first need to run the pod. You can follow below command to run the pod.
kubectl run mypod --image=nginx
kubectl get pods
NAME READY STATUS RESTARTS AGE
mypod 0/1 ContainerCreating 0 5s
NAME READY STATUS RESTARTS AGE
mypod 1/1 Running 0 21s
To delete the Pod use below command:
kubectl delete pod mypod
pod "mypod" deleted
kubectl run mypod --image=nginx-myimage-123
kubectl get pods
NAME READY STATUS RESTARTS AGE
mypod 0/1 ErrImagePull 0 9s
To check the events we can use describe command:
kubectl describe pod mypod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 34s default-scheduler Successfully assigned default/mypod to docker-desktop
Normal BackOff 26s kubelet Back-off pulling image "nginx-myimage-123"
Warning Failed 26s kubelet Error: ImagePullBackOff
Normal Pulling 12s (x2 over 33s) kubelet Pulling image "nginx-myimage-123"
Warning Failed 6s (x2 over 27s) kubelet Failed to pull image "nginx-myimage-123": rpc error: code = Unknown desc = Error response from daemon: pull access denied for nginx-myimage-123, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
Warning Failed 6s (x2 over 27s) kubelet Error: ErrImagePull
kubectl logs mypod
Error from server (BadRequest): container "mypod" in pod "mypod" is waiting to start: trying and failing to pull image
kubectl logs --previous mypod container_name
Conclusion
How to scan vulnerabilities for Docker images
Vulnerability scanning for Docker
Vulnerability scanning
docker scan --help
Usage: docker scan [OPTIONS] IMAGE
A tool to scan your images
Options:
--accept-license Accept using a third party scanning provider
--dependency-tree Show dependency tree with scan results
--exclude-base Exclude base image from vulnerability scanning (requires --file)
-f, --file string Dockerfile associated with image, provides more detailed results
--group-issues Aggregate duplicated vulnerabilities and group them to a single one (requires --json)
--json Output results in JSON format
--login Authenticate to the scan provider using an optional token (with --token), or web base token if empty
--reject-license Reject using a third party scanning provider
--severity string Only report vulnerabilities of provided level or higher (low|medium|high)
--token string Authentication token to login to the third party scanning provider
--version Display version of the scan plugin
docker scan --accept-license --version
How to scan
docker scan my-image
Scan images during Development and Production
Ending thoughts
Running your first Pod on Kubernetes
What is Kubernetes
Cluster
Node
Control Plane
Kubelete
Pods
How to run your first Pod on Kubernetes
kubectl cluster-info
kubectl get pods
kubectl run ng --image=nginx
kubectl get pods
NAME READY STATUS RESTARTS AGE
ng 1/1 Running 0 98s
You can add -o wide in you get Pod command to get more information about running Pods.
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
So you get more info.
Note:
kubectl get pods will check running Pods in default Namespace. Kubernetes has a concept of Namespace. So you can have multiple namespaces. When you install Kubernetes so by default the are two namespaces.
- Default
- kube-system
kubectl get pods --all-namespaces -o wide
By running above command you can see all Pods running on all different namespaces.
What are some more flags/options in running a pod?
#Start a single instance of busybox and keep it in the foreground, don't restart it if it exits.
Command Below:
kubectl run -i --tty busybox --image=busybox --restart=Never
# Start a replicated instance of nginx.
Command Below:
kubectl run nginx --image=nginx --replicas=3
kubectl delete pod ng
pod "ng" deleted
Containers orchestration: Kubernetes vs Docker swarm
When deploying applications at scale, you need to plan all your architecture components with current and future strategies in mind. Container orchestration tools help achieve this by automating the management of application microservices across all clusters.
There are few major containers orchestration tools listed below:
- Docker Swarm
- Kubernetes
- OpenShift
- Hashicorp Nomad
- Mesos
What is container orchestration
Let's talk Kubernetes
Cluster
Node
Control Plane
Kubelete
Pods
Deployments, Replicas and ReplicaSets
Docker Swarm
Swarm
Service
Manager node
Worker node
Tasks
Choosing the right Orchestrator for your containers
Some fundamental differences between both
GUI:
- Deploy containerized application on cluster
- Manage cluster resources
- View an error log, deployments, jobs
Availability:
Scalability:
Monitoring:
How and why container monitoring is so important
What is container monitoring?
Container observability
But if you are unable to achieve observability so this can result in below:
- It is very difficult for developers and operations task to understand what is running and how it is performing. So without observability it is very difficult to troubleshoot the problem and meeting the SLA for a production system.
- Scalability is also the major challenge to achieve without observability. Scaling your application on demand can enhance your user's experience. But if scalability is too slow it can make it poor.
Challenges with container monitoring
- Containers are ephemeral so provisioning and destroying a container very quick process. This is one of the biggest advantage but for complex and big production system it makes very difficult to identify the issue.
- Containers share resources. These consume resources from host machine. If there is no monitoring of resources on host machine then any point of time high CPU or memory spike can scare you and can lead your production running application to stop.
Then how can we monitor containers
What are the common features in monitoring tools
- Real time monitoring
- Performance baseline
- Anomaly detection
- Network Performance monitoring
- Config monitoring
- Dashboards
- API monitoring
- Alerting
- Automation
Here are famous container monitoring tools used by modern industries
Prometheus
features:
- A multi-dimensional data model with time series data identified by metric name and key/value pairs
- PromQL is a flexible query language to query the dimensionality
- Multiple modes of graphing and dashboard support
Grafana
How to run PostgreSQL on Docker
Postgres on Docker
docker pull postgres
Using default tag: latest
latest: Pulling from library/postgres
a9eb63951c1c: Pull complete
b192c7f382df: Pull complete
e7ce3f587986: Pull complete
4098744a1414: Pull complete
4c98d6f3399d: Pull complete
65e57fefc38a: Pull complete
d61d9528cfd5: Pull complete
de6b20f44659: Pull complete
25db13ff0bef: Pull complete
7f74f4b0e936: Pull complete
144c847b11fb: Pull complete
cf0afd1be009: Pull complete
fe0c14991327: Pull complete
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres latest 83ce63c594ee 5 days ago 355MB
docker run --name test -e POSTGRES_PASSWORD=Test@123 -d postgres
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
83ec4a222 postgres "docker-entrypoint.s…" 2 minutes ago Up
docker exec -it 83ec4a222 bash
root@83ec4a222:/#
psql -h localhost -p 5432 -U postgres -w
psql (14.0 (Debian 14.0-1.pgdg110+1))
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=#
postgres=# select current_database();
current_database
------------------
postgres
(1 row)
postgres=# select datname from pg_catalog.pg_database;
datname
-----------
postgres
template1
template0
(3 rows)
postgres=# select table_name from information_schema.tables limit 10;
table_name
-----------------------
pg_statistic
pg_type
pg_foreign_table
pg_authid
pg_shadow
pg_statistic_ext_data
pg_roles
pg_settings
pg_file_settings
pg_hba_file_rules
(10 rows)
Quantum Computing: The Future of Supercomputing Explained
Introduction Quantum computing is revolutionizing the way we solve complex problems that classical computers struggle with. Unlike tradi...

-
How to handle Out of memory error inside Docker Container Sometimes we face some special scenarios where we encounter insufficient memory o...
-
Are you looking to run microsoft sql server on Mac? Then you are at the right place. I am going to tell you how you can run sql server easil...
-
If you are running an application on Kubernetes, you may want to expose a specific port to a pod so that you can access it outside world. Ku...
-
Running docker container as non root account. Docker is revolutionary technology in the world of devops. Today docker is making applicatio...
-
Understanding about memory and other resources consumption is very important in Kubernetes. Whenever we run a Pod it consumes some amount of...