0

I have theoretically gone through hostNetwork definition provided by Kubernetes. For the below pod spec

cat hostpod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  #hostNetwork: true
  containers:
  - image: ubuntu
    name: test-container
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
    securityContext:
      privileged: false
      runAsNonRoot: false
      runAsUser: 0
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /usr/local
      # this field is optional

And trying to write to a file

root@test-pd:/test-pd# touch newthree.txt
touch: cannot touch 'newthree.txt': Permission denied

But this works when I set hostNetwork:true.

could I get some inf on how this actually works and why hostNetwork is required.

ambikanair
  • 4,004
  • 11
  • 43
  • 83
  • There is absolutely zero relation between hostNetwork and an hostPath volume. It must be something else. Can it be your pod is scheduled in different nodes and it works on one of the nodes but no on another one? – whites11 Jul 22 '21 at 07:05
  • To build on @whites11's comment, this setup will write to a file on some random node in the cluster, but you don't really have control over which one, and if you delete and recreate this pod it will run on different nodes. You might need a different [volume type](https://kubernetes.io/docs/concepts/storage/volumes/#volume-types) if you want the data to be persisted, or to use a lighter-weight orchestrator (or not use a container at all) if you're not in a multi-node environment. – David Maze Jul 22 '21 at 11:13
  • could it be related to any SCC policy. This is an openshift environment – ambikanair Jul 23 '21 at 03:58

0 Answers0