Andrean
Andrean

Reputation: 353

Kubernetes YAML deploy for multiple images in same pod?

I would to deploy, through kubernetes, two applications in local docker images (no docker hub/artifactory). I want them to see each other through name (no ip), so I should deploy them in the same POD and load the name of the first as system environment variable in the second container.

They should be both visible from the external, so I need NodePort deploy and I would be able to choose the port.

I know how to reach this goal through kubectl cli commands, but I would to have the result through a YAML configuration file so I can apply with the command kubectl apply -f deploy.yml

Upvotes: 0

Views: 3433

Answers (1)

Oli
Oli

Reputation: 1

Technically, You can deploy multiple app containers in same POD but you should avoid that as

  • you want to scale them independently (X replicas of APP1 and Y replicas of APP2)
  • also to keep resource allocation dedicated to one kind of application
  • and many more benefits of isolation

As far as communicating them via name (no IP) kubernetes has the concept of services to achieve that with ease.

All of this can be written in YAML format

You can see this:

https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/

https://kubernetes.io/docs/tutorials/stateless-application/guestbook/

BUT STILL If you want to do this........ Then containers inside same pod can communicate with each other using localhost and in YML can you define spec for multiple container

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: app1-container
    image: app1
  - name: .... for app 2
    image: app2

Upvotes: 2

Related Questions