Detailed service analysis including endpoints, connectivity, and configuration
Provides comprehensive Kubernetes service analysis including configuration, endpoints, connectivity testing, and troubleshooting diagnostics.
/plugin marketplace add kcns008/cluster-code/plugin install kcns008-cluster-core-plugins-cluster-core@kcns008/cluster-codesonnetI'll provide comprehensive analysis of your Kubernetes service including configuration, endpoints, and connectivity testing.
# Basic service information
kubectl get service {{service}} -n {{namespace}} -o wide
# Service specification details
kubectl get service {{service}} -n {{namespace}} -o yaml
# Service selector and matching pods
kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.selector}'
# Pods matching the service selector
selector=$(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.selector | keys[0]}')=$(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.selector | values[0]}')
kubectl get pods -n {{namespace}} -l $selector -o wide
# Service endpoints
kubectl get endpoints {{service}} -n {{namespace}} -o wide
# Endpoint details with pod information
kubectl get endpoints {{service}} -n {{namespace}} -o yaml
# Check if endpoints are ready
kubectl get endpoints {{service}} -n {{namespace}} -o jsonpath='{range .subsets[*]}{range .addresses[*]}{.ip}{":"}{.ports[0].port}{" ready\n"}{end}{end}'
# Check for unready endpoints
kubectl get endpoints {{service}} -n {{namespace}} -o jsonpath='{range .subsets[*]}{range .notReadyAddresses[*]}{.ip}{":"}{.ports[0].port}{" not ready\n"}{end}{end}'
# Service type analysis
kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.type}{"\n"}'
# ClusterIP service details
if [ "$(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.type}')" = "ClusterIP" ]; then
echo "ClusterIP: $(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.clusterIP}')"
echo "Ports: $(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{range .spec.ports[*]}{.port}{"/"}{.targetPort}{", "}{end}')"
fi
# NodePort service details
if [ "$(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.type}')" = "NodePort" ]; then
echo "NodePort: $(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{range .spec.ports[*]}{.nodePort}{"\n"}{end}')"
fi
# LoadBalancer service details
if [ "$(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.spec.type}')" = "LoadBalancer" ]; then
echo "External IP: $(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
echo "Hostname: $(kubectl get service {{service}} -n {{namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
fi
{{#if test}}
# Create a test pod for connectivity testing
kubectl run service-test --image=nicolaka/netshoot --rm -it --restart=Never -- bash -c "
echo 'Testing DNS resolution for {{service}}.{{namespace}}.svc.cluster.local'
nslookup {{service}}.{{namespace}}.svc.cluster.local
echo 'Testing service connectivity'
# Test each port
kubectl get service {{service}} -n {{namespace}} -o jsonpath='{range .spec.ports[*]}{.port}{\" \"}{end}' | while read port; do
echo \"Testing port \$port...\"
timeout 5 nc -zv {{service}}.{{namespace}}.svc.cluster.local \$port 2>&1 || echo \"Connection failed on port \$port\"
done
"
# Set up port forwarding for local testing
echo "Setting up port forwarding for {{service}}..."
kubectl port-forward service/{{service}} 8080:80 -n {{namespace}} &
# Test local connection
sleep 2
curl -s http://localhost:8080/healthz 2>/dev/null && echo "✅ Service accessible via port-forward" || echo "❌ Service not accessible via port-forward"
# Clean up
kill %1 2>/dev/null
{{/if}}
# Test DNS resolution
kubectl run dns-test --image=busybox --rm -it --restart=Never -- nslookup {{service}}.{{namespace}}.svc.cluster.local
# Test service discovery from pods
kubectl run dns-test --image=busybox --rm -it --restart=Never -- wget -qO- {{service}}.{{namespace}}.svc.cluster.local:80/healthz 2>/dev/null || echo "Service not reachable"
# Ingress resources pointing to this service
kubectl get ingress -n {{namespace}} -o jsonpath='{range .items[*]}{range .spec.rules[*]}{range .http.paths[*]}{.backend.service.name}{"\n"}{end}{end}{end}' | grep {{service}}
# Endpointslice information
kubectl get endpointslices -n {{namespace}} -l kubernetes.io/service-name={{service}}
# Network policies affecting this service
kubectl get networkpolicies -n {{namespace}} -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | while read policy; do
echo "Checking policy $policy for service {{service}}..."
kubectl get networkpolicy $policy -n {{namespace}} -o yaml | grep -q {{service}} && echo "Policy $policy affects service {{service}}"
done
I'll analyze:
kubectl get service {{service}} -n {{namespace}}kubectl get endpoints {{service}} -n {{namespace}}Based on the analysis, I can suggest:
Would you like me to proceed with the detailed service analysis and connectivity testing?