Skip to content

Commit 909220f

Browse files
dhi: add guide to use in Kubernetes
1 parent b67e13f commit 909220f

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

content/manuals/dhi/how-to/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ params:
2020
description: Learn how to pull, run, and reference Docker Hardened Images in Dockerfiles, CI pipelines, and standard development workflows.
2121
icon: play_arrow
2222
link: /dhi/how-to/use/
23+
- title: Use a Docker Hardened Image in Kubernetes
24+
description: Learn how to use Docker Hardened Images in Kubernetes deployments.
25+
icon: play_arrow
26+
link: /dhi/how-to/k8s/
2327
- title: Manage Docker Hardened Images
2428
description: Learn how to manage your mirrored and customized Docker Hardened Images in your organization.
2529
icon: reorder

content/manuals/dhi/how-to/k8s.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Use a Docker Hardened Image in Kubernetes
3+
linktitle: Use an image in Kubernetes
4+
description: Learn how to use Docker Hardened Images in Kubernetes deployments.
5+
keywords: use hardened image, kubernetes, k8s
6+
weight: 10
7+
---
8+
9+
{{< summary-bar feature_name="Docker Hardened Images" >}}
10+
11+
## Authentication
12+
13+
To be able to use Docker Hardened Images in Kubernetes, you need to create a
14+
Kubernetes secret for pulling image from your mirror or internal registry.
15+
16+
> [!NOTE]
17+
>
18+
> You need to create this secret in each Kubernetes namespace that uses a DHI.
19+
20+
To use the credentials from Docker Desktop run:
21+
22+
```
23+
$ kubectl create -n <kubernetes namespace> secret generic <secret name> \
24+
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
25+
--type=kubernetes.io/dockerconfigjson
26+
```
27+
28+
Alternatively, you can create the secret manually using a Personal Access Token (PAT).
29+
Ensure the token has at least read-only access to private repositories. For Docker Hub
30+
replace`<registry server>` with `docker.io`
31+
32+
```
33+
$ kubectl create -n <kubernetes namespace> secret docker-registry <secret name> --docker-server=<registry server> \
34+
--docker-username=<registry user> --docker-password=<access token> \
35+
--docker-email=<registry email>
36+
```
37+
38+
To tests the secrets use the following command:
39+
40+
```
41+
kubectl apply --wait -f - <<EOF
42+
apiVersion: v1
43+
kind: Pod
44+
metadata:
45+
name: dhi-test
46+
namespace: <kubernetes namespace>
47+
spec:
48+
containers:
49+
- name: test
50+
image: <your-namespace>/dhi-bash:5
51+
command: [ "sh", "-c", "echo 'Hello from DHI in Kubernetes!'" ]
52+
imagePullSecrets:
53+
- name: <secret name>
54+
EOF
55+
```
56+
57+
Get the status of the pod by running:
58+
59+
```
60+
$ kubectl get -n <kubernetes namespace> pods/dhi-test
61+
```
62+
63+
You should be getting the following result
64+
65+
```
66+
NAME READY STATUS RESTARTS AGE
67+
dhi-test 0/1 Completed ... ...
68+
```
69+
70+
If instead, the result is the following, there might be an issue with your secret.
71+
72+
```
73+
NAME READY STATUS RESTARTS AGE
74+
dhi-test 0/1 ErrImagePull 0 ...
75+
```
76+
77+
After a successful test, the test pod can be deleted with the following command:
78+
79+
```
80+
$ kubectl delete -n <kubernetes namespace> pods/dhi-test
81+
```

0 commit comments

Comments
 (0)