skills/kubeblocks-expose-service/SKILL.md
Expose KubeBlocks database clusters externally via LoadBalancer or NodePort services using the Expose OpsRequest. Includes cloud-specific annotations for AWS NLB, Azure LB, GCP, and Alibaba Cloud. Use when the user wants to access the database from outside the Kubernetes cluster, expose a service externally, set up external connectivity, or create a public endpoint. NOT for configuring internal ClusterIP services (default behavior) or setting up TLS for connections (see configure-tls).
npx skillsauth add apecloud/kubeblocks-skills kubeblocks-expose-serviceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
By default, KubeBlocks database clusters are only accessible within the Kubernetes cluster. Use the Expose OpsRequest to create external-facing services via LoadBalancer or NodePort, allowing access from outside the cluster.
Official docs: https://kubeblocks.io/docs/preview/user_docs/connect-databases/expose-database-service
Before proceeding, verify the cluster is healthy and no other operation is running:
# Cluster must be Running
kubectl get cluster <cluster-name> -n <namespace> -o jsonpath='{.status.phase}'
# No pending OpsRequests
kubectl get opsrequest -n <namespace> -l app.kubernetes.io/instance=<cluster-name> --field-selector=status.phase!=Succeed
If the cluster is not Running or has a pending OpsRequest, wait for it to complete before proceeding.
Check current services for the cluster:
kubectl get svc -n <namespace> -l app.kubernetes.io/instance=<cluster-name>
- [ ] Step 1: Choose exposure method
- [ ] Step 2: Create Expose OpsRequest
- [ ] Step 3: Verify external service
- [ ] Step 4: Connect from outside
| Method | Use Case | Requirements | |--------|----------|-------------| | LoadBalancer | Cloud environments (AWS, Azure, GCP, Alibaba) | Cloud LB controller | | NodePort | On-premises or local clusters | None |
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: <cluster>-expose
namespace: <ns>
spec:
clusterName: <cluster>
type: Expose
expose:
- componentName: <component>
switch: Enable
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
switch: Enable to create the service, Disable to remove itroleSelector: primary exposes only the primary node (recommended for writes)serviceType: LoadBalancer or NodePortAdd annotations for cloud-specific load balancer configuration:
AWS (Network Load Balancer):
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-internal: "false"
Azure:
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "false"
GCP:
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
annotations:
networking.gke.io/load-balancer-type: External
Alibaba Cloud:
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
services:
- name: <cluster>-<component>-nodeport
roleSelector: primary
serviceType: NodePort
Before applying, validate with dry-run:
kubectl apply -f expose-ops.yaml --dry-run=server
If dry-run reports errors, fix the YAML before proceeding.
Apply it:
kubectl apply -f expose-ops.yaml
kubectl get ops <cluster>-expose -n <ns> -w
Success condition:
.status.phase=Succeed| Typical: 1-2min | If stuck >5min:kubectl describe ops <cluster>-expose -n <ns>
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: <cluster>-unexpose
namespace: <ns>
spec:
clusterName: <cluster>
type: Expose
expose:
- componentName: <component>
switch: Disable
services:
- name: <cluster>-<component>-internet
roleSelector: primary
serviceType: LoadBalancer
kubectl get svc -n <ns> | grep internet
Expected output (LoadBalancer):
mycluster-mysql-internet LoadBalancer 10.96.x.x a1b2c3.elb.amazonaws.com 3306:30123/TCP 2m
Wait for the EXTERNAL-IP to be assigned (may take 1-2 minutes on cloud providers).
For NodePort:
kubectl get svc -n <ns> | grep nodeport
mycluster-mysql-nodeport NodePort 10.96.x.x <none> 3306:31234/TCP 2m
# MySQL
mysql -h <EXTERNAL-IP> -P 3306 -u root -p
# PostgreSQL
psql -h <EXTERNAL-IP> -p 5432 -U postgres
# Redis
redis-cli -h <EXTERNAL-IP> -p 6379 -a <password>
# MongoDB
mongosh mongodb://<user>:<password>@<EXTERNAL-IP>:27017
# Use any node's IP + the assigned NodePort
mysql -h <NODE-IP> -P <NODE-PORT> -u root -p
Get a node's IP:
kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}'
LoadBalancer EXTERNAL-IP stuck in <pending>:
Connection timeout:
kubectl describe svc <svc-name> -n <ns>For complete cloud provider annotations, exposing read replicas, local development without cloud LB (MetalLB, port-forward), and security considerations, see reference.md.
For general agent safety conventions (dry-run, status confirmation, production protection), see safety-patterns.md.
devops
Expand persistent volume storage for KubeBlocks database clusters via OpsRequest. Requires the StorageClass to support volume expansion (allowVolumeExpansion=true). Use when the user needs more disk space, wants to increase storage, expand volumes, or resize PVCs. NOT for changing CPU/memory (see vertical-scaling) or adding more replicas (see horizontal-scaling). Note that volume shrinking is not supported by Kubernetes.
data-ai
Scale CPU and memory resources for KubeBlocks database clusters via OpsRequest (vertical scaling). Supports in-place updates when the feature gate is enabled. Use when the user wants to change, increase, decrease, resize, or adjust CPU or memory resources of a database cluster. NOT for adding/removing replicas or shards (see horizontal-scaling) or expanding disk storage (see volume-expansion).
data-ai
Upgrade the KubeBlocks operator itself via Helm. Covers update operator, upgrade to v1.0, update kubeblocks version, and CRD updates. Use when the user wants to upgrade KubeBlocks, update the operator, or upgrade to a new KubeBlocks release. NOT for upgrading database engine versions (see minor-version-upgrade).
development
Diagnostic guide for KubeBlocks-managed database clusters. Use when the user reports troubleshoot, debug, diagnose, not working, error, failed, stuck, CrashLoopBackOff, cluster exception, or similar problems with their database cluster. This skill guides the agent through diagnostic steps — it does NOT perform actions.