Kubernetes Ingress
To switch between namespaces:
kubectl get ns
kubens <namespace-name>
Ingress (Path Based Routing)
1. Create a Docker Image:
In your project directory, create a Dockerfile (as shown earlier) and organize your HTML content in separate folders (app1 and app2). Your directory structure might look like this:
project-directory/
├── Dockerfile
├── app1/
│ └── index.html (content for /app1)
├── app2/
│ └── index.html (content for /app2)Your Dockerfile should copy these folders into the Nginx default HTML directory (/usr/share/nginx/html).
2. Build and Push Docker Image:
Build the Docker image and push it to a container registry of your choice (e.g., Docker Hub, Google Container Registry, or a private registry). Replace [YOUR_REGISTRY], [YOUR_IMAGE_NAME], and [TAG] with appropriate values:
docker build -t [YOUR_REGISTRY]/[YOUR_IMAGE_NAME]:[TAG] .
docker push [YOUR_REGISTRY]/[YOUR_IMAGE_NAME]:[TAG]3. Create Kubernetes Deployment and Service:
Create a Kubernetes Deployment and Service for your Nginx application. Here's an example YAML file (nginx-app-deployment-service.yaml):
Apply this configuration to your cluster:
4. Create an Ingress Resource for Path-Based Routing:
Create an Ingress resource (nginx-app-ingress.yaml) to configure path-based routing:
Apply the Ingress configuration to your cluster:
5. DNS Configuration:
Ensure that the DNS records for your domains or subdomains point to the IP address or LoadBalancer of your Kubernetes cluster.
6. Access Your Application:
After applying the Ingress configuration and ensuring proper DNS setup, you should be able to access your application using the paths /app1 and /app2 based on the path-based routing rules defined in the Ingress.
For example:
http://your-domain/app1should serve content from the/usr/share/nginx/html/app1directory.http://your-domain/app2should serve content from the/usr/share/nginx/html/app2directory.