Container Architectures Flashcards
Dockers, Kubernetes, Anthos
What are the technical benefits of containerisation?
1) Portability - Applications / services easily transport between different servers and environments.
2) Less Resources - Efficiency through using far fewer resources than VMs as your are only virtualising the OS rather than the entire infra.
3) DevOps – Bridges the environment and dependency logic between development and production.
4) Teams can create functionality with its own life cycle and scaling policies.
5) Security - Improved security by isolating applications from the host system and from each other.
6) Faster - Faster app start-up and easier scaling.
What are the business benefits of containerisation?
1) Consistency leading to lower cost of development via reduced overhead between development and operation.
2) Loose coupling, avoiding legacy and vendor lock-in
3) Agility
How do you list all docker images?
docker images
How would you go about deleting an old docker image?
docker rmi {image_name}
docker image rm {image_name}
How would you go about running a container from a local docker image in detached mode?
docker run -d {image_name : image_tag}
How would you go listing all running containers on docker?
docker ps
container ls
How would you list docker containers even in exited state?
docker ps -a
How would you go about mapping your dockerhost port to the container port when spinning up a container?
Docker run -d -p {dockerhost_portnumber}:{container_portnumber} {image_name}:{tag_id}
For example:
Docker run -d -p 8080:80 nginx:latest
How would you go about mapping multiple ports on the host when spinning up a container?
Docker run -d -p {{dockerhost_portnumber}:{container_portnumber} -p {dockerhost_portnumber}:{container_portnumber} {image_name}:{tag_id}
For example:
Docker run -d -p 3000:80 -p 8080:80 nginx:latest
How would you run a container in docker with a name?
Docker run –name {name} -d {image_name}:{tag_id}
What is the purpose of docker volumes?
Allows us to MOUNT data between:
1) Host and container
2) Between multiple containers
What command flag would you use to mount files between host and container in docker?
-v {host_destination} :{ conatiner_destination}
How would you go about running commands within a active container in docker?
docker exec -it { container_name } bash
How do you exit the CLI of a “stepped into” container?
ctrl + d
What flag would you use to mount files between two containers in docker?
docker run –volumes-from { target_container_name }
How would you go about building a docker image from a local dockerfile named “website”?
docker build -t website:latest .
Are docker volumes better in dev or prod and why?
Development, for connecting local file system to container file system.
This is not as required prod, as you can use the dockerfile to move files between host and container.
What’s the difference between CMD and RUN within a dockerfile?
RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image.
CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined.
How would you go about taking advantage of caching within docker builds?
Integrated the ADD and COPY commands into the Dockerfile.
The ADD and COPY commands in a Dockerfile allow you to import external files into a Docker image.
If the contents of all external files on the first ADD command are the same, the layer cache will be used and all subsequent commands until the next ADD or COPY command will use the layer cache.
However, if the contents of one or more external files are different, then all subsequent commands will be executed without using the layer cache.
If you would like to reduce the size or resource efficiency of a single container, how would you go about it?
Use an alpine distribution of the container to reduce the image size.
How would you go about tagging a existing docker image to give a version number?
docker tag website:latest website:1.0.0
Where does the word Kubernetes come from?
Greek for “Captain”
Why was Kubernetes invented by Google?
The rise of microservices caused an increased usage of container technologies, because containers offer the perfect host for small, independent and decoupled applications and servcies.
The rise of loosely coupled services resulted in the creation of applications that comprise of 100’s or even 1000’s of containers. Managing this number of containers across multiple environments using just scripts and self-made tools became more complex than managing a monolith.
What benefits does container orchestration offer?
High availability
Automation - Automates deployment, scaling, load balancing, logging and monitoring of containers.
Self-Healing - Automatically replaces unhealthy or failed conatiners.
What is a pod and why is it a kubernetes concept?
A running environment for a container.
The reason kubernetes abstracts pods as a layer ontop of the container is to give the engineers choice over which container runtime environment is used.
What does it mean when we claim that pods in kubernetes are ephemeral?
The last for a very short length of time. They are not infinite.
What happens when a pod goes down on a node in kubernetes?
A new pod will get created in its place, and the new pod will get assigned it’s own new IP address on re-creation.
What is a service within kubernetes and why is it used?
A static/permanent IP address that can be assigned to each pod.
Services are used to disconnect lifecycles of pods from services, meaning that services are still discoverable even if pods go down and their IP addresses change.
They can also be used to share services between different replicas of the same application running on different nodes.
What is a ingress within a Kubernetes node and why is it used?
Think of it as a service for services!
An ingress is an API object that manages external inbound connections to a set of existing services within a cluster, typically HTTP.
Ingress can be used for load balancing, SSL certificates and name-based virtual hosting (i.e. providing domain names to external services rather than IP addresses).
Does your Kubernetes Cluster manage any data persistence?
No - You have to use volumes to persist data either within a kubernetes node itself or within a remote storage service.
If you do not use volumes, any data will be lost whenever a pod goes down and is recreated.
What is a StatefulSet in kubernetes and why is it used?
StatefulSet is used to ensure data consistency between multiple database replicas. It does this by ensuring the database reads and writes are synchronised.
How would you go about creating a deployment of a single pod with nginx running on it on kubernetes?
kubectl create deployment nginx –image=nginx
How would you go about logging activity on a pod?
kubectl logs pod_name
How would you go about creating a kubernetes deployment from a yaml file?
kubectl apply -f config-file.yaml
How would you go about storing sensitive environmental variables in kubernetes?
You would store them on K8 itself rather than in any files being pushed to a repository, and you would accomplish this via creating a secret.
You create a secret by creating a new configuration file, setting “kind: Secret” and “type: Opaque” and then run the below command:
kubectl apply -f filename.yaml
What is the difference between a kubernetes secret and a kubernetes ConfigMap?
Secrets store data in base64 format meanwhile ConfigMaps store data in a plain text. So:
Use Secrets for things which are actually secret like API keys, credentials, etc
Use ConfigMaps for not-secret configuration data that needs to be shared among multiple components/services
What do you need to additionally specify on a service config file in order to create an external service?
type: LoadBalancer
nodePort: range from 30000 - 32767
What is the default service type on a kubernetes config file if you do not specify one?
clusterIP, also known as Internal Service
What are the 3 primary things namespaces are used for in Kubernetes?
1) You can organise resources inside a virtual cluster within your cluster. These resources might be grouped by function, for example:
Database
Monitoring
Elastic Stack
Web Server Ingress
2) You can also use it to separate out teams to ensure nobody overwrites deployments with the same name. You can even assign access and resource limits for users within these name spaces for security and cost saving benefits.
3) You can use namespaces to serparate out Dev, Staging and Prod environments.
How would you go about placing a domain name url on your kubernetes service?
Using an ingress.
You create one of these within a configuration.yaml file by specifying “kind: Ingress” and then write routing rules for forwarding requests to the internal service(s).
You will also need to install an Ingress Controller pod which will act as the entrypoint to the K8 cluster and will evaluate all the rules and manage redirections.
What is Helm and what can it be used for?
Helm is a package manager for kubernetes.
It can be used for:
1) Download Helm Charts from public and private registries.
2) A templating engine for YAML configuration files.
3) Deploying the same application across development, staging and production environments.
What is Helm Charts?
Package collections of YAML file and that are distributed via public and private registries.
For example, there can be a mongodb Helm Chart that contains all the necessary YAML files to setup express,, mongodb and any ingress config files.
How would you use Helm as a templating engine?
You would create a template YAML file with placeholders within appropriate value fields.
Then you would create a values.yaml file to specify the values used for that deployment.
What is the need for volumes within Kubernetes?
To persist data by creating a data store that is not dependent upon pod lifecycles.
How is persistent data storage achieved within kubernetes?
You use volumes to plug in an external database solution or file storage system into your K8 cluster.
What is a headless service within Kubernetes?
Making requests directly to pods rather than going through a clusterIP address or loadbalancer.
This is useful for stateful database storage services as the pods do not necessarily all have the same read / write responsibiltiies.
What does Anthos use for logging and monitoring within hybrid-cloud environments?
Stackdriver
What are nodes within Kubernetes?
Compute Engine instances (VMs) that house groups of pods.
How would you go about creating a GKE instance in the GCP CLI?
gcloud container clusters create webfrontend –zone $MY_ZONE –num-nodes 2
How would you go about building a docker image within the GCP CLI?
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/{container_directory} {path_to_dockerfile}
The files are staged in Cloud Storage, and a Docker image is built and stored in the Container Registry.