How curl Pod k8S

9/4/2019

I have installed 1 master and two nodes. I have created namespace for a POD. I have launched a Yaml file provided by linux academy on a tutorial see below tutorial But I when I do my command curl it's doesn't work.

[rbo@K8SMaster ~]$ curl 10.244.1.2:80

Yaml file

apiVersion: v1
kind: Pod
metadata:
  name: examplepod
  namespace: pod-example
spec:
  volumes:
  - name: html
    emptyDir: {}
  containers:
  - name: webcontainer
    image: nginx
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
  - name: filecontainer
    image: debian
    volumeMounts:
    - name: html
      mountPath: /html
    command: ["/bin/sh", "-c"]
    args:
      - while true; do
         date >> /html/index.html;
         sleep 1;
        done

Command:

    [rbo@K8SMaster ~]$ kubectl get nodes
NAME        STATUS   ROLES    AGE     VERSION
k8smaster   Ready    master   4d17h   v1.15.3
k8snode1    Ready    <none>   3d23h   v1.15.3
k8snode2    Ready    <none>   3d16h   v1.15.3


kubectl create namespace podexample
kubectl create -f pod-example.yml
pod/examplepod created

kubectl get pods --all-namespaces
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
kube-system   coredns-5c98db65d4-9929x            1/1     Running   216        4d17h
kube-system   coredns-5c98db65d4-mb9t2            1/1     Running   216        4d17h
kube-system   etcd-k8smaster                      1/1     Running   1          4d17h
kube-system   kube-apiserver-k8smaster            1/1     Running   1          4d17h
kube-system   kube-controller-manager-k8smaster   1/1     Running   1          4d17h
kube-system   kube-flannel-ds-amd64-2d28b         1/1     Running   1          3d23h
kube-system   kube-flannel-ds-amd64-kpnqs         1/1     Running   1          3d16h
kube-system   kube-flannel-ds-amd64-zbh7z         1/1     Running   1          4d17h
kube-system   kube-proxy-24msd                    1/1     Running   1          4d17h
kube-system   kube-proxy-ghngr                    1/1     Running   0          3d16h
kube-system   kube-proxy-mg25z                    1/1     Running   1          3d23h
kube-system   kube-scheduler-k8smaster            1/1     Running   1          4d17h
podexample    examplepod                          2/2     Running   0          5m33s

Thanks for help and sorry i'am newbies with K8S

-- rab
curl
kubernetes

1 Answer

9/5/2019

I think curl command is right but nginx container have nothing to return on port 80 . Make sure pvc is created and manually check this directory -> /usr/share/nginx/html if it have index.html or not and also check whether index.html file have read permission.

-- shubham_asati
Source: StackOverflow