Skip to content

Commit 040f6af

Browse files
dhi: add guide to use in Kubernetes (#23393)
## Description dhi: add guide to use in Kubernetes. For now, this only covers image pull secrets. ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review
1 parent 58f0803 commit 040f6af

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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: 35
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 images 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+
Create a secret using a Personal Access Token (PAT). Ensure the token has at least
21+
read-only access to private repositories. For Docker Hub replace `<registry server>`
22+
with `docker.io`.
23+
24+
```console
25+
$ kubectl create -n <kubernetes namespace> secret docker-registry <secret name> --docker-server=<registry server> \
26+
--docker-username=<registry user> --docker-password=<access token> \
27+
--docker-email=<registry email>
28+
```
29+
30+
To tests the secrets use the following command:
31+
32+
```console
33+
kubectl apply --wait -f - <<EOF
34+
apiVersion: v1
35+
kind: Pod
36+
metadata:
37+
name: dhi-test
38+
namespace: <kubernetes namespace>
39+
spec:
40+
containers:
41+
- name: test
42+
image: <your-namespace>/dhi-bash:5
43+
command: [ "sh", "-c", "echo 'Hello from DHI in Kubernetes!'" ]
44+
imagePullSecrets:
45+
- name: <secret name>
46+
EOF
47+
```
48+
49+
Get the status of the pod by running:
50+
51+
```console
52+
$ kubectl get -n <kubernetes namespace> pods/dhi-test
53+
```
54+
55+
The command should return the following result:
56+
57+
```console
58+
NAME READY STATUS RESTARTS AGE
59+
dhi-test 0/1 Completed ... ...
60+
```
61+
62+
If instead, the result is the following, there might be an issue with your secret.
63+
64+
```console
65+
NAME READY STATUS RESTARTS AGE
66+
dhi-test 0/1 ErrImagePull 0 ...
67+
```
68+
69+
Verify the output of the pod by running, which should return `Hello from DHI in Kubernetes!`
70+
71+
```console
72+
kubectl logs -n <kubernetes namespace> pods/dhi-test
73+
```
74+
75+
After a successful test, the test pod can be deleted with the following command:
76+
77+
```console
78+
$ kubectl delete -n <kubernetes namespace> pods/dhi-test
79+
```

0 commit comments

Comments
 (0)