There is an iron gallery app that the Nautilus DevOps team was developing. They have recently customized the app and are going to deploy the same on the Kubernetes cluster.
- Create a namespace
iron-namespace-devops
Create a deployment iron-gallery-deployment-devops for iron gallery under the same namespace you created.
:- Labels run should be iron-gallery.
:- Replicas count should be 1.
:- Selector's matchLabels run should be iron-gallery.
:- Template labels run should be iron-gallery under metadata.
:- The container should be named as iron-gallery-container-devops, use kodekloud/irongallery:2.0 image ( use exact image name / tag ).
:- Resources limits for memory should be 100Mi and for CPU should be 50m.
:- First volumeMount name should be config, its mountPath should be /usr/share/nginx/html/data.
:- Second volumeMount name should be images, its mountPath should be /usr/share/nginx/html/uploads.
:- First volume name should be config and give it emptyDir and second volume name should be images, also give it emptyDir.
Create a deployment iron-db-deployment-devops for iron db under the same namespace.
:- Labels db should be mariadb.
:- Replicas count should be 1.
:- Selector's matchLabels db should be mariadb.
:- Template labels db should be mariadb under metadata.
:- The container name should be iron-db-container-devops, use kodekloud/irondb:2.0 image ( use exact image name / tag ).
:- Define environment, set MYSQL_DATABASE its value should be database_apache, set MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD value should be with some complex passwords for DB connections, and MYSQL_USER value should be any custom user ( except root ).
:- Volume mount name should be db and its mountPath should be /var/lib/mysql. Volume name should be db and give it an emptyDir.
- Create a service for
iron dbwhich should be namediron-db-service-devopsunder the same namespace. Configure spec as selector's db should bemariadb. Protocol should beTCP, port and targetPort should be3306and its type should beClusterIP. - Create a service for
iron gallerywhich should be namediron-gallery-service-devopsunder the same namespace. Configure spec as selector's run should beiron-gallery. Protocol should beTCP, port and targetPort should be80, nodePort should be32678and its type should beNodePort.
Create the yaml file, iron-gallery-setup.yaml
apiVersion: v1
kind: Namespace
metadata:
name: iron-namespace-devops
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: iron-gallery-deployment-devops
namespace: iron-namespace-devops
spec:
replicas: 1
selector:
matchLabels:
run: iron-gallery
template:
metadata:
labels:
run: iron-gallery
spec:
containers:
- name: iron-gallery-container-devops
image: kodekloud/irongallery:2.0
resources:
limits:
memory: "100Mi"
cpu: "50m"
volumeMounts:
- name: config
mountPath: /usr/share/nginx/html/data
- name: images
mountPath: /usr/share/nginx/html/uploads
volumes:
- name: config
emptyDir: {}
- name: images
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: iron-db-deployment-devops
namespace: iron-namespace-devops
spec:
replicas: 1
selector:
matchLabels:
db: mariadb
template:
metadata:
labels:
db: mariadb
spec:
containers:
- name: iron-db-container-devops
image: kodekloud/irondb:2.0
env:
- name: MYSQL_DATABASE
value: database_apache
- name: MYSQL_ROOT_PASSWORD
value: "R@@tP@ssw0rd123!"
- name: MYSQL_USER
value: devuser
- name: MYSQL_PASSWORD
value: "D3v0ps@321"
volumeMounts:
- name: db
mountPath: /var/lib/mysql
volumes:
- name: db
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: iron-db-service-devops
namespace: iron-namespace-devops
spec:
type: ClusterIP
selector:
db: mariadb
ports:
- protocol: TCP
port: 3306
targetPort: 3306
---
apiVersion: v1
kind: Service
metadata:
name: iron-gallery-service-devops
namespace: iron-namespace-devops
spec:
type: NodePort
selector:
run: iron-gallery
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 32678
Apply the file:
thor@jumphost ~$ kubectl apply -f iron-gallery-setup.yaml
namespace/iron-namespace-devops created
deployment.apps/iron-gallery-deployment-devops created
deployment.apps/iron-db-deployment-devops created
service/iron-db-service-devops created
service/iron-gallery-service-devops createdVerify - check namespace, deployments, pods and services:
thor@jumphost ~$ kubectl get ns
NAME STATUS AGE
default Active 14m
iron-namespace-devops Active 65s
kube-node-lease Active 14m
kube-public Active 14m
kube-system Active 14m
local-path-storage Active 14m
thor@jumphost ~$ kubectl get all -n iron-namespace-devops
NAME READY STATUS RESTARTS AGE
pod/iron-db-deployment-devops-559f689bbc-4jjjz 1/1 Running 0 108s
pod/iron-gallery-deployment-devops-9c67c8cb7-srrk9 1/1 Running 0 108s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/iron-db-service-devops ClusterIP 10.96.107.103 <none> 3306/TCP 108s
service/iron-gallery-service-devops NodePort 10.96.73.15 <none> 80:32678/TCP 108s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/iron-db-deployment-devops 1/1 1 1 108s
deployment.apps/iron-gallery-deployment-devops 1/1 1 1 108s
NAME DESIRED CURRENT READY AGE
replicaset.apps/iron-db-deployment-devops-559f689bbc 1 1 1 108s
replicaset.apps/iron-gallery-deployment-devops-9c67c8cb7 1 1 1 108s