Ex 9
Ex 9
Description:
To automate the process of running the containerized application developed in exercise 7
using Kubernetes, follow these steps:
3. Create a Deployment
Create a deployment in Kubernetes that specifies the number of replicas and the Docker
image to use. Below is an example YAML file for the deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myimage
ports:
- containerPort: 80
4. Create a Service
Create a service in Kubernetes that exposes the deployment to the network. Below is an
example YAML file for the service:
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- name: http
port: 80
targetPort: 80
type: ClusterIP
Additional Notes
This is a basic example of how to automate the process of running a containerized
application using Kubernetes. In real-world scenarios, you might need to handle additional
complexities such as:
- Managing persistent data.
- Scaling applications.
- Rolling updates.
This lab provides a good starting point for using Kubernetes to manage your containers.
Result
By following this lab manual, you successfully automated the process of running the
containerized application developed in Exercise 7 using Kubernetes.