My client has a deployment requiring the following three items:
The deployment is currently running with items 1 and 3. I would like to add item 2 (the websockets server).
I'd like to use a container for each of the above, in the same pod. It doesn't make any sense to me to create an entirely new deployment just to host the websockets server.
Since the proposed websockets server runs off the same Dockerized application that the Artisan server does, I am using the same image to build a matching container, using a different port and a different CMD.
Is this a good way to approach this, or is there a better way? Here is my Kubernetes file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: zebra-master
labels:
app: zebra-master
spec:
replicas: 1
selector:
matchLabels:
app: zebra-master
template:
metadata:
labels:
app: zebra-master
spec:
containers:
- name: zebra-master
image: registry/zebra-master:build-BUILDNUMBER
ports:
- containerPort: 8080
command: ["php artisan serve --host=0.0.0.0 --port=8080 -vvv"]
- name: websockets-master
image: registry/zebra-master:build-BUILDNUMBER
ports:
- containerPort: 6001
command: ["php artisan websockets:serve"]
- name: mysql
image: mysql/mysql-server:5.7
ports:
- containerPort: 3306
volumeMounts:
...
restartPolicy: Always
volumes:
...
---
apiVersion: v1
kind: ConfigMap
...
---
apiVersion: v1
kind: Service
metadata:
name: zebra-master
annotations:
field.cattle.io/targetWorkloadIds: '["deployment:default:zebra-master"]'
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
workload: "zebra-master"
type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: zebra-master
spec:
rules:
- host: zebra.com
http:
paths:
- backend:
serviceName: zebra-master
servicePort: 8080
path: /
if i undestand, you want to run the websocket on the zebra-master, and run the php project on the same time, i saw that you are using "command". i found this maybe it should help you : How to set multiple commands in one yaml file with Kubernetes?
and for the port you can add this lines :
ports:
- containerPort: 8080
name: http
- containerPort: 6001
name: websocket-port
in my case i will rebuild the images entrypoint with the websocket command.