<p dir="auto">The <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockertools/docker_manager_test.go">docker_manager_test</a> needs some refactoring. A few of the problems:</p>
<ul dir="auto">
<li>Rampant code duplication (the test is over 2500 lines long)</li>
<li>Fragile tests depending on lots of internal functionality</li>
</ul>
<p dir="auto">Cleanup up the test properly may require exposing a few more interfaces from the DockerManager, or just providing better fakes.</p>
<p dir="auto"><strong>What keywords did you search in Kubernetes issues before filing this one?</strong> (If you have found any duplicates, you should instead reply there.):<br>
service</p>
<hr>
<p dir="auto"><strong>Is this a BUG REPORT or FEATURE REQUEST?</strong> (choose one):<br>
BUG REPORT</p>
<p dir="auto"><strong>Kubernetes version</strong> (use <code class="notranslate">kubectl version</code>):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;3&quot;, GitVersion:&quot;v1.3.4&quot;, GitCommit:&quot;dd6b458ef8dbf24aff55795baa68f83383c9b3a9&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2016-08-01T16:45:16Z&quot;, GoVersion:&quot;go1.6.2&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;3&quot;, GitVersion:&quot;v1.3.5&quot;, GitCommit:&quot;b0deb2eb8f4037421077f77cb163dbb4c0a2a9f5&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2016-08-11T20:21:58Z&quot;, GoVersion:&quot;go1.6.2&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}"><pre class="notranslate"><code class="notranslate">Client Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.4", GitCommit:"dd6b458ef8dbf24aff55795baa68f83383c9b3a9", GitTreeState:"clean", BuildDate:"2016-08-01T16:45:16Z", GoVersion:"go1.6.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.5", GitCommit:"b0deb2eb8f4037421077f77cb163dbb4c0a2a9f5", GitTreeState:"clean", BuildDate:"2016-08-11T20:21:58Z", GoVersion:"go1.6.2", Compiler:"gc", Platform:"linux/amd64"}
</code></pre></div>
<p dir="auto"><strong>Environment</strong>:</p>
<ul dir="auto">
<li><strong>Cloud provider or hardware configuration</strong>: GCE container cluster</li>
</ul>
<p dir="auto"><strong>What happened</strong>:<br>
Tried to create a service, but the service disappeared after a minute or two. Watch doesn't tell any  info about the removal. Tried both ClusterIP and NodePort, the same result. Appreciate if someone can explain the cause.</p>
<p dir="auto">Create the service:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ kubectl create -f grafana-service.yaml
You have exposed your service on an external port on all nodes in your
cluster.  If you want to expose this service to the external internet, you may
need to set up firewall rules for the service port(s) (tcp:30603) to serve traffic.

See http://releases.k8s.io/release-1.3/docs/user-guide/services-firewalls.md for more details.
service &quot;monitoring-grafana&quot; created"><pre class="notranslate"><code class="notranslate">$ kubectl create -f grafana-service.yaml
You have exposed your service on an external port on all nodes in your
cluster.  If you want to expose this service to the external internet, you may
need to set up firewall rules for the service port(s) (tcp:30603) to serve traffic.

See http://releases.k8s.io/release-1.3/docs/user-guide/services-firewalls.md for more details.
service "monitoring-grafana" created
</code></pre></div>
<p dir="auto">The service was created:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ kubectl get services --namespace kube-system
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
default-http-backend   10.3.247.212   &lt;nodes&gt;       80/TCP              2d
heapster               10.3.247.1     &lt;none&gt;        80/TCP              1d
kube-dns               10.3.240.10    &lt;none&gt;        53/UDP,53/TCP       2d
kubernetes-dashboard   10.3.246.164   &lt;none&gt;        80/TCP              2d
monitoring-grafana     10.3.243.215   &lt;nodes&gt;       80/TCP              40s
monitoring-influxdb    10.3.250.25    &lt;none&gt;        8083/TCP,8086/TCP   19m"><pre class="notranslate"><code class="notranslate">$ kubectl get services --namespace kube-system
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
default-http-backend   10.3.247.212   &lt;nodes&gt;       80/TCP              2d
heapster               10.3.247.1     &lt;none&gt;        80/TCP              1d
kube-dns               10.3.240.10    &lt;none&gt;        53/UDP,53/TCP       2d
kubernetes-dashboard   10.3.246.164   &lt;none&gt;        80/TCP              2d
monitoring-grafana     10.3.243.215   &lt;nodes&gt;       80/TCP              40s
monitoring-influxdb    10.3.250.25    &lt;none&gt;        8083/TCP,8086/TCP   19m
</code></pre></div>
<p dir="auto">But it disappeared later on:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ kubectl get services --namespace kube-system
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
default-http-backend   10.3.247.212   &lt;nodes&gt;       80/TCP              2d
heapster               10.3.247.1     &lt;none&gt;        80/TCP              1d
kube-dns               10.3.240.10    &lt;none&gt;        53/UDP,53/TCP       2d
kubernetes-dashboard   10.3.246.164   &lt;none&gt;        80/TCP              2d
monitoring-influxdb    10.3.250.25    &lt;none&gt;        8083/TCP,8086/TCP   20m"><pre class="notranslate"><code class="notranslate">$ kubectl get services --namespace kube-system
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
default-http-backend   10.3.247.212   &lt;nodes&gt;       80/TCP              2d
heapster               10.3.247.1     &lt;none&gt;        80/TCP              1d
kube-dns               10.3.240.10    &lt;none&gt;        53/UDP,53/TCP       2d
kubernetes-dashboard   10.3.246.164   &lt;none&gt;        80/TCP              2d
monitoring-influxdb    10.3.250.25    &lt;none&gt;        8083/TCP,8086/TCP   20m
</code></pre></div>
<p dir="auto">Below is what I got from watch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2016-08-24T23:09:51Z
  labels:
    kubernetes.io/cluster-service: &quot;true&quot;
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
  resourceVersion: &quot;57700&quot;
  selfLink: /api/v1/namespaces/kube-system/services/monitoring-grafana
  uid: dc8a45c5-6a4f-11e6-a055-42010a8a0fc8
spec:
  clusterIP: 10.3.243.215
  ports:
  - nodePort: 30603
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    name: influxGrafana
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2016-08-24T23:09:51Z
  labels:
    kubernetes.io/cluster-service: &quot;true&quot;
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
  resourceVersion: &quot;57709&quot;
  selfLink: /api/v1/namespaces/kube-system/services/monitoring-grafana
  uid: dc8a45c5-6a4f-11e6-a055-42010a8a0fc8
spec:
  clusterIP: 10.3.243.215
  ports:
  - nodePort: 30603
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    name: influxGrafana
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}"><pre class="notranslate"><code class="notranslate">apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2016-08-24T23:09:51Z
  labels:
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
  resourceVersion: "57700"
  selfLink: /api/v1/namespaces/kube-system/services/monitoring-grafana
  uid: dc8a45c5-6a4f-11e6-a055-42010a8a0fc8
spec:
  clusterIP: 10.3.243.215
  ports:
  - nodePort: 30603
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    name: influxGrafana
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2016-08-24T23:09:51Z
  labels:
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
  resourceVersion: "57709"
  selfLink: /api/v1/namespaces/kube-system/services/monitoring-grafana
  uid: dc8a45c5-6a4f-11e6-a055-42010a8a0fc8
spec:
  clusterIP: 10.3.243.215
  ports:
  - nodePort: 30603
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    name: influxGrafana
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}
</code></pre></div>