Kubernetes Notes - Part 4
Kubernetes Notes - Part 4
Pods
Provide a runtime environment for your container to run
Deployments
A deployment declaration allows you to do app deployment and app updates.
A deployment file describes the state of your application you would like to have and kubernetes will make sure the cluster matches it
A Deployment Object will allow you to
- Create a deployment
- Update a deployment
- Rolling Updates with zero downtime deployments
- Roll back
- Pause/Resume a deployment
Some useful Commands
|
|
Replication Controller / ReplicaSet
ReplicaSet and Replication Controller have the same task but ReplicaSet is the new generation of Replication Controller
ReplicaSet supports “Set-based Selectors” while Replication Controller supports “Equality-based Selectors”
They both ensures that a specified number of pods are running at any time. The controller will make sure your cluster will always have the right amount of replicas of your POD running at the same time. If there are less the controller will launch new PODS if there are more the controller will kill PODS.
They both ensures a POD is always available
It is up to the scheduler to find out the best place to create replicas for the specific POD
Labels and Selectors
Labels and selectors give Controllers a way to know what is connected to what. It is a kind of a TAG to define relations.
When creating a deployment file for your POD you define some labels to represent it
|
|
In the example above app is a key and myapp is a value
Later when creating Controllers and Services files you use selectors to tell what are the POD you want that Service or that Controller to look at
Set-based selectors
We use Set-Based selectors in new resources such as
- ReplicaSets
- Deployments
- Jobs
- DaemonSet
Valid operators: In NotIn Exists
|
|
|
|
Supported by Job, Deployment, ReplicaSet and DaemonSet
Equality-based selectors
We use Equality-Based selectors on older resources such as
- ReplicationControllers
- Services
Valid operators: = == !=
|
|
|
|
Supported by Services, Replication Controller
ReplicaSet Example
That object file will create 3 replicas of the Rainbow app
|
|
|
|
|
|
DaemonSet
Different from ReplicaSet where the scheduler figures out which are the nodes to spin up a container a DaemonSet will ensure all (or some) Nodes will run a copy of a POD.
To delete the PODS created by a DaemonSet you must delete the DaemonSet
DaemonSets are usually used to spin up log collectors or monitoring process because you will need them to run in every node at the same time
|
|
ConfigMaps
Images are made to spin up containers that can run anywhere. They provide you the same environment and application binary to run it on your kubernetes cluster, on you local machine, etc
But let’s say you would like to have a different behavior depending on your needs. Like a different behavior when running it on production and test environments. To archive such state of configuration containers can be configured in 3 different ways:
- Configuration files
- Command line arguments
- Environment Variables
ConfigMap is a Kubernetes object that allows you to separate configuration from your components and pods. They will keep your containers portable as they were meant to be and makes the configuration easy to change (no hardcoded configuration is needed ❤️)
A ConfigMap stores configuration data as Key-Value pairs
- Configuration files
- Command line arguments
- Environment variables
ConfigMaps are similar to Secrets but they don’t and MUST NOT contain sensitive information. For sensitive information we use SECRETS
|
|
Use of ConfigMaps as a volume
|
|
Use of ConfigMaps as environment variables
|
|
Data Source
- Directories
- Files
- Literals
Secrets
Secrets are used to reduce risks of exposing sensitive data while deploying the pods.
Secrets are create outside of pods and can be injected inside any POD
Secrets are stored inside ETCD database
Secrets can be mounted as volumes or exposed by environment variables
Create Secrets
|
|
|
|
|
|
Secret types
- Generic
- File (Max 1Mb)
- Directory
- Literal Value
- Docker-Registry
- TLS
Secret data
| | | | | | | Path to dir/file | –from-file | | Key-value pair | –from-literal |
Consume Secrets
As a volume
|
|
As environment variable
|
|