Skip to content

Instantly share code, notes, and snippets.

@jasperf
Forked from matthewpalmer/pod.yaml
Created January 10, 2021 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperf/96f165af4f633eb8cff2978e03f7c598 to your computer and use it in GitHub Desktop.
Save jasperf/96f165af4f633eb8cff2978e03f7c598 to your computer and use it in GitHub Desktop.
kubernetes nginx php-fpm pod
# Create a pod containing the PHP-FPM application (my-php-app)
# and nginx, each mounting the `shared-files` volume to their
# respective /var/www/html directories.
kind: Pod
apiVersion: v1
metadata:
name: phpfpm-nginx-example
spec:
volumes:
# Create the shared files volume to be used in both pods
- name: shared-files
emptyDir: {}
# Add the ConfigMap we declared above as a volume for the pod
- name: nginx-config-volume
configMap:
name: nginx-config
containers:
# Our PHP-FPM application
- image: my-php-app:1.0.0
name: app
volumeMounts:
- name: shared-files
mountPath: /var/www/html
# Important! After this container has started, the PHP files
# in our Docker image aren't in the shared volume. We need to
# get them into the shared volume. If we tried to write directly
# to this volume from our Docker image the files wouldn't appear
# in the nginx container.
#
# So, after the container has started, copy the PHP files from this
# container's local filesystem (/app -- added via the Docker image)
# to the shared volume, which is mounted at /var/www/html.
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "cp -r /app/. /var/www/html"]
# Our nginx container, which uses the configuration declared above,
# along with the files shared with the PHP-FPM app.
- image: nginx:1.7.9
name: nginx
volumeMounts:
- name: shared-files
mountPath: /var/www/html
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
@jasperf
Copy link
Author

jasperf commented Jan 10, 2021

Basically you should use kind pod only for local usage (development). For production it is better to work with kind deployment Deployments allow you work with replicas to revive pods when need be. You can also work with container resources (ram/cpu) but that goes the same for pods. It is the replication / revival that is key here.

See https://stackoverflow.com/questions/41325087/what-is-the-difference-between-a-pod-and-a-deployment

Because you need a deployment object - or other Kubernetes API objects like a replication controller or replicaset - that needs to keep the replicas (pods) alive (that's kind of the point of using kubernetes).

I create pods without deployment when I don't need kubernetes to re create pods when deleted. One use case is to test things out by creating a pod first.

...one deployment can have many running instances(replicas).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment