k8s: service unchanged but not listed

9/27/2018

I am trying to create a service on kubernetes but although no error is printed, I am unable to list the service;

working locally with 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

Here is the manifest used:

---

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
-- pkaramol
kubectl
kubernetes
minikube

1 Answer

9/27/2018

The Service is created on esa-local-dev namespace. In your yaml, you have:

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

You can see the service by running,

$ kubectl get services -n esa-local-dev
-- Abdullah Al Maruf - Tuhin
Source: StackOverflow