I try to learn kubernetes on minikube. I deploy 3 replicas of Nginx via this below yaml.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginxdeployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
ports:
- containerPort: 80
Then I try to expose deployments via this yaml.
apiVersion: v1
kind: Service
metadata:
name: nginxservice
spec:
ports:
- port: 8080
targetPort: 80
type: LoadBalancer
selector:
app: nginx
Everything is perfect.
PS D:\kubernates work> kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginxdeployment-7848d4b86f-7rdzv 1/1 Running 0 111m
pod/nginxdeployment-7848d4b86f-8d7n5 1/1 Running 1 111m
pod/nginxdeployment-7848d4b86f-wmvtw 1/1 Running 0 111m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h51m
service/nginxservice LoadBalancer 10.110.215.102 <pending> 8080:30903/TCP 70m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginxdeployment 3/3 3 3 111m
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginxdeployment-7848d4b86f 3 3 3 111m
But I try to access service via name from the pod. I am getting this error : Host name could not resolved. I can access over the ip address.
PS D:\kubernates work> kubectl exec -it nginxdeployment-7848d4b86f-7rdzv -- /bin/sh
# curl http://10.110.215.102:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
over servicename :
PS D:\kubernates work> kubectl exec -it nginxdeployment-7848d4b86f-7rdzv -- /bin/sh
# curl http://nginxservice:8080
**curl: (6) Could not resolve host: nginxservice**
dns informations :
PS D:\kubernates work> kubectl exec -it nginxdeployment-7848d4b86f-7rdzv -- /bin/sh
# cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
#
enviroment informations:
PS D:\kubernates work> kubectl exec -it nginxdeployment-7848d4b86f-7rdzv -- /bin/sh
# env
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.96.0.1:443
HOSTNAME=nginxdeployment-7848d4b86f-7rdzv
NGINXSERVICE_SERVICE_HOST=10.111.162.61
NGINXSERVICE_PORT_8080_TCP_ADDR=10.111.162.61
HOME=/root
NGINXSERVICE_PORT_8080_TCP_PORT=8080
NGINXSERVICE_PORT_8080_TCP_PROTO=tcp
PKG_RELEASE=1~buster
NGINXSERVICE_SERVICE_PORT=8080
NGINXSERVICE_PORT=tcp://10.111.162.61:8080
NGINXSERVICE_PORT_8080_TCP=tcp://10.111.162.61:8080
TERM=xterm
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
NGINX_VERSION=1.19.5
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
NJS_VERSION=0.4.4
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_SERVICE_HOST=10.96.0.1
PWD=/
what is the problem ? I am new in kubernetes. Thanks for advice.
for comment @ThanhNguyenVan :
kubectl get pods --all-namespaces
default nginxdeployment-7848d4b86f-7rdzv 1/1 Running 0 170m
default nginxdeployment-7848d4b86f-8d7n5 1/1 Running 1 170m
default nginxdeployment-7848d4b86f-wmvtw 1/1 Running 0 170m
kube-system coredns-f9fd979d6-tqtdh 1/1 Running 2 5h51m
kube-system etcd-minikube 1/1 Running 2 5h50m
kube-system kindnet-ndzcp 1/1 Running 0 5h8m
kube-system kindnet-p4hw2 1/1 Running 1 5h8m
kube-system kube-apiserver-minikube 1/1 Running 2 5h50m
kube-system kube-controller-manager-minikube 1/1 Running 0 155m
kube-system kube-proxy-dn9tw 1/1 Running 0 5h8m
kube-system kube-proxy-l48px 1/1 Running 2 5h51m
kube-system kube-scheduler-minikube 1/1 Running 2 5h50m
kube-system storage-provisioner 1/1 Running 4 5h51m