简体   繁体   English

Kubernetes网络问题

[英]Kubernetes networking issue

I have installed a Kubernetes cluster on VirtualBox (centos7) using a tutorial from here . 我已经使用此处的教程在VirtualBox(centos7)上安装了Kubernetes集群。

Here is my setup: 这是我的设置:

  • kube-master - 10.1.10.152 (etcd, kube-apiserver, kube-controller-manager, kube-scheduler) kube-master-10.1.10.152(etcd,kube-apiserver,kube-controller-manager,kube-scheduler)
  • kube-minion1 - 10.1.10.153 (kube-proxy, kubelet, docker, flanneld) kube-minion1-10.1.10.153(kube-proxy,kubelet,docker,flanneld)

When i finished the setup everything looked good: 当我完成设置后,一切看起来都很好:

$ kubectl get nodes
NAME           LABELS                                STATUS
kube-minion1   kubernetes.io/hostname=kube-minion1   Ready

I tried to add mysql pod and service using the following config: 我试图使用以下配置添加mysql pod和服务:

$ cat mysql.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
      containers:
    - resources:
        limits :
          cpu: 1
      image: mysql
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: qwe123
      ports:
        - containerPort: 3306
          name: mysql

$ cat mysql-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: mysql
spec:
  publicIPs:
    - 10.1.10.153
  ports:
    # the port that this service should serve on
    - port: 3306
  # label keys and values that must match in order to receive traffic for this service
  selector:
    name: mysql

Notice that i do provide the publicIPs = 10.1.10.153. 请注意,我确实提供了publicIPs = 10.1.10.153。 Once both mysql.yaml and mysql-service.yaml were injected, here is what i get: 一旦注入了mysql.yaml和mysql-service.yaml,这就是我得到的:

$ kubectl get pods
NAME           READY     STATUS    RESTARTS   AGE
mysql          1/1       Running   0          31s

$ kubectl get services
NAME         LABELS                                    SELECTOR     IP(S)            PORT(S)
kubernetes   component=apiserver,provider=kubernetes   <none>       10.254.0.1       443/TCP
mysql        name=mysql                                name=mysql   10.254.215.138   3306/TCP


$ kubectl describe service mysql
Name:           mysql
Namespace:      default
Labels:         name=mysql
Selector:       name=mysql
Type:           ClusterIP
IP:             10.254.215.138
Port:           <unnamed>   3306/TCP
Endpoints:      172.17.17.5:3306
Session Affinity:   None
No events.

So the problem i am having is that mysql is not accessible using 10.1.10.153. 所以我遇到的问题是使用10.1.10.153无法访问mysql。 The only way to communicate with mysql that i was able to do is accessing from the minion host using 10.254.215.138 我能够与mysql通信的唯一方法是使用10.254.215.138从奴才主机进行访问

Why am i unable to access it using 10.1.10.153? 为什么我无法使用10.1.10.153访问它? Is there a way to make it work? 有办法使它起作用吗?

Thank you -D 谢谢-D

In your case simplest way will be specify service type "NodePort". 在您的情况下,最简单的方法是指定服务类型“ NodePort”。 In that case kubernetes will open port for the service on each node so it will be accessible via 10.1.10.153:3306. 在这种情况下,kubernetes将在每个节点上打开该服务的端口,以便可以通过10.1.10.153:3306对其进行访问。 What about your case - if service type is ClusterIP then service is accessible only from inside the cluster (from the pods) independently from it's publicIp if specified. 您的情况如何-如果服务类型为ClusterIP,则只能从群集内部(从pod)访问服务,而与指定的publicIp无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM