
AWS SageMaker is a fully managed Machine Learning (ML) platform that provides notebooks, training jobs, pipelines, model serving, and hyperparameter tuning as hosted services within the AWS ecosystem. It abstracts infrastructure management but ties teams to AWS-specific APIs, regional data boundaries, and usage-based pricing that scales with compute time.
Kubeflow is an open-source alternative built on Kubernetes that replicates each SageMaker capability as a portable, self-hosted component, giving teams control over infrastructure, data residency, and resource allocation.
This article explains how to deploy Kubeflow on a Kubernetes cluster as a self-hosted replacement for AWS SageMaker. It covers installation via Kustomize manifests, notebook configuration, pipeline orchestration, distributed training with the Trainer v2 API, model serving with KServe, hyperparameter tuning with Katib, access control, object storage integration, and migration steps from SageMaker.
AWS SageMaker and Kubeflow provide comparable ML platform capabilities, but they differ in deployment and operational models. SageMaker delivers these as fully managed services within the AWS ecosystem, while Kubeflow provides equivalent open-source components that run on any Kubernetes cluster. The following table maps each SageMaker feature to its Kubeflow counterpart.
Self-hosting with Kubeflow eliminates per-minute compute charges, keeps all data within your own cluster, runs on any cloud provider or on-premises hardware, and allows complete customization of every component.
Before you begin, you need to:
StorageClass that is configured in your cluster for provisioning persistent volumes.Kubeflow uses Kustomize to deploy its components as Kubernetes resources. The official kubeflow/manifests repository contains all component manifests that are organized under common/ for shared infrastructure services such as Istio, cert-manager, and Dex, and under applications/ for Kubeflow-specific applications such as Pipelines, Notebooks, and KServe.
The following steps clone the Kubeflow manifests repository and deploy all components to the cluster.
Verify the Kubernetes cluster connection.
Check the Kubernetes server version.
Verify that the Server Version field shows version 1.31 or later.
Clone the official Kubeflow manifests repository.
Switch to the manifests directory.
Check out the latest stable release tag.
Deploy all Kubeflow components. The command uses a bounded retry loop that attempts the installation up to 5 times, which accommodates the time that Kubernetes CRDs and webhooks need to register before dependent resources apply. The loop exits automatically after a successful apply or after reaching the retry limit.
The first one or two attempts may output errors about CRDs or webhooks not being established. These errors are expected and resolve on subsequent attempts after the CRDs register. The loop exits automatically when the apply succeeds, usually on the second or third attempt after CRDs register. The full installation takes approximately 10 to 15 minutes after the final successful apply for all pods to reach a Running state. The --server-side --force-conflicts flags are required because some Kubeflow CRDs exceed the annotation size limit that standard kubectl apply supports.
The default installation uses the email user@example.com and password 12341234. Change these credentials before exposing Kubeflow to any network. See the Set Up Access Control section later in this article for instructions.
After the deployment completes, verify that all Kubeflow components are running and the CRDs are registered.
Check that all pods in the kubeflow namespace reach a Running state.
Verify that all listed pods display a Running status with all containers ready. If any pods show CrashLoopBackOff or Pending, check their logs with kubectl logs -n kubeflow POD-NAME and verify that the cluster meets the minimum resource requirements.
Check that the Istio ingress gateway service is running.
Verify that the service appears in the output.
Check that Kubeflow and its component CRDs are registered.
The output displays the count of registered CRDs across Kubeflow and its components. Verify that the count matches the expected number for your Kubeflow version.
Kubeflow uses profiles to provide namespace-level isolation for each user. The default installation does not provision a user namespace automatically. Create one before proceeding.
Create a new file called user-profile.yaml.
Add the following configuration:
Save and close the file.
Apply the profile manifest.
This command creates an isolated namespace called kubeflow-user-example-com with default Role-Based Access Control (RBAC) policies and a service account for the default user.
Verify that the namespace exists.
Verify that the default service account exists. The service account takes a few seconds to provision after the profile is created. Wait 10 seconds before running this command.
Kubeflow components such as Notebooks, Pipelines, and the Model Registry require persistent storage. The cluster needs a default StorageClass to dynamically provision Persistent Volume Claims (PVCs).
Verify that a default StorageClass exists.
The default StorageClass shows (default) next to its name. If no default exists, set one by annotating an existing StorageClass. Replace STORAGE-CLASS-NAME with the name of an existing StorageClass from the output above.
Kubeflow Notebooks provides managed JupyterLab, VS Code, and RStudio environments that run as Kubernetes pods with direct access to cluster resources, GPUs, and persistent storage. This component replaces SageMaker Studio notebooks with a self-hosted alternative.
Set up port forwarding and log in to the Kubeflow Central Dashboard.
Set up port forwarding to access the Kubeflow Central Dashboard.
Open http://localhost:8080 in a web browser. The Kubeflow login screen appears. Click Sign in with Dex.
Enter the default credentials on the Dex login form and click Login.
user@example.com12341234
The Kubeflow Central Dashboard loads with links to Notebooks, Pipelines, Katib Experiments, KServe Endpoints, and other components. Select kubeflow-user-example-com from the namespace dropdown at the top.
Launch a new notebook server from the Kubeflow dashboard.
Navigate to Notebooks in the left sidebar and click New Notebook.
Enter ml-workspace in the Name field.
Select the notebook environment from the image cards. Choose JupyterLab for a general-purpose data science environment. Select VisualStudio Code for a code editor interface, or RStudio for R-based statistical computing. To use a specific image version, select Custom Notebook from the dropdown below the cards.
Set Minimum CPU to 0.5 and Minimum Memory Gi to 1.
Leave the Workspace Volume at the default 5Gi. This volume persists data across notebook restarts.
Click Launch and wait for the notebook pod to reach a Running state. The status indicator turns green when the notebook is ready.
Open the JupyterLab interface and verify that ML libraries are accessible.
Click Connect next to the notebook server name. A new tab opens with the JupyterLab interface.
Click Python 3 (ipykernel) under the Notebook section in the launcher to create a new notebook. Paste the following code into a cell and press Shift + Enter to run it.
The cell outputs an accuracy score such as Accuracy: 0.9750.
Kubeflow Pipelines (KFP) is an orchestration platform that enables building and deploying ML workflows as Directed Acyclic Graphs (DAGs). Each pipeline step runs in its own container, which enables reproducibility and version tracking. KFP replaces SageMaker Pipelines with an open-source alternative.
Install the KFP SDK, define a three-step pipeline, compile it, and submit a run through the internal API. The following steps use both the notebook terminal and the cluster management terminal where specified.
Inside JupyterLab, click File > New > Terminal to open a terminal tab.
Create the pipeline definition file.
Add the following configuration:
Save and close the file.
Compile the pipeline to generate the YAML definition.
Switch to the cluster management terminal and create the authorization policy manifest. This policy allows the notebook namespace to call the Kubeflow Pipelines API through the Istio service mesh.
Add the following configuration:
Save and close the file.
Apply the authorization policy.
Switch to the notebook terminal and upload the compiled pipeline to Kubeflow Pipelines through the internal API.
The command returns a JSON response that contains the pipeline_id. Note this value for the next step.
Create an experiment to organize pipeline runs. Kubeflow Pipelines automatically creates a system experiment named Default, so use a different name to avoid a conflict.
The command returns a JSON response that contains the experiment_id. Note this value for the next step.
Start a pipeline run. Replace PIPELINE-ID and EXPERIMENT-ID with the values from the previous steps.
The pipeline run status is visible from the command line and from the Kubeflow dashboard. The dashboard provides a graph view that shows each step's completion state.
Verify that the workflow completed.
Verify that the STATUS column shows Succeeded.
Navigate to Pipelines in the left sidebar of the Kubeflow dashboard, then click Experiments. Click sample-experiment, then click the test-run entry. The graph view shows the preprocess, train, and evaluate steps each marked with a green checkmark when the run completes successfully.
Kubeflow Trainer v2 provides a unified TrainJob API for running distributed training jobs across frameworks including PyTorch, DeepSpeed, MLX, JAX, and XGBoost. The Trainer uses ClusterTrainingRuntime resources that define pre-configured runtime environments, which separates infrastructure configuration from training logic. Kubeflow Trainer replaces SageMaker Training Jobs with native Kubernetes-based distributed training.
Create and deploy a distributed PyTorch training job that uses the torch-distributed runtime. Run the following commands from the cluster management terminal.
Create the TrainJob manifest.
Add the following configuration:
Save and close the file. The runtimeRef field references the torch-distributed ClusterTrainingRuntime, which configures the PyTorch distributed training environment. The numNodes field specifies the number of training nodes that Kubeflow provisions for the job.
Apply the training manifest.
Check the training job status from the cluster management terminal.
Verify the TrainJob status.
The STATE column shows Complete when training finishes successfully.
KServe provides a Kubernetes CRD called InferenceService for deploying, scaling, and managing ML model endpoints. It supports serverless inference with autoscaling from zero, canary rollouts, and multi-model serving across frameworks including TensorFlow, PyTorch, scikit-learn, XGBoost, and ONNX. KServe also supports deploying models directly from Hugging Face Hub using the hf:// URI schema and from the Kubeflow Model Registry using the model-registry:// protocol. KServe is included in the Kubeflow installation and replaces SageMaker Endpoints.
Deploy a pre-trained scikit-learn model and expose it as a serving endpoint. Run the following commands from the cluster management terminal.
Create the model serving manifest.
Add the following configuration:
Save and close the file.
Apply the InferenceService manifest.
Monitor the InferenceService status. The -w flag watches for status changes and updates the output in place.
The READY column changes to True when the model is loaded and serving. Press Ctrl + C to stop watching. Navigate to KServe Endpoints in the Kubeflow dashboard sidebar to view the deployed model.
Send a test inference request to verify that the model is serving predictions.
Run the following command from the Kubeflow notebook terminal, which has direct access to the cluster-internal service endpoint.
The response returns predicted class labels.
Katib is the Kubeflow component that provides automated hyperparameter tuning and neural architecture search. It supports multiple search algorithms including random search, grid search, Bayesian optimization, Tree-structured Parzen Estimator (TPE), and CMA Evolution Strategy. Katib replaces SageMaker Experiments and Automatic Model Tuning with a Kubernetes-native solution.
Katib experiments are defined and submitted through the Katib Python SDK from a JupyterLab notebook cell. The SDK creates the experiment resource on the cluster and manages trial pod configuration and metrics collection automatically.
Open a terminal in JupyterLab by clicking File > New > Terminal and install the Katib Python SDK.
Close the terminal tab and create a new Python notebook by clicking File > New > Notebook, then selecting Python 3 (ipykernel) as the kernel. Run the following code in a cell to define an objective function and launch a tuning experiment.
The tune() method creates a Katib experiment that runs 4 trials (2 in parallel) using random search. The cell output includes a Katib Experiment tune-experiment link here line. Click here to monitor trial progress in the Katib Experiments tab. The experiment status turns green when all trials complete.
Retrieve the optimal hyperparameters by running the following code in the next cell.
Kubeflow uses Dex as its OpenID Connect (OIDC) identity provider and Istio for network-level authorization. Each user gets an isolated namespace, which is called a profile, with its own resources, secrets, and RBAC policies.
The Dex ConfigMap uses hashFromEnv: DEX_USER_PASSWORD to read the password hash from an environment variable rather than storing it directly in the ConfigMap. To change the default password, update the Secret that provides this environment variable to the Dex pod.
Install the bcrypt Python package to generate a password hash.
Generate a bcrypt hash for the new password. Replace YOUR-SECURE-PASSWORD with the password you want to set.
Copy the output hash for use in the next step.
Update the dex-passwords Secret with the new hash. Replace GENERATED-BCRYPT-HASH with the hash output from the previous step.
The command outputs a warning about a missing annotation. This is expected because dex-passwords was created by Kubeflow without --save-config. Verify that the output ends with secret/dex-passwords configured.
Restart the Dex deployment to apply the changes.
To add additional static users or configure external identity providers such as Lightweight Directory Access Protocol (LDAP), GitHub, or Google, add entries to the staticPasswords list or connector entries in the Dex ConfigMap. See the Dex documentation for details.
Each additional user needs a profile that follows the same manifest structure as the default user profile. Replace the metadata.name and owner.name fields with the new user's details, then apply the manifest with kubectl apply -f.
To give an existing user access to another user's namespace without creating a separate profile, navigate to the target namespace in the Kubeflow dashboard namespace dropdown. Click Manage Contributors in the left sidebar and enter the user's email address.
ML workflows generate large artifacts including trained models, pipeline outputs, datasets, and logs. Kubeflow uses SeaweedFS as its default S3-compatible object storage backend for artifact persistence. KServe also supports S3-compatible storage for loading model artifacts.
The default Kubeflow installation deploys SeaweedFS in the kubeflow namespace with pre-configured credentials. Verify that the storage deployment is running.
Check the SeaweedFS pod status.
For production deployments, replace SeaweedFS with an external S3-compatible object storage service. Create a Kubernetes secret with your external S3 credentials in the user namespace. Replace YOUR-ACCESS-KEY and YOUR-SECRET-KEY with the credentials from your storage service.
Update the kfp-launcher ConfigMap in the user namespace to route pipeline artifacts to the external S3 endpoint. Replace YOUR-BUCKET, YOUR-S3-ENDPOINT, and YOUR-REGION with values from your storage service.
Restart the Kubeflow Pipelines API server to apply the changes.
Verify that the pod restarts successfully.
Verify that all listed pods show a Running status.
Migrating from SageMaker to Kubeflow involves exporting existing assets and mapping each SageMaker component to its Kubeflow equivalent. Notebooks transfer without format changes since both platforms use the standard Jupyter notebook format. Training scripts, pipelines, and experiments require rewriting to replace SageMaker SDK calls with Kubeflow and KFP SDK equivalents.
Export Notebooks: Download SageMaker Studio notebooks as .ipynb files from the SageMaker console or the AWS CLI. Upload them directly to Kubeflow Notebook servers, since both platforms use standard Jupyter notebook format. Update any AWS SDK calls such as sagemaker.Session() or boto3 references that rely on SageMaker-specific APIs.
Convert Training Scripts: SageMaker training scripts that use the SageMaker Python SDK estimator pattern (such as sagemaker.pytorch.PyTorch()) need conversion to standard framework training scripts. Replace SageMaker-specific environment variables like SM_MODEL_DIR and SM_CHANNEL_TRAINING with Kubernetes volume mount paths. Package the training code into container images and reference them in TrainJob manifests.
Migrate Pipelines: SageMaker Pipelines that are defined using the SageMaker SDK need rewriting with the KFP SDK. Map each sagemaker.workflow.steps step to a KFP @dsl.component function. Replace sagemaker.processing.ProcessingStep with KFP container components, and replace sagemaker.workflow.pipeline.Pipeline with @dsl.pipeline decorated functions.
Export Models: Download trained model artifacts from SageMaker S3 buckets using the AWS CLI. Upload them to your Kubeflow-connected object storage. Update the storageUri in KServe InferenceService manifests to point to the new storage location. KServe supports the same model formats that SageMaker uses (SavedModel, TorchScript, ONNX, scikit-learn pickle files) without conversion.
Migrate Experiments: Export SageMaker experiment tracking data using the SageMaker SDK list_trials() and describe_trial_component() API calls. For hyperparameter tuning, recreate tuning jobs as Katib experiments with equivalent search spaces and objective metrics using the Katib Python SDK.
You have successfully deployed Kubeflow on a Kubernetes cluster as a self-hosted alternative to AWS SageMaker. The deployment includes interactive notebooks for model development, Kubeflow Pipelines for workflow orchestration, the Trainer v2 API for distributed PyTorch training, KServe for model serving with serverless inference, and Katib for automated hyperparameter tuning. For more information on GPU scheduling, multi-tenancy, and production hardening, visit the official Kubeflow documentation.
0 Comments
Be the first to comment and share your perspective with the community.