Docker is an open-source lightweight containerization technology.
It allows you to
automate the deployment of applications in lightweight and portable containers.
What command should you run to see all running container in Docker?
$ docker ps
What is the command to run the image as a container?
$ sudo docker run -i -t alpine /bin/bash
Write a Docker file to create and copy a directory and built it using python
modules?
FROM pyhton:2.7-slim
WORKDIR /app
COPY . /app
docker build –tag
------
to reduce size of a docker image
docker squash
by combining two layers into 1
RUN apt-get -y update && apt-get install -y python
use custom base images
avoid storing application data
-------------------------
kubernetes does automating deployment, scaling, and management of containerized
applications.” Kubernetes can then allow you to automate container provisioning,
networking, load-balancing, security and scaling across all these nodes from a
single command line.A collection of nodes that is managed by a single Kubernetes
instance is referred to as a Kubernetes cluster.
Why do u need more nodes
To make the infrastructure more robust: Your application will be online, even if
some of the nodes go offline, i.e, High availability.
To make your application more scalable: If workload increases, simply spawn more
containers and/or add more nodes to your Kubernetes cluster.
Kube ApI server interacts with kubectl.
etcd- state of the cluster,stores key-value pairs
kube proxy- This network proxy allows various microservices of your application to
communicate with each other, within the cluster, as well as expose your application
to the rest of the world
kubelet: Each node has a running kubelet service that updates the running node
accordingly with the configuration(YAML or JSON) file. NOTE: kubelet service is
only for containers created by Kubernetes.
Rolling updates allow Deployments' update to take place with zero downtime by
incrementally updating Pods instances with new ones
Blue/Green deployments are a form of progressive delivery where a new version of
the application is deployed while the old version still exists. The two versions
coexist for a brief period of time while user traffic is routed to the new version,
before the old version is discarded (if all goes well)
expose to outside world by change service
can test by pinging internal ip or log in to the pod and curl localhost
can test by smoke test
canary deployment gradually shift to new version( instead use service mesh like
istio)
session affinity: request will be served to a particular pod
job: once it finishes the job the pod will be deleted
cronjob: scheduled jobs
helm is used to install software in kubernetes.(helm client, helm server-tiller)
package mgr for kubernetes. do it in form of charts.
Taint is to reserve node-pool
kubectl taint node "nodename" key1=value1=noschedule
Tolerations is a pod specification
clusterip will not have external ip address
service-cluster ip is a static ip.
Exposes the Service on a cluster-internal IP. Choosing this value makes the
Service only reachable from within the cluster. This is the default ServiceType.
NodePort: Exposes the Service on the same port of each selected Node in the cluster
using NAT. Makes a Service accessible from outside the cluster using
<NodeIP>:<NodePort>. Superset of ClusterIP.
You can only use ports 30000–32767
If your Node/VM IP address change, its a drawbak
Loadbalancer: Creates an external load balancer in the current cloud (if supported)
and assigns a fixed, external IP to the Service. Superset of NodePort.
namespace-makes your applications organise into groups.each department can create
different namespace to manage quota
istio manages communication bween different microservices
An ingress is a set of rules that allows inbound connections to reach the
kubernetes cluster services.
A PersistentVolume (PV) is a piece of storage in the cluster that has been
provisioned by an administrator or dynamically provisioned using Storage Classes.
A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to
a Pod. Pods consume node resources and PVCs consume PV resources.
Terraform is a third party tool. Hasicorp Product
provider.tf configure using json
Terraform requires three steps for deployment: initializing the directory,
reviewing an execution plan, and applying (executing) the Terraform plan.
Initialization prepares the working directory for use by accounting for any changes
in Terraform's backend configuration.
--------------
What is the difference between Python Arrays and lists?
Ans: Arrays and lists, in Python, have the same way of storing data. But, arrays
can hold only a single data type elements whereas lists can hold any data type
elements.
What are functions in Python?
Ans: A function is a block of code which is executed only when it is called. To
define a Python function, the def keyword is used.
What is __init__?
Ans: __init__ is a method or constructor in Python. This method is automatically
called to allocate memory when a new object/ instance of a class is created. All
classes have the __init__ method.
What is self in Python?
Ans: Self is an instance or an object of a class. In Python, this is explicitly
included as the first parameter. However, this is not the case in Java where it’s
optional. It helps to differentiate between the methods and attributes of a class
with local variables.
How does break, continue and pass work?
Break Allows loop termination when some condition is met and the control is
transferred to the next statement.
Continue Allows skipping some part of a loop when some specific condition is met
and the control is transferred to the beginning of the loop
Pass Used when you need some block of code syntactically, but you want to skip its
execution. This is basically a null operation. Nothing happens when this is
executed.