Skip to content

Commit 2d36601

Browse files
authored
Merge pull request #2102 from afbjorklund/k8s-kubectl
k8s: stop using sudo kubectl for kubeconfig
2 parents 5f16b68 + 8e17eee commit 2d36601

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/k8s.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Deploy kubernetes via kubeadm.
22
# $ limactl start ./k8s.yaml
3-
# $ limactl shell k8s sudo kubectl
3+
# $ limactl shell k8s kubectl
44

55
# It can be accessed from the host by exporting the kubeconfig file;
66
# the ports are already forwarded automatically by lima:
@@ -126,6 +126,14 @@ provision:
126126
# Replace the server address with localhost, so that it works also from the host
127127
sed -e "/server:/ s|https://.*:\([0-9]*\)$|https://127.0.0.1:\1|" -i $KUBECONFIG
128128
mkdir -p ${HOME:-/root}/.kube && cp -f $KUBECONFIG ${HOME:-/root}/.kube/config
129+
- mode: system
130+
script: |
131+
#!/bin/bash
132+
set -eux -o pipefail
133+
export KUBECONFIG=/etc/kubernetes/admin.conf
134+
mkdir -p ${LIMA_CIDATA_HOME}/.kube
135+
cp -f $KUBECONFIG ${LIMA_CIDATA_HOME}/.kube/config
136+
chown -R ${LIMA_CIDATA_USER} ${LIMA_CIDATA_HOME}/.kube
129137
probes:
130138
- description: "kubeadm to be installed"
131139
script: |
@@ -151,15 +159,15 @@ probes:
151159
script: |
152160
#!/bin/bash
153161
set -eux -o pipefail
154-
if ! timeout 300s bash -c "until sudo kubectl version >/dev/null 2>&1; do sleep 3; done"; then
162+
if ! timeout 300s bash -c "until kubectl version >/dev/null 2>&1; do sleep 3; done"; then
155163
echo >&2 "kubernetes cluster is not up and running yet"
156164
exit 1
157165
fi
158166
- description: "coredns deployment to be running"
159167
script: |
160168
#!/bin/bash
161169
set -eux -o pipefail
162-
sudo kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns
170+
kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns
163171
copyToHost:
164172
- guest: "/etc/kubernetes/admin.conf"
165173
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"

0 commit comments

Comments
 (0)