我们正在尝试使用
我尝试获取文件内容并使用https://onlinelinuxtools.com/escape-shell-characters来进行转义。由于我们使用Golang,我可以将kubeconfig作为go模板并将敏感数据(如token、certificate-authority-data等)保存为Github秘密,并在工作流程中将秘密值更新到模板中,但不确定如何操作。
最终,我需要使以下命令在工作流程中正常运行:
github actions
,并且希望将敏感数据(如kubeconfig
)保留在github的secrets
中。
我已经创建了一个名为KUBECONFIG1
的GitHub secret。
重现步骤:
在GitHub secret中,我应该存储以下文件,还尝试使用此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 Actions 工作流程中,我们将文件内容保存为名为 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模板并将敏感数据(如token、certificate-authority-data等)保存为Github秘密,并在工作流程中将秘密值更新到模板中,但不确定如何操作。
最终,我需要使以下命令在工作流程中正常运行:
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default
。
KUBECONFIG1
的值并隐藏token吗? - jordanmcat .tmpfile.json
时,我看到星号。 - PJEMkubectl create
命令之前,先使用cat
命令查看文件内容,以确保它包含了你认为的内容。 - jordanm