@int128

int128.hatenablog.com

Deploy static site on nginx pod

滅多に変更しない静的ページを配置したい時に便利です。

apiVersion: v1
kind: ConfigMap
metadata:
  name: landing-page
data:
  index.html: |
    <!DOCTYPE html>
    <html>
    <body>
      <h2>Welcome</h2>
    </body>
    </html>
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: landing-page
spec:
  rules:
  - host: www.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: landing-page
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: landing-page
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: landing-page
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: landing-page
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: landing-page
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
        - name: html
          mountPath: /usr/share/nginx/html
        livenessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: 2
          timeoutSeconds: 3
        readinessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: 2
          timeoutSeconds: 3
          periodSeconds: 5
      volumes:
      - name: html
        configMap:
          name: landing-page
kubectl apply -f landing-page.yaml