Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kubernetes demo with cluster mode on k3s

Install k3s on master node:

curl -sfL https://get.k3s.io | sh -
# get token
cat /var/lib/rancher/k3s/server/node-token

Install k3s on worker nodes as agents:

export K3S_URL="https://10.12.66.37:6443"
export K3S_TOKEN="K10e9fd828806f453fa2293e4fa7e5db51696b29565819b2a5a0320c3b620572b01::node:519d266f594a54673f1f52bef47443e1"
curl -sfL https://get.k3s.io | sh -
# repeat on node 2

See if the nodes checked in:

kubectl get nodes
NAME           STATUS   ROLES    AGE     VERSION
k3s-master     Ready    master   5m36s   v1.15.4-k3s.1
k3s-worker-1   Ready    worker   21s     v1.15.4-k3s.1
k3s-worker-2   Ready    worker   6s      v1.15.4-k3s.1

Deploy the application from https://sysadmins.co.za/develop-build-and-deploy-a-golang-app-to-k3s/

kubectl apply -f k3s-demo.yml
deployment.extensions/k3s-demo created
service/k3s-demo created
ingress.extensions/k3s-demo created

View service:

kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.43.0.1      <none>        443/TCP   8m50s
k3s-demo     ClusterIP   10.43.191.53   <none>        80/TCP    11s

View deployments:

kubectl get deployments
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
k3s-demo   1/1     1            1           28s

View pods:

kubectl get pods -o wide
NAME                       READY   STATUS    RESTARTS   AGE   IP          NODE           NOMINATED NODE   READINESS GATES
k3s-demo-5c864f6cb-wlbg2   1/1     Running   0          66s   10.42.1.3   k3s-worker-1   <none>           <none>

Test application:

> curl k3s-demo.example.org
Hostname: k3s-demo-5c864f6cb-wlbg2

Scale deployment:

kubectl scale --replicas 3 deployments/k3s-demo
deployment.extensions/k3s-demo scaled

View if we are in desired state:

kubectl get pods -o wide
NAME                       READY   STATUS    RESTARTS   AGE    IP          NODE           NOMINATED NODE   READINESS GATES
k3s-demo-5c864f6cb-wlbg2   1/1     Running   0          2m6s   10.42.1.3   k3s-worker-1   <none>           <none>
k3s-demo-5c864f6cb-99h46   1/1     Running   0          27s    10.42.0.6   k3s-master     <none>           <none>
k3s-demo-5c864f6cb-24mnf   1/1     Running   0          27s    10.42.2.3   k3s-worker-2   <none>           <none>

Test application:

> curl k3s-demo.example.org
Hostname: k3s-demo-5c864f6cb-99h46

> curl k3s-demo.example.org
Hostname: k3s-demo-5c864f6cb-wlbg2

> curl k3s-demo.example.org
Hostname: k3s-demo-5c864f6cb-24mnf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.