kubernetes / kubernetes/kubectl

kubectl diff fails to detect differences in Service objects

Open
#1,601 15 comments 4 reactions 1 assignee Claimed by @mabulgu View on GitHub
kind/bug needs-kind priority/backlog triage/accepted
Dominant language
Go
Stars
3.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

**What happened**:
`kubectl diff` is not detecting diffs between a service's manifest file and the modified service object in Kubernetes. I tried both client-side or server-side mode without success.

**What you expected to happen**:
`kubectl diff` identifies the diff

**How to reproduce**:

1. Create a K8s service using a manifest `kubectl create -f my-svc.yaml`. Where `my-svc.yaml` is:
```yaml
apiVersion: v1
kind: Service
metadata:
name: example
namespace: default
spec:
ports:
- name: service-port
port: 80
protocol: TCP
targetPort: service-port
selector:
app.kubernetes.io/instance: example
type: ClusterIP
```
1. Using `kubectl edit`, modify the K8s service. i.e. Add an extra port.
```yaml
apiVersion: v1
kind: Service
metadata:
name: example
namespace: default
spec:
ports:
- name: service-port
port: 80
protocol: TCP
targetPort: service-port
- name: shouldntbehere # <<<< THIS
port: 8080
protocol: TCP
targetPort: service-port
selector:
app.kubernetes.io/instance: example
type: ClusterIP
```
4. Run:
```sh
kubectl diff -f my-svc.yaml
# or
kubectl diff -f my-svc.yaml --server-side --force-conflicts
```
5. No diff shows up.

**Anything else we need to know?**:

**Environment**:
- Kubernetes client and server versions (use `kubectl version`): 1.27 on both server/client. Also tried 1.30 with same results.
- Cloud provider or hardware configuration: AWS EKS
- OS (e.g: `cat /etc/os-release`): Ubuntu 22.04.4 LTS

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.