-
Notifications
You must be signed in to change notification settings - Fork 923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selector does not work for service. #535
Comments
/kind bug |
I can reproduce it. It's wired. When I add a new label to the service, I can select the service using this label:
but
I'll look, if I can find the cause and if it. |
I think, it's not a bug. I just realised that the steps to reproduce do not have a step where we mark a service with a label. I didn't manage to find evidence that it's expected from A bit more details below. @J-Siu I hope it will explain why you are experiencing this. When you run:
It creates a service and a pod (and a deployment, but it's not important for this issue). Important thing is - It does not assign new labels to the service implicitly. The selector you see in the output of Try run apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2018-10-06T10:07:07Z
name: ghost
namespace: default
resourceVersion: "110979"
selfLink: /api/v1/namespaces/default/services/ghost
uid: 94d84ee9-c94f-11e8-9ae1-0800274eddd9
spec:
clusterIP: 10.106.181.96
ports:
- port: 2368
protocol: TCP
targetPort: 2368
selector:
run: ghost
# ^^^^^^^^^^^^
# This is what `kubectl get svc -o wide` prints. Resource itself doesn't have any labels
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {} (see the comment in the yaml file) In order to be able to select the service by a label, you need to add a new label to it explicitly. Like It works with the kubectl get svc -n kube-system kube-dns -oyaml
apiVersion: v1
kind: Service
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","k8s-app":"kube-dns","kubernetes.io/name":"KubeDNS"},"name":"kube-dns","namespace":"kube-system"},"spec":{"clusterIP":"10.96.0.10","ports":[{"name":"dns","port":53,"protocol":"UDP"},{"name":"dns-tcp","port":53,"protocol":"TCP"}],"selector":{"k8s-app":"kube-dns"}}}
creationTimestamp: 2018-08-12T19:54:21Z
labels:
addonmanager.kubernetes.io/mode: Reconcile
k8s-app: kube-dns
kubernetes.io/name: KubeDNS
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# This is what `kubectl` uses to find resources
name: kube-dns
namespace: kube-system
resourceVersion: "16567"
selfLink: /api/v1/namespaces/kube-system/services/kube-dns
uid: 815573bc-9e69-11e8-a6b0-0800274eddd9
spec:
clusterIP: 10.96.0.10
ports:
- name: dns
port: 53
protocol: UDP
targetPort: 53
- name: dns-tcp
port: 53
protocol: TCP
targetPort: 53
selector:
k8s-app: kube-dns
# ^^^^^^^^^^^^^^^^^^^^
# This is what services uses to discover related pods
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {} (also see the comments in the yaml file) So
|
Arrrrr. I understand what you saying after I went through it a few times. As I am new to kubernetes and confusing between labels/selectors and also the -l option. But after some search and try with --show-labels, it becomes clear: $ kubectl get svc -o wide --all-namespaces --show-labels
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR LABELS
default ghost ClusterIP 10.97.101.35 <none> 2368/TCP 13d run=ghost <none>
default hn LoadBalancer 10.96.66.191 <pending> 8080:30673/TCP 12d run=hn run=hn
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 14d <none> component=apiserver,provider=kubernetes
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 14d k8s-app=kube-dns k8s-app=kube-dns,kubernetes.io/cluster-service=true,kubernetes.io/name=KubeDNS
kube-system tiller-deploy ClusterIP 10.104.224.90 <none> 44134/TCP 13d app=helm,name=tiller app=helm,name=tiller Thank you!! |
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.):
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.):
Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT
Kubernetes version (use
kubectl version
):Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.3", GitCommit:"a4529464e4629c21224b3d52edfe0ea91b072862", GitTreeState:"clean", BuildDate:"2018-09-09T18:02:47Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.3", GitCommit:"a4529464e4629c21224b3d52edfe0ea91b072862", GitTreeState:"clean", BuildDate:"2018-09-09T17:53:03Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Environment:
uname -a
): Linux u64s01 4.15.0-34-generic Current bash-completion instructions do not work on Mac OS 10.11.6 and bash 3.2 #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/LinuxWhat happened:
Selector does not work for service.
What you expected to happen:
Selector should work for service.
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know:
It work if I select k8s-app
The text was updated successfully, but these errors were encountered: