Skip to content

Commit 766036f

Browse files
committed
feat(install): adding resources install
Kustomize was just too difficult to get working well in getting started. This introduces an `install` and `delete` command that does it for all resources, not just the CRD. There's some minimal patching that happens to the resources so that they hopefully can still be applied with `kubectl` directly from the repo.
1 parent 813ecb3 commit 766036f

17 files changed

+497
-145
lines changed

Cargo.lock

+37-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ categories = ["command-line-interface", "development-tools", "virtualization"]
2525
[dependencies]
2626
ansi-to-tui = "6.0.0"
2727
async-trait = "0.1.82"
28+
base64 = "0.22.1"
2829
bon = "2.2.1"
2930
cata = { version = "0.1.1" }
3031
chrono = { version = "0.4.38", features = ["serde"] }
@@ -37,13 +38,13 @@ crossterm = { version = "0.28.1", default-features = false, features = [
3738
"events",
3839
] }
3940
derive_builder = { version = "0.20.1", features = ["clippy"] }
40-
either = "1.13.0"
4141
eyre = "0.6.12"
4242
fast_qr = "0.12.5"
4343
futures = "0.3.30"
4444
hostname = "0.4.0"
4545
humantime = "2.1.0"
4646
itertools = "0.13.0"
47+
json-patch = "2.0.0"
4748
json_value_merge = "2.0.0"
4849
jsonwebtoken = "9.3.0"
4950
k8s-openapi = { version = "0.22.0", features = ["earliest"] }
@@ -65,6 +66,7 @@ ringbuffer = "0.15.0"
6566
russh = "0.45.0"
6667
russh-keys = "0.45.0"
6768
russh-sftp = "2.0.3"
69+
rust-embed = "8.5.0"
6870
schemars = { version = "0.8.21", features = ["chrono"] }
6971
serde = { version = "1.0.210", features = ["derive"] }
7072
serde_json = "1.0.128"

DEVELOPMENT.md

+8
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ If you're not running on the cluster, you'll want to:
8989
- Set `POD_UID` to the `metadata.uid` of the pod from `HOSTNAME`.
9090
- Set `POD_IP` to the IP address of your host. You can get this by going into a
9191
pod and doing a `nslookup host.docker.internal`.
92+
93+
## Kubernetes Resources
94+
95+
When updating resources, make sure to update them in both places:
96+
97+
- [resources](/resources/) - Used for `kty resources`, primarily as part of
98+
getting started.
99+
- [helm/templates](/helm/templates/) - Used for `helm install`

TODO.md

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
particular, it seems like it is a little difficult to see the install commands
1212
and realize that's what you need to use.
1313

14-
## `users grant`
15-
16-
- Allow YAML output for users who don't have a `kubeconfig`.
17-
1814
## Authorization
1915

2016
- Groups are probably what most users are going to want to use to configure all

docs/pages/getting-started.mdx

+124-29
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,147 @@
1+
import { Callout } from 'nextra/components'
2+
13
# Getting Started
24

