I am not be able to access my service from my local machine. I had done my k8 deployment using minikube and created a service of NodePort type to access it.
C:\WINDOWS\system32>kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
fromk8dashboard 2/2 2 2 25m
And the service
C:\WINDOWS\system32>kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
fromk8dashboard NodePort 10.100.68.204 <none> 31000:32058/TCP 26m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24h
When I run the command:
C:\WINDOWS\system32>minikube service fromk8dashboard
|-----------|-----------------|--------------------------|----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-----------------|--------------------------|----------------------------|
| default | fromk8dashboard | tcp-31000-80-6bw28/31000 | http://172.26.75.182:32058 |
|-----------|-----------------|--------------------------|----------------------------|
* Opening service default/fromk8dashboard in default browser...
This opens the url "http://172.26.75.182:32058" on browser but it shows the site cannot be reached. Am I missing some config or proxy settings?
Another query is, my kubernetes dashboard is running on "http://127.0.0.1:61750/", so shouldn't the service nodeport url be http://127.0.0.1:32058/ or localhost:32058 ?
Describe service returns the below result:
C:\WINDOWS\system32>kubectl describe svc fromk8dashboard
Name: fromk8dashboard
Namespace: default
Labels: k8s-app=fromk8dashboard
Annotations: <none>
Selector: k8s-app=fromk8dashboard
Type: NodePort
IP: 10.100.68.204
Port: tcp-31000-80-6bw28 31000/TCP
TargetPort: 80/TCP
NodePort: tcp-31000-80-6bw28 32058/TCP
Endpoints: 172.17.0.7:80,172.17.0.8:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
C:\WINDOWS\system32>kubectl describe pod fromk8dashboard-6f98f9468c-wjrd5
Name: fromk8dashboard-6f98f9468c-wjrd5
Namespace: default
Priority: 0
Node: minikube/172.26.75.182
Start Time: Tue, 12 May 2020 17:43:05 +0530
Labels: k8s-app=fromk8dashboard
pod-template-hash=6f98f9468c
Annotations: <none>
Status: Running
IP: 172.17.0.8
Controlled By: ReplicaSet/fromk8dashboard-6f98f9468c
Containers:
fromk8dashboard:
Container ID: docker://eef3ecc8e564d9439b66592aa2f1eebd0a886e6380986066ae61bb00193c3687
Image: ranjit1827/niguel
Image ID: docker-pullable://ranjit1827/niguel@sha256:b9229b2fdc7e5e3e9872189b3840f3c6f23d312af1bff9bbf5a5c68428be5894
Port: <none>
Host Port: <none>
State: Running
Started: Tue, 12 May 2020 17:43:30 +0530
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-rn7lm (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-rn7lm:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-rn7lm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
My service yaml below:
kind: Service
apiVersion: v1
metadata:
name: fromk8dashboard
namespace: default
selfLink: /api/v1/namespaces/default/services/fromk8dashboard
uid: 406e99ce-dec1-4e80-91aa-84f75c2d9892
resourceVersion: '70115'
creationTimestamp: '2020-05-12T12:13:05Z'
labels:
k8s-app: fromk8dashboard
managedFields:
- manager: dashboard
operation: Update
apiVersion: v1
time: '2020-05-12T12:13:41Z'
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:labels':
.: {}
'f:k8s-app': {}
'f:spec':
'f:externalTrafficPolicy': {}
'f:ports':
.: {}
'k:{"port":31000,"protocol":"TCP"}':
.: {}
'f:name': {}
'f:port': {}
'f:protocol': {}
'f:targetPort': {}
'f:selector':
.: {}
'f:k8s-app': {}
'f:sessionAffinity': {}
'f:type': {}
spec:
ports:
- name: tcp-31000-80-6bw28
protocol: TCP
port: 31000
targetPort: 80
nodePort: 32058
selector:
k8s-app: fromk8dashboard
clusterIP: 10.100.68.204
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
status:
loadBalancer: {}
Use below yaml and you should be to access it via http://172.26.75.182:30007/
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
k8s-app: fromk8dashboard
ports:
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
- port: 80
targetPort: 80
# Optional field
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
nodePort: 30007
Check the guide for exposing pod via nodeport service.