k8s:服务未更改但未列出

时间:2018-09-27 13:28:43

标签: kubernetes kubectl minikube

我正在尝试在kubernetes上创建服务,但是尽管未显示任何错误,但我无法列出该服务;

minikube

在本地合作
*$ kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   4h
/home/pkara/Workspace/gitlab/my-minikube
*$ kubectl apply -f mydb.yaml 
service/mydatabase unchanged
/home/pkara/Workspace/gitlab/my-minikube
*$ kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   4h

这是使用的清单:

---

apiVersion: v1
kind: Service
metadata:
  name: mydatabase
  namespace: esa-local-dev
  labels:
    app: mydatabase
spec:
  ports:
  - name: mydatabase-port
    port: 3306
    targetPort: 3306
  selector:
    app: mydatabase
  clusterIP: None

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mydatabase-deployment
  labels:
    app: mydatabase
spec:
  selector:
    matchLabels:
      app: mydatabase
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mydatabase
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        - name: MYSQL_DATABASE
          value: "mydatabase"
        - name: MYSQL_USER
          value: "mydatabase"
        - name: MYSQL_PASSWORD
          value: "mydatabase"
        ports:
        - containerPort: 3306
          name: mysql
      restartPolicy: Always

1 个答案:

答案 0 :(得分:3)

该服务是在esa-local-dev名称空间上创建的。在您的Yaml中,您拥有:

apiVersion: v1
kind: Service
metadata:
  name: mydatabase
  namespace: esa-local-dev
...

您可以通过运行查看服务,

$ kubectl get services -n esa-local-dev