Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Run and expose php-apache server

To demonstrate HPA, we will use a custom docker image based on the php-apache image. Copy the following lines of code into the Dockerfile and index.php files and place them in the same folder. Then run the docker build . command

Code Block
languagephp
titleDockerfile and index.php
collapsetrue
FROM php:5-apache
COPY index.php /var/www/html/index.php
RUN chmod a+rx index.php

// These lines of code define the index.php file, which performs some CPU intensive computations
<?php
  $x = 0.0001;
  for ($i = 0; $i <= 1000000; $i++) {
    $x += sqrt($x);
  }
  echo "OK!";
?>

...

Apply the following file, to install a simple PHP web application in the Kubernetes cluster. Then, verify the pods were created.

Code Block
languageyml
titlephp-apache.yaml
collapsetrue
apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-apache
spec:
  selector:
    matchLabels:
      run: php-apache
  replicas: 1
  template:
    metadata:
      labels:
        run: php-apache
    spec:
      containers:
      - name: php-apache
        image: k8s.gcr.io/hpa-example
        ports:
        - containerPort: 80
        resources:	# <--- Pay attention
          limits:
            cpu: 500m
          requests:
            cpu: 200m
---
apiVersion: v1
kind: Service
metadata:
  name: php-apache
  labels:
    run: php-apache
spec:
  ports:
  - port: 80
  selector:
    run: php-apache

...