3-
1. Download the [cli][cli-download] and add it to your `$PATH`.
4-
1. Get a k8s cluster. [k3d][k3d] is a convenient way to get a cluster up and
5-
running fast. Follow their installation instructions and create a default
6-
cluster.
7-
1. Grant your email address access to the cluster. Choose `cluster-admin` if
8-
you'd like something simple to check out how things work. For more details on
9-
the minimum possible permissions, read the [Authorization][auth] section. The
10-
email address is what you'll be using to authenticate against. It can either
11-
be the one associated with a google or github account. Note, the ID used for
12-
login and the providers available can all be configured.
5+
As part of this getting started guide, you will:
6+
7+
- Grant your email address access to the cluster.
8+
- Install kty on your cluster.
9+
- Test it out!
10+
11+
<Callout type="info">
12+
You can run kty outside of a cluster, but it is a little more complex to get
13+
setup because of permissions. Check out the
14+
[off-cluster](/installation#off-cluster) instructions for more details.
15+
</Callout>
16+
17+
## Prerequisites
18+
19+
- Get a k8s cluster. [k3d][k3d] is a convenient way to get a cluster up and
20+
running fast. Follow their installation instructions and create a default
21+
cluster.
22+
23+
## Install the CLI
24+
25+
Binares are available on the [releases page][cli-download]. If you have
26+
homebrew, you can install with:
27+
28+
```bash
29+
brew install grampelberg/kty/kty
30+
```
31+
32+
<Callout type="info">
33+
`ssh` is all you need to use kty. The CLI is optional, but makes installation
34+
and management a little easier.
35+
</Callout>
36+
37+
## Setup Permissions
38+
39+
Just like `kubectl`, kty delegates authorization to Kubernetes RBAC. The email
40+
address you use to login needs to be granted access to the cluster. If your
41+
organization already uses email addresses for access, you can skip the install
42+
step - make sure you verify you've got access though.
43+
44+
To grant access to your email, you can use the `kty` CLI. It will apply a
45+
`ClusteerRoleBinding` that associates your email address with the provided role.
46+
In this example, we're using `cluster-admin` because it is everywhere and an
47+
easy way to get started. You can change this to another role, anything with the
48+
[minimum permissions](/architecture/access-control#authorization) in fact. Run:
49+
50+
```bash
51+
kty users grant cluster-admin me@example.com
52+
```
53+
54+
<Callout type="info">
55+
If you'd like to verify the YAML or apply it youself, pass `-o yaml` to the
56+
command.
57+
</Callout>
58+
59+
You can verify that this worked and you have the minimum permissions required by
60+
running:
61+
62+
```bash
63+
kty users check me@example.com
64+
```
1365

14-
```bash
15-
kty users grant <cluster-role> <email-address>
16-
```
66+
This command runs a `SelfSubjectAccessReview` against your cluster. If you want
67+
to use `kubectl` instead, you can run:
1768

18-
1. Start the server.
69+
```bash
70+
kubectl auth can-i list pods --as me@example.com
71+
```
1972

20-
```bash
21-
kty --serve
22-
```
73+
## Install on your cluster
2374

24-
1. SSH into your cluster!
75+
While it isn't required that you run `kty` on your cluster, it takes care of the
76+
dependencies. To install the server and associated configuration such as
77+
`ClusterRole` and `Service` resources, run:
2578

26-
```bash
27-
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 2222 me@localhost
28-
```
79+
```bash
80+
kubectl create ns kty && \
81+
kty resources install -n kty
82+
```
2983

30-
From this point, here's a few suggestions for things to check out:
84+
<Callout type="info">
3185

32-
- Start a new pod. It'll show up in the dashboard immediately!
86+
You can pass `--dry-run` to see what's happening or pass the output to
87+
`kubectl apply -f -` yourself. If you'd like to install using a different
88+
method, such as helm, see the [installation](/installation) instructions.
89+
90+
To clean these resources up, you can run `kty resources delete -n kty`.
91+
92+
</Callout>
93+
94+
Verify that this is up and running successfully by checking that the pod has
95+
started up:
96+
97+
```bash
98+
kubectl -n kty rollout status deploy server
99+
```
100+
101+
Once the pod has started up, you'll want to make sure there's an IP address that
102+
can be reached:
103+
104+
```bash
105+
kubectl -n kty get service server --output=jsonpath='{.status.loadBalancer.ingress[0].ip}'
106+
```
107+
108+
<Callout type="warning">
109+
110+
If the load balancer isn't getting a public IP address, there's other ways to
111+
connect to the server. On way is to port forward using `kubectl`:
112+
113+
```bash
114+
kubectl -n kty port-forward service/server 2222:2222
115+
```
116+
117+
This is not something you'd want to do in production, but it's a quick way to
118+
see what you can do with kty.
119+
120+
</Callout>
121+
122+
## Test it out
123+
124+
```bash
125+
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 2222 me@localhost
126+
```
127+
128+
## Next Steps
33129

34130
- Exec into a pod. Select the pod you want and go to the `Shell` tab. You'll be
35131
able to pick the command to exec and then be shell'd into the pod directly.
36132

37-
- Follow the logs. Logs for all containers in a pod are streamed to the `Logs`
38-
tab when you've selected a pod from the main list.
39-
40133
- `scp` some files out of a container:
41134

42135
```bash
43136
scp -P 2222 me@localhost:/default/my-pod/etc/hosts /tmp
44137
```
45138

46-
- Use your own [OpenID provider](/installation#bring-your-own-provider).
139+
- Check out [usage](/usage) for more information on everything that you can do.
47140

48-
Note: you'll want to install on-cluster to use the tunnelling functionality.
49-
Check out the [helm](/installation/helm) docs for a quick way to do that.
141+
- You can [bring your own provider](/installation#bring-your-own-provider) if
142+
the default provider don't work for you. This would be a great way to
143+
configure groups or use other types of logins if your organization uses
144+
something other than Google or Github.
50145

51146
[cli-download]: https://github.com/grampelberg/kty/releases
52147
[k3d]: https://k3d.io

kustomize/kustomization.yaml

-14
This file was deleted.

resources/account.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: kty-server
5+
labels:
6+
app.kubernetes.io/component: server
7+
app.kubernetes.io/name: kty-server
8+
app.kubernetes.io/part-of: kty
9+
app.kubernetes.io/managed-by: kty-cli

resources/binding.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: kty-server
5+
labels:
6+
app.kubernetes.io/component: server
7+
app.kubernetes.io/name: kty-server
8+
app.kubernetes.io/part-of: kty
9+
app.kubernetes.io/managed-by: kty-cli
10+
subjects:
11+
- kind: ServiceAccount
12+
name: kty-server
13+
namespace: kty
14+
roleRef:
15+
kind: ClusterRole
16+
name: kty-server
17+
apiGroup: rbac.authorization.k8s.io

resources/key.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: kty-server
5+
labels:
6+
app.kubernetes.io/component: server
7+
app.kubernetes.io/name: server
8+
app.kubernetes.io/part-of: kty
9+
app.kubernetes.io/managed-by: kty-cli
10+
data:
11+
placeholder: ''
+3-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
---
21
apiVersion: rbac.authorization.k8s.io/v1
32
kind: ClusterRole
43
metadata:
54
name: kty-server
65
labels:
76
app.kubernetes.io/component: server
7+
app.kubernetes.io/name: kty-server
8+
app.kubernetes.io/part-of: kty
9+
app.kubernetes.io/managed-by: kty-cli
810
rules:
911
- apiGroups: ['']
1012
resources:
@@ -27,17 +29,3 @@ rules:
2729
- patch
2830
resourceNames:
2931
- keys.kty.dev
30-
---
31-
apiVersion: rbac.authorization.k8s.io/v1
32-
kind: ClusterRoleBinding
33-
metadata:
34-
name: kty-server
35-
labels:
36-
app.kubernetes.io/component: server
37-
subjects:
38-
- kind: ServiceAccount
39-
name: kty-server
40-
roleRef:
41-
kind: ClusterRole
42-
name: kty-server
43-
apiGroup: rbac.authorization.k8s.io

0 commit comments

Comments
 (0)