将已创建的Pod部署为Service时遭遇deployments.apps "wordpress" NotFound错误求助
Let's break down why you're hitting this error and how to fix it step by step:
First, the error is telling you that Kubernetes can't find a Deployment named wordpress in your cluster. This almost always happens because either:
- You're trying to expose a Deployment that no longer exists (even if its old Pods are still running), or
- You accidentally used a command that targets a Deployment instead of your existing standalone Pod.
Step 1: Verify Your Cluster Resources
First, let's confirm what's actually running in your cluster:
- Check for existing Deployments:
Ifkubectl get deploymentswordpressdoesn't show up here, that's the root cause—your command is looking for a Deployment that's gone. - Check your existing WordPress Pod(s) and their labels:
Look at thekubectl get pods -o wideLABELScolumn for your WordPress Pod—this will tell you what tags we can use to link a Service to it.
Step 2: Fix the Issue Based on Your Setup
Scenario 1: You don't need a Deployment (just want to expose your existing Pod)
If your WordPress Pod was created directly (not via a Deployment), you need to expose the Pod itself instead of a Deployment.
Option 1: Use the expose command directly on the Pod:
# Replace <your-pod-name> with the actual name of your WordPress Pod from the previous step kubectl expose pod <your-pod-name> --port=80 --type=ClusterIP
Option 2: Create a Service YAML file (more flexible):
Create a file named wordpress-service.yaml with this content, making sure the selector matches the labels from your Pod:
apiVersion: v1 kind: Service metadata: name: wordpress-service spec: selector: # Replace this with your Pod's actual label (e.g., app=wordpress) app: wordpress ports: - protocol: TCP port: 80 targetPort: 80 type: ClusterIP
Then apply it with:
kubectl apply -f wordpress-service.yaml
Scenario 2: You want to use a Deployment (recommended for reliability)
Deployments are better for managing Pods—they handle self-healing, scaling, and updates. If your original Deployment was deleted, recreate it first:
- Use your original Deployment YAML file (if you have it):
kubectl apply -f your-wordpress-deployment.yaml - Wait for the Deployment to spin up new Pods (check with
kubectl get podsuntil they showRunning). - Now you can expose the Deployment safely:
kubectl expose deployment wordpress --port=80 --type=ClusterIP
Scenario 3: You made a typo
Double-check the name of your Deployment—Kubernetes resource names are case-sensitive. If your Deployment was named WordPress (with a capital W) instead of wordpress, fix the command to match the correct name.
内容的提问来源于stack exchange,提问作者Dev Rao

