Config Maps
- One way to think of ConfigMap is as a k8s object that defines a small file system.
- Another way is a set of variables that can be used when defining the environment or command line for your container
- In config map we generally define application related configuration data. We can create ConfigMap through a literal value or from a file
- Creating config map from literal values and mount it to the Pod
kubectl create configmap --help
kubectl create configmap onevalue-cmap --from-literal=message=Hello --from-literal=url=https://qt.com/downloads/test.html
- Now lets create a Pod and mount the config maps as environment variables Refer Here for the changeset and apply this manifest
- Now lets login into the container and check environment variables
- Now lets create a configmap as Manifest Refer Here for the changeset and apply the manifests
- When you change the config maps and want to apply it your deployment use kubectl rollout restart Refer Here
Secrets
- They are much like config map, but in secrets values are base64 encoded
- Lets create the following secrets
kubectl create secret generic my-secret --from-literal=username=qtdevops --from-literal=password=qtdevops
- Refer Here for the changeset
Stateful Sets
- Kubernetes statefulsets are useful for running things in cluster e.g hadoop cluset, mysql cluster where each Pod is expected to have its own storage
- In Statefulset also we would have replicas, but each replica will have its own Persitent volume claim placed
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi
Elastic Kubernetes Services (EKS)
- To setup the EKS Refer Here
- In this case i would be using the eksctl way of bringing up kubernetes cluster
- To install eksctl Refer Here
- Refer Here to create and configure iam user
- Now lets create a k8s cluster
eksctl create cluster --name my-cluster --version 1.21 --with-oidc --without-nodegroup
- Lets add nodes to the eks cluster
eksctl create nodegroup `
--cluster my-cluster `
--region us-west-2 `
--name my-mng `
--node-type t2.large `
--nodes 2 `
--nodes-min 1 `
--nodes-max 2 `
--ssh-access `
--ssh-public-key docker
- Deleting the node group
eksctl delete nodegroup --cluster my-cluster --name my-mng
- Deleting the cluster
eksctl delete cluster --name my-cluster
Exercise
- Refer Here for the article which is about the journey of application from containers to k8s
