我们正在尝试使用github actions,我们希望在github secrets中保留敏感数据(如kubeconfig )--我创建了一个名为KUBECONFIG1的GitHub秘密
复制的步骤
在GitHub秘密中,我应该存储以下文件,并尝试使用此https://onlineyamltools.com/convert-yaml-to-json转换为JSON
apiVersion: v1
kind: Config
clusters:
- name: brf
cluster:
certificate-authority-data: >-
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURTakNBd0t6RXBNQ2NHQTFVRUF4TWdkbWx5ZE2bUljTlRtakFWCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
server: 'https://vfg.canary.k8s.ondemand.com'
users:
- name: user1
user:
token: >-
eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuW1lc3BhY2UiOiJnYXJkZW4tZGV2e
contexts:
- name: g-root
context:
cluster: garv
user: robot
namespace: gking
current-context: gaot在github工作流中,我们将上面的文件内容与名称KUBECONFIG1保持在一起,并从其中创建k8s机密。
name: Example action
on: [push]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: install k8s
run: |
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=777 sh -
cat /etc/rancher/k3s/k3s.yaml
mkdir -p ~/.kube
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
- run: 'echo -e "$KUBECONFIG1" > ~/.tmpfile.json'
shell: bash
env:
KUBECONFIG1: ${{secrets.KUBECONFIG1}}
- name: example
shell: bash
run: |
cd ~/
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default运行此工作流后,我得到以下错误:
error: error loading config file "/home/runner/work/_temp/kubeconfig_1617030542039": couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct *** APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" ***
Error: Process completed with exit code 1.我还尝试获取文件内容并使用https://onlinelinuxtools.com/escape-shell-characters。
当我们使用Golang时,也许我应该使用kubeconfig作为go模板,并将sensitive-data (如token、certificate-authority-data等)保存为github秘密,并且在工作流过程中将机密值更新到模板,但不确定如何.
我所需要的,我需要在工作流中使用以下命令
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default
发布于 2021-04-01 19:44:03
问题在于下面的命令
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default问题是,~会转到kubectl,它不会将其扩展到主目录。所以,如果你像下面这样改变它,它就会起作用。
kubectl create secret generic project-kubecfg --from-file=/home/runner/.tmpfile.json -n default或者更确切地说,使用固定路径,而不是使用~的主目录。
https://stackoverflow.com/questions/66856876
复制相似问题