Understand Service and Deployment in Kubernetes

1/18/2018

I have created below service and pod in a single yaml.

I am listing down the steps and my understanding on deployment and service below. Please let me know if my understanding is correct and guide me for imporvements.

  1. create a deployment with 1 replica for my spring boot application.
  2. The container Port is 80 meaning any other application which needs to send a request to the application running in this container be sent on port 80 on "Cluster IP".

  3. Exposing 8080 to the outside world to access it meaning i can hit this service with "External IP". This External IP and cluster IP detaisl can be retrieved using kubectl get svc ReferenceDataService.

  4. The Target Port in service makes sure that requests received from outside world on 8080 are posted on 80 of the container port.

  5. Azure Files are used for accessing my data. Pod would have /mnt/azure in it created. Meaning if i have /A/B/C folder created in Azure file torage, I can access files in /A/B/C using path /mnt/azure/A/B/C.


apiVersion: v1  
kind: Service  
metadata:  
name: ReferenceDataService  
 labels:  
  run: my-rflabel  
spec:  
  type: NodePort  
  ports:
- port: 8080  
        targetPort: 80    
    protocol: TCP  
    name: http  
  selector:  
    run: my-rflabel  
apiVersion: apps/v1beta1  
kind: Deployment  
metadata:  
  name: my-rflabel  
spec:  
 replicas: 1  
  template:  
    metadata:  
      labels:  
        run: my-rflabel  
    spec:  
      volumes:  
      - name: lhapidatasource  
        azureFile:  
        secretName: azure-secret  
        shareName: openapidevshare  
        readOnly: false  
      containers:  
      - name: referencedata  
        image: **/referencedata:v1  
        ports:  
       - containerPort: 80  
         volumeMounts:  
      - name: lhapidatasource  
        mountPath: /mnt/azure  
-- Anil Kumar P
azure
kubernetes

1 Answer

1/22/2018

2.The container Port is 80 meaning any other application which needs to send a request to the application running in this container be sent on port 80 on "Cluster IP".

Yes, you are right, k8s will communicate with other pods with Cluster IP.

3.Exposing 8080 to the outside world to access it meaning i can hit this service with "External IP". This External IP and cluster IP detaisl can be retrieved using kubectl get svc ReferenceDataService.

You can hit that service with External IP and port, like this:

root@k8s-master-79E9CFFD-0:~# kubectl get service azure
NAME               CLUSTER-IP     EXTERNAL-IP      PORT(S)          AGE
azure              10.0.136.182   52.224.219.190   8080:31419/TCP   10m

4.The Target Port in service makes sure that requests received from outside world on 8080 are posted on 80 of the container port.

You have map k8s service port 8080 to port 80(pod). So you can hit service with External IP with port 8080 to access pod my-rflabel.

5.Azure Files are used for accessing my data. Pod would have /mnt/azure in it created. Meaning if i have /A/B/C folder created in Azure file torage, I can access files in /A/B/C using path /mnt/azure/A/B/C.

Right, you can use path /mnt/azure/A/B/C to access files.

-- Jason Ye
Source: StackOverflow