简体   繁体   中英

Need help running two OS containers in a single pod on kubernetes

I'm still new to Kubernetes. I'm trying to run a ubuntu container and a linux kali container within the same pod on kubernetes. I also need those two containers to be able to be accessed from a browser. My approach right now is using ubuntu and kali docker image with VNC installed.

Here are the docker image that I'm trying to use:

Here is the YAML file for creating the pod:

apiVersion: v1
kind: Pod
metadata:
  name: training
  labels:
    app: training
spec:
  containers:
    - name: kali
      image: jgamblin/kalibrowser-lxde
      ports:
        - containerPort: 6080
    - name: centos
      image: consol/centos-xfce-vnc
      ports:
        - containerPort: 5901

Here's the problem. When I run the pod with those 2 containers, only the Kali container is having issue running, cause it to keep on restarting.

May I know how I can achieve this?

jgamblin/kalibrowser-lxde image require tty (display) allocation.

You can see an example command on docker hub page.

Then you should allow it in your Pod manifest:

apiVersion: v1
kind: Pod
metadata:
  name: training
  labels:
    app: training
spec:
  containers:
    - name: kali
      image: jgamblin/kalibrowser-lxde
      ports:
        - containerPort: 6080
      tty: true
    - name: centos
      image: consol/centos-xfce-vnc
      ports:
        - containerPort: 5901

Put tty: true in kali container declaration.

You can add a simple sleep command to be executed inside then container to keep it running, for example:

apiVersion: v1
kind: Pod
metadata:
  name: training
  labels:
    app: training
spec:
  containers:
    - name: kali
      image: jgamblin/kalibrowser-lxde
      ports:
        - containerPort: 6080
      command: ["bash", "-c"]
      args: ["sleep 500"]
    - name: centos
      image: consol/centos-xfce-vnc
      ports:
        - containerPort: 5901`

This way the pod will be in running state:

kubectl get pod
NAME                            READY   STATUS    RESTARTS   AGE
training                        2/2     Running   0          81s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM