I am trying to deploy nginx on kubernetes, kubernetes version is v1.5.2, I have deployed nginx with 3 replica, YAML file is below,
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: deployment-example
spec:
replicas: 3
revisionHistoryLimit: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: 80
and now I want to expose its port 80 on port 30062 of node, for that I created a service below,
kind: Service
apiVersion: v1
metadata:
name: nginx-ils-service
spec:
ports:
- name: http
port: 80
nodePort: 30062
selector:
app: nginx
type: LoadBalancer
this service is working good as it should be, but it is showing as pending not only on kubernetes dashboard also on terminal.
so please help me to resolve this issue. Thanks ...
Use NodePort:
kubectl run user-login --replicas=2 --labels="run=user-login" --image=kingslayerr/teamproject:version2 --port=5000
kubectl expose deployment user-login --type=NodePort --name=user-login-service
kubectl describe services user-login-service (Note down the port)
kubect cluster-info (IP-> Get The IP where master is running)
Your service is accessible at (IP):(port)
If you are not using GCE or EKS (you used
kubeadm
) you can add anexternalIPs
spec to your service YAML. You can use the IP associated with your node's primary interface such aseth0
. You can then access the service externally, using the external IP of the node.I created a single node k8s cluster using kubeadm. When i tried PortForward and kubectl proxy, it showed external IP as pending.
In my case I've patched the service like this:
After this, it started serving over the public IP
delete existing service and create a same new service solved my problems. My problems is that the loading balancing Ip I defines is used so that external endpoint is pending. When I changed a new load balancing IP it still coundn't work. Finally, delete existing service and create a new one solved my problem.
If you are using Minikube, there is a magic command!
Hopefully someone can save a few minutes with this.
Reference link https://github.com/kubernetes/minikube/blob/master/docs/networking.md#loadbalancer-emulation-minikube-tunnel
To access a service on
minikube
, you need to run the following command:More information here : Minikube GitHub