基于deployment.yml将微服务生态部署至IBM Cloud Kubernetes
Got it, let's walk through getting your microservices ecosystem deployed to IBM Cloud step by step. Since you already have your Dockerized services and Kubernetes manifests (deployment.yml + service.yml), most of the heavy lifting is already done—we just need to adapt them for IBM Cloud's Kubernetes Service (IKS) and handle a few cloud-specific steps.
1. 前期准备工作
- First, make sure you have all the necessary tools installed:
ibmcloudCLI: For interacting with IBM Cloudkubectl: You’re already using this—just double-check its version is compatible with your IKS cluster (runibmcloud ks versionsto see supported versions)- Docker: To build and push images to IBM Cloud’s container registry
- Log in to your IBM Cloud account:
If you’re using an enterprise account, add theibmcloud login--ssoflag:ibmcloud login --sso
2. Create/Select an IBM Cloud Kubernetes Service (IKS) Cluster
- If you don’t have a cluster yet, spin one up (this takes ~10-15 minutes):
Swapibmcloud ks cluster create classic --name your-cluster-name --zone your-preferred-zone --machine-type b3c.4x16classicforvpc-gen2if you want a VPC-based cluster, and adjust the machine type based on your service resource needs. - Once the cluster is ready, configure
kubectlto connect to it:
Verify the connection works:ibmcloud ks cluster config --cluster your-cluster-name
You should see a list of your cluster’s nodes if everything’s set up correctly.kubectl get nodes
3. Push Docker Images to IBM Cloud Container Registry (ICR)
Your local Docker images need to live in IBM Cloud’s registry so IKS can pull them:
- Create a namespace to organize your images:
ibmcloud cr namespace-add your-namespace-name - Log in to the container registry:
ibmcloud cr login - Tag your local image with the ICR format:
REGISTRY_URL/NAMESPACE/IMAGE_NAME:TAG(get your registry URL viaibmcloud cr info, e.g.,us.icr.io):docker tag your-local-image:v1 us.icr.io/your-namespace/your-service-image:v1 - Push the image to ICR:
docker push us.icr.io/your-namespace/your-service-image:v1 - Confirm the image was uploaded successfully:
ibmcloud cr image-list
4. Adjust Your Kubernetes Manifests
You’ll need to update your deployment.yml to pull images from ICR instead of your local Docker:
- Find the
spec.template.spec.containers[0].imagefield and replace your local image name with the full ICR image path you just pushed, like:image: us.icr.io/your-namespace/your-service-image:v1 - Optional: If your services need persistent storage, secrets, or config maps, IBM Cloud offers managed services like Object Storage and Secrets Manager—you can define corresponding Kubernetes resources (e.g.,
PersistentVolumeClaim,Secret) to integrate these.
5. Deploy Your Microservices to IKS
This part is almost identical to your Minikube workflow:
- Deploy your Deployment first:
kubectl create -f deployment.yml - Then deploy your Service:
kubectl create -f service.yml - Verify everything’s running:
# Check pod status kubectl get pods # Check service status kubectl get services
6. Expose Services to the Public Internet (If Needed)
IBM Cloud offers two main ways to make your services externally accessible:
Option 1: Use a LoadBalancer Service
If your service.yml already defines a LoadBalancer type, IKS will automatically provision a public IP. Run kubectl get services and look for the EXTERNAL-IP field—use that IP to access your service.
Option 2: Use IBM Cloud Ingress (For Complex Routing)
If you need to route multiple services under a single domain, set up an Ingress:
- Enable the Ingress add-on for your cluster:
ibmcloud ks cluster addon enable ingress --cluster your-cluster-name - Create an
ingress.ymlfile (example below):apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: your-microservices-ingress annotations: kubernetes.io/ingress.class: "public-iks-k8s-nginx" spec: rules: - host: your-custom-domain.com # Or use IBM's default provided domain http: paths: - path: /auth-service pathType: Prefix backend: service: name: auth-service port: number: 8080 - path: /payment-service pathType: Prefix backend: service: name: payment-service port: number: 8080 - Deploy the Ingress:
kubectl create -f ingress.yml - Get the public IP for your Ingress:
kubectl get ingress
7. Monitor & Maintain Your Deployment
- Use built-in IBM Cloud tools like Monitoring and Logs to keep an eye on your services, or use basic
kubectlcommands for quick checks:# View pod logs kubectl logs your-pod-name # Check cluster events for issues kubectl get events - To update a service later, just push a new image to ICR and roll out the update:
kubectl set image deployment/your-deployment-name your-container-name=us.icr.io/your-namespace/your-service-image:v2
内容的提问来源于stack exchange,提问作者branko terzic

