Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(microblog): ✨ cool way to use kubectl with go-templates
- Loading branch information
1 parent
022662e
commit 645dd14
Showing
3 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
extends: default | ||
rules: | ||
line-length: disable | ||
comments: | ||
require-starting-space: false | ||
ignore-shebangs: true | ||
min-spaces-from-content: 1 | ||
comments-indentation: disable | ||
|
||
# For all rules | ||
ignore: |- | ||
.markdownlint-cli2.yaml | ||
.licenses/ | ||
docs/godocs/ | ||
.pre-commit-config.yaml |
37 changes: 37 additions & 0 deletions
37
content/posts/2022/2022-03-10-go-templates-with-kubectl.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
|
||
date: 2022-03-10T19:13:52+0000 | ||
title: Go Templates With Kubectl | ||
slug: go-templates-with-kubectl | ||
tags: | ||
|
||
- tech | ||
- development | ||
- microblog | ||
- go | ||
- kubernetes | ||
|
||
# images: [/images/] | ||
|
||
typora-root-url: ../../../static | ||
typora-copy-images-to: ../../../static/images | ||
--- | ||
|
||
An alternative to using jsonpath with kubectl is go templates! | ||
|
||
Try switching this: | ||
|
||
````shell | ||
kubectl get serviceaccount myserviceaccount --context supercoolcontext --namespace themagicalcloud -o jsonpath='{.secrets[0].name}' | ||
``` | ||
To this and it should work just the same. | ||
Since I know go templates pretty well, this is a good alternative for jsonpath syntax. | ||
````shell | ||
kubectl get serviceaccount myserviceaccount --context supercoolcontext --namespace themagicalcloud -o go-template='{{range .secrets }}{{.name}}{{end}}' | ||
``` | ||
|
||
Further reading: | ||
|
||
- [List Container images using a go-template instead of jsonpath](https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-container-images-using-a-go-template-instead-of-jsonpath) |