# app.yaml
apiVersion: v1
kind: Namespace
metadata:
name: count-ns
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
namespace: count-ns
spec:
replicas: 1
selector:
matchLabels:
app: webapp # let deployment know which pod for this deployment
template: # configuration for pods
metadata:
labels:
app: webapp # each pod has a unique name, but pods can share the same label
spec:
containers: # containers in a pod, usually add one container per pod
- name: webapp
image: lchenlangley/count # pull image from local
imagePullPolicy: Never
ports:
- containerPort: 5000
env:
- name: MYREDIS_HOST
value: redis-service
---
apiVersion: v1
kind: Service
metadata:
name: webapp-service # service name accessed by app
namespace: count-ns
spec:
selector:
app: webapp # match the pod labels
ports:
- protocol: TCP
port: 5000 # service port
targetPort: 5000 # pod port
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deployment
labels:
app: redis
namespace: count-ns
spec:
replicas: 1
selector:
matchLabels:
app: redis # let deployment know which pod for this deployment
template: # configuration for pods
metadata:
labels:
app: redis # each pod has a unique name, but pods can share the same label
spec:
containers: # containers in a pod, usually add one container per pod
- name: redisdb
image: redis:alpine # pull image from Docker Hub
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
name: redis-service # service name accessed by app
namespace: count-ns
spec:
selector:
app: redis # match the pod labels
ports:
- protocol: TCP
port: 6379 # service port
targetPort: 6379 # pod port
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress # ingress name
namespace: count-ns
spec:
rules:
- host: count.org
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: webapp-service # service name
port:
number: 5000 # service port
kubectl apply -f app.yaml