> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Initialize DockerHub

> Guide to push a Docker image to Docker Hub and deploy it with Flux to a Kubernetes cluster by updating manifests and verifying the app

In this lesson you'll push a Docker image to Docker Hub and update Flux-managed manifests to deploy that image to a Flux-enabled Kubernetes cluster. The workflow shows how to:

* Log in to Docker Hub
* Pull an existing upstream image
* Tag and push that image to your Docker Hub repository
* Update a Kubernetes Deployment to reference the pushed image
* Create Flux GitRepository and Kustomization objects to deploy the manifest
* Verify the application is running and confirm the bug fix present in version 7.8.0

Quick links:

* Flux docs: [https://fluxcd.io/docs/](https://fluxcd.io/docs/)
* Docker Hub: [https://hub.docker.com/](https://hub.docker.com/)
* Kubernetes docs: [https://kubernetes.io/docs/](https://kubernetes.io/docs/)

## Prerequisites

| Requirement | Why |
| - | - |
| Docker Hub account | Needed to host container images. Create one at `https://hub.docker.com`. |
| Docker installed | Required to pull, tag, and push images. |
| Flux-enabled cluster and Flux CLI | Flux will deploy the manifests; Flux CLI helps create GitRepository/Kustomization objects. |

Make sure to replace `siddharth67` in the examples below with your own Docker Hub username wherever applicable. For improved security, prefer using a Docker access token instead of your password when running `docker login`.

Never commit Docker credentials or access tokens to git. Use secret management or CI/CD secret stores when automating image pushes.

***

## 1) Log in to Docker Hub

If you are authenticated to another registry, log out first, then log in to Docker Hub:

```bash theme={null}
# log out any current registry
docker logout

# log in to Docker Hub (use a personal access token if possible)
docker login
# Enter your Docker Hub username and password or token when prompted
```

Successful login will show:

```text theme={null}
Login Succeeded
```

***

## 2) Pull the existing image

Pull the upstream image used as the source for this demo:

```bash theme={null}
docker pull siddharth67/block-buster-dev:7.8.0
```

Example output (condensed):

```text theme={null}
7.8.0: Pulling from siddharth67/block-buster-dev
Digest: sha256:cf5c4e2a9ef6ad48798dd0ae41e3a39565eb2bce7dbc69f239a22804ee78f691
Status: Image is up to date for docker.io/siddharth67/block-buster-dev:7.8.0
```

***

## 3) Tag the image for your Docker Hub repository

Tag the pulled image to point at your Docker Hub repository and the desired image name. Replace `your-username` with your Docker Hub username:

```bash theme={null}
docker tag siddharth67/block-buster-dev:7.8.0 your-username/bb-app-flux-demo:7.8.0
```

Instructor example (preserves original username for clarity):

```bash theme={null}
docker tag siddharth67/block-buster-dev:7.8.0 siddharth67/bb-app-flux-demo:7.8.0
```

***

## 4) Push the image to Docker Hub

Push the tagged image up to your Docker Hub repository:

```bash theme={null}
docker push your-username/bb-app-flux-demo:7.8.0
```

Example push output (condensed):

```text theme={null}
The push refers to repository [docker.io/siddharth67/bb-app-flux-demo]
7.8.0: Pushed
digest: sha256:cf5c4e2a9ef6ad48798dd0ae41e3a39565eb2bce7dbc69f239a22804ee78f691 size: 3662
```

After the push completes, verify the `7.8.0` tag is visible in your Docker Hub repository UI for `your-username/bb-app-flux-demo`.

***

## 5) Update the deployment manifest

Edit the Deployment YAML stored in the `bb-app-source` repository (branch `8-demo`) so the `image:` field points to your pushed image. This minimal example highlights the `image:` field to change:

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bb-app
  namespace: 8-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bb-app
  template:
    metadata:
      labels:
        app: bb-app
    spec:
      containers:
        - name: app
          image: siddharth67/bb-app-flux-demo:7.8.0
          imagePullPolicy: Always
          resources:
            requests:
              memory: "10Mi"
              cpu: "10m"
```

Before committing, replace `siddharth67` with your Docker Hub username in the `image:` field.

***

## 6) Publish manifests and create Flux objects

The demo uses two repositories:

* A source repo that contains application manifests (`bb-app-source` branch `8-demo`)
* A Flux repo that contains Flux GitRepository and Kustomization manifests (e.g., `flux-clusters`)

From the `flux-clusters/dev-cluster` directory, create a GitRepository source and Kustomization for the `8-demo` branch. The commands below use `--export` to save the generated objects to YAML files:

```bash theme={null}
# from the flux-clusters/dev-cluster directory
flux create source git 8-demo-source-git-bb-app \
  --url https://github.com/sidd-harth-2/bb-app-source \
  --branch 8-demo \
  --timeout 10s \
  --export > 8-demo-source-git-bb-app.yml

flux create kustomization 8-demo-kustomize-git-bb-app \
  --source GitRepository/8-demo-source-git-bb-app \
  --prune true \
  --interval 100s \
  --target-namespace 8-demo \
  --path manifests \
  --export > 8-demo-kustomize-git-bb-app.yml
```

Example exported manifests:

GitRepository (8-demo-source-git-bb-app.yml)

```yaml theme={null}
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: GitRepository
metadata:
  name: 8-demo-source-git-bb-app
  namespace: flux-system
spec:
  interval: 1m0s
  ref:
    branch: 8-demo
  url: https://github.com/sidd-harth-2/bb-app-source
```

Kustomization (8-demo-kustomize-git-bb-app.yml)

```yaml theme={null}
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: 8-demo-kustomize-git-bb-app
  namespace: flux-system
spec:
  interval: 1m40s
  path: ./manifests
  prune: true
  sourceRef:
    kind: GitRepository
    name: 8-demo-source-git-bb-app
  targetNamespace: 8-demo
```

Commit and push these files to the repository monitored by Flux (for example, your `flux-clusters` repo). To accelerate reconciliation after pushing, run:

```bash theme={null}
flux reconcile source git 8-demo-source-git-bb-app --with-source
flux reconcile kustomization 8-demo-kustomize-git-bb-app
```

***

## 7) Verify deployment

Confirm Flux created the `8-demo` namespace and applied the manifests:

```bash theme={null}
kubectl get namespaces
kubectl get all -n 8-demo
# expect: Pod, Service, Deployment, ReplicaSet in Running/Ready state
```

The application in this demo is exposed on a NodePort. The demo uses:

```text theme={null}
http://localhost:30008
```

Open that URL in your browser and exercise the app. Version 7.8.0 includes a bug fix: the high score is persisted to the database.

![A screenshot of a web-based game titled "BLOCK BUSTER" showing deployment info at the top (pod name, IP, namespace, node, app version) and a large dark play area with "PRESS START" in the center and a green "START GAME" button at the bottom.](https://mintcdn.com/kodekloud-c4ac6d9a/AyhVWHpoMIYCWiei/images/GitOps-with-FluxCD/Image-Automation-Controller/Demo-Initialize-DockerHub/block-buster-game-deployment-press-start.jpg?fit=max\&auto=format\&n=AyhVWHpoMIYCWiei\&q=85\&s=a15891dd626ac83f17e619f8fbb73dae)

In the demo, after pressing Start and ending the game quickly, a score like `1200` will be persisted and displayed in the high score field after restarting — confirming the fix in `7.8.0`.

***

## Next steps

* Automate image updates with Flux Image Automation Controller and an `ImageRepository` object to fetch tags from Docker Hub automatically.
* Integrate CI to build and push images and then let Flux detect and roll out updates.

Useful command reference:

| Action | Command / Example |
| - | - |
| Push image | `docker push your-username/bb-app-flux-demo:7.8.0` |
| Reconcile GitRepository | `flux reconcile source git 8-demo-source-git-bb-app --with-source` |
| Reconcile Kustomization | `flux reconcile kustomization 8-demo-kustomize-git-bb-app` |
| Inspect namespace | `kubectl get all -n 8-demo` |

For more on Flux GitRepository and Kustomization, see the Flux documentation: [https://fluxcd.io/docs/](https://fluxcd.io/docs/)

That's all for this demo.

> **[Watch Video](https://learn.kodekloud.com/user/courses/gitops-with-fluxcd/module/e4076c7b-6728-412c-b4d7-9316fc346fc5/lesson/8b4c829a-b3d6-4291-98ff-51fc8b52e6bf)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.