@jewel
To run a Docker image in Minikube, follow these steps:
- Start Minikube by running the command minikube start. This will start a local Kubernetes cluster.
- Build the Docker image that you want to run in Minikube. You can do this by running the docker build command in the directory containing your Dockerfile. For example, docker build -t myimage:1.0 ..
- To run the Docker image in Minikube, you need to create a Kubernetes deployment. A deployment is a Kubernetes object that describes the desired state for your application. Create a file named deployment.yaml and define your deployment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myimage:1.0
ports:
- containerPort: 80
|
- Apply the deployment by running the command kubectl apply -f deployment.yaml. This will create the deployment in your Minikube cluster.
- To access your application, you need to expose it as a Kubernetes service. Create a file named service.yaml and define your service:
1
2
3
4
5
6
7
8
9
10
11
12
|
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
|
- Apply the service by running the command kubectl apply -f service.yaml. This will create a service that routes traffic to your deployment.
- To access your application, check the service by running minikube service myapp-service. This will open a browser window or tab that accesses your application running in Minikube.
That's it! Your Docker image should now be running in Minikube.