Httpd Deploy in Kubernetes: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 20: Line 20:


<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='yaml'>
apiVersion: v1
kind: Pod
metadata:
  name: 'httpd-local'
  labels:
    function: 'httpd-server'
spec:
  containers:
  - name: 'httpd'
    image: docker.io/ovidiufeodorov/httpd:latest
    volumeMounts:
      - name: 'httpd-local-root'
        mountPath: '/usr/local/apache2/htdocs'
  volumes:
    - name: 'httpd-local-root'
      hostPath:
        path: /Users/ovidiu/runtime/httpd-root
---
apiVersion: v1
kind: Service
metadata:
  name: 'httpd-local'
spec:
  type: 'LoadBalancer'
  selector:
    function: 'httpd-server'
  ports:
    - name: 'http'
      protocol: 'TCP'
      port: 80
      targetPort: 80
</syntaxhighlight>
</syntaxhighlight>


==hostPath==
==hostPath==

Revision as of 19:20, 15 December 2019

Internal

Overview

This is a procedure to deploy httpd as a pod in Kubernetes and make it serve content form a local directory, mounted as "hostPath". The procedure was written using Docker Desktop Kubernetes.

Playground

https://github.com/ovidiuf/playground/tree/master/kubernetes/httpd-serving-local-hostPath

Procedure

Local Directory

Create a local directory that will host the content to be served by httpd.

mkdir ~/runtime/httpd-root

Pod and Service Manifest

apiVersion: v1
kind: Pod
metadata:
  name: 'httpd-local'
  labels:
    function: 'httpd-server'
spec:
  containers:
  - name: 'httpd'
    image: docker.io/ovidiufeodorov/httpd:latest
    volumeMounts:
      - name: 'httpd-local-root'
        mountPath: '/usr/local/apache2/htdocs'
  volumes:
    - name: 'httpd-local-root'
      hostPath:
        path: /Users/ovidiu/runtime/httpd-root
---
apiVersion: v1
kind: Service
metadata:
  name: 'httpd-local'
spec:
  type: 'LoadBalancer'
  selector:
    function: 'httpd-server'
  ports:
    - name: 'http'
      protocol: 'TCP'
      port: 80
      targetPort: 80

hostPath