Running an Apache container
Creating a pod manifest file to run an Apache file is not much different than what we have seen before.
Search in directory...
/
apache.yaml
apache.yaml
12345678
apiVersion: v1
kind: Pod
metadata:
name: apache
spec:
containers:
- name: apache-container
image: httpd
Run
Save
Reset
Your app can be found at: https://ed-5009147949744128_dc.educative.run
Testing the Solution
Note: Please run the above widget, and wait for the application to load before clicking on the above URL.
In the apache.yaml file, we’re creating a pod named apache. We can name it whatever we want. But for this solution, we’re naming it “apache.” We can change the name of this pod in line 4. In line 7 and 8, we’re specifying the name and image of the container. We’re naming our container apache, and httpd is the name of the docker image that belongs to Apache.
Let’s apply this manifest using the following command:
kubectl apply -f apache.yaml
Next, let’s check the pods we have running:
kubectl get pods
Once the pod is in the running state, we’ll use kubectl port-forward to send requests from localhost:3000 to the container’s port 80:
kubectl port-forward apache 3000:80
Note: We need to add the --address 0.0.0.0 flag to the above command to run it on this platform, so the above command would become: kubectl port-forward apache --address 0.0.0.0 3000:80. Or if you want to execute it with nohup, the updated command would be: nohup kubectl port-forward --address 0.0.0.0 apache 3000:80 > /dev/null 2>&1 &. Press Ctrl+D to exit out of the shell session.
Now, if you access the URL in the SPA widget, you should see the default apache page.
Default Apache page
Now, let’s try to change the contents of the /usr/local/apache2/htdocs/index.html file. For this, we need to enter the container by running the following command:
kubectl exec -it apache -- sh
Once inside the container, we can change the contents of this file to whatever string we want. But for the sake of this example, let’s change it to “Welcome to Apache!” We can use the following command to do just that: