Skip to content

Commit

Permalink
Refactor the all-in-one image
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed May 16, 2024
1 parent 3b622ae commit ae4eea5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 67 deletions.
4 changes: 2 additions & 2 deletions images/cluster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY --chmod=0755 bin/$TARGETPLATFORM/kwok /usr/local/bin/
COPY --chmod=0755 bin/$TARGETPLATFORM/kwokctl /usr/local/bin/

ENV KWOK_CONTROLLER_BINARY /usr/local/bin/kwok
ENV KWOK_KUBE_APISERVER_PORT 8080
ENV KWOK_KUBE_APISERVER_INSECURE_PORT 8080

ARG kube_version
ENV KWOK_KUBE_VERSION $kube_version
Expand All @@ -40,7 +40,7 @@ COPY --chmod=0755 bin/$TARGETPLATFORM/kwok /usr/local/bin/
COPY --chmod=0755 bin/$TARGETPLATFORM/kwokctl /usr/local/bin/

ENV KWOK_CONTROLLER_BINARY /usr/local/bin/kwok
ENV KWOK_KUBE_APISERVER_PORT 8080
ENV KWOK_KUBE_APISERVER_INSECURE_PORT 8080

ARG kube_version
ENV KWOK_KUBE_VERSION $kube_version
Expand Down
55 changes: 19 additions & 36 deletions images/cluster/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

show_info() {
sleep 1
export KWOK_KUBE_APISERVER_INSECURE_PORT="${KWOK_KUBE_APISERVER_INSECURE_PORT:-${KWOK_KUBE_APISERVER_PORT}}"
export KWOK_KUBE_APISERVER_PORT=0

# Print some useful information
echo "###############################################################################"
echo "> kubectl -s :${KWOK_KUBE_APISERVER_PORT} version"
kwokctl kubectl version || true

echo "###############################################################################"
echo "# The following kubeconfig can be used to connect to the Kubernetes API server"
cat <<EOF
apiVersion: v1
clusters:
- cluster:
server: http://127.0.0.1:${KWOK_KUBE_APISERVER_PORT}
name: kwok
contexts:
- context:
cluster: kwok
name: kwok
current-context: kwok
kind: Config
preferences: {}
users: null
EOF

echo "###############################################################################"
echo "> kubectl -s :${KWOK_KUBE_APISERVER_PORT} get ns"
kwokctl kubectl get ns || true
kwokctl create cluster || {
echo "Failed to create cluster"
exit 1
}

echo "###############################################################################"
echo "# The above example works if your host's port is the same as the container's,"
echo "# otherwise, change it to your host's port"
catch_exit() {
kwokctl stop cluster || true
exit 0
}

# Create a cluster
KWOK_KUBE_APISERVER_PORT=0 kwokctl create cluster "$@" || exit 1
keep_alive() {
while true; do
if ! output="$(kwokctl start cluster 2>&1)"; then
echo "Failed to start cluster: ${output}"
fi
sleep 10
done
}

show_info &
trap catch_exit INT TERM

# Start a proxy to the Kubernetes API server
kwokctl kubectl proxy --port="${KWOK_KUBE_APISERVER_PORT}" --accept-hosts='^*$' --address="0.0.0.0"
keep_alive
43 changes: 14 additions & 29 deletions site/content/en/docs/user/all-in-one-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@ This document walks through the steps to create a cluster with the all-in-one im
## Getting started

``` bash
docker run --rm -it -p 8080:8080 registry.k8s.io/kwok/cluster:v0.4.0-k8s.v1.28.0
docker run -d --name kwok-cluster -p 8080:8080 registry.k8s.io/kwok/cluster:v0.5.2-k8s.v1.29.2
```

``` log
Cluster is creating cluster=kwok
Cluster is created elapsed=0.3s cluster=kwok
Cluster is starting cluster=kwok
Cluster is started elapsed=0.7s cluster=kwok
You can now use your cluster with:
kubectl cluster-info --context kwok-kwok
Thanks for using kwok!
Starting to serve on [::]:8080
###############################################################################
> kubectl -s :8080 version
Client Version: v1.28.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.0
###############################################################################
# The following kubeconfig can be used to connect to the Kubernetes API server
### Quick Verification

You can use the `kubectl` with the `-s` option to connect to the cluster.

``` bash
kubectl -s :8080 version
```

### Setting up kubeconfig

You can set up the `kubeconfig` file to connect to the cluster.

``` bash
apiVersion: v1
clusters:
- cluster:
Expand All @@ -47,16 +42,6 @@ current-context: kwok
kind: Config
preferences: {}
users: null
###############################################################################
> kubectl -s :8080 get ns
NAME STATUS AGE
default Active 1s
kube-node-lease Active 1s
kube-public Active 1s
kube-system Active 1s
###############################################################################
# The above example works if your host's port is the same as the container's,
# otherwise, change it to your host's port
```

## Use in a pod
Expand Down

0 comments on commit ae4eea5

Please sign in to comment.