Categories
Uncategorized

Commands For Installing K3s and kubectl Console on Ubuntu with video

install k3s

curl -sfL https://get.k3s.io | sh -
sudo systemctl status k3s.service
sudo kubectl cluster-info
sudo kubectl get node
sudo cat /etc/rancher/k3s/k3s.yaml

install on linux console

snap install kubectl --classic
sudo kubectl version --output=yaml
mkdir -p ~/.kube
touch ~/.kube/config
chown $(id -u):$(id -g) ~/.kube/config
chmod 600 ~/.kube/config

copy /etc/rancher/k3s/k3s.yaml to ~/.kube/config

kubectl version --output=yaml
kubectl cluster-info
kubectl get node

running first ct

mkdir -p ~/k8s/whoami
cat << EOF > ~/k8s/whoami/whoami.yml
---
apiVersion: v1
kind: Namespace
metadata:
  name: k3s-test
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami-deploy
  namespace: k3s-test
  labels:
    app: whoami
spec:
  replicas: 3
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
        - name: whoami
          image: traefik/whoami:v1.8.0
          ports:
            - name: whoami
              containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: whoami-svc
  namespace: k3s-test
  labels:
    service: whoami
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      protocol: TCP
  selector:
    app: whoami
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-ingress
  namespace: k3s-test
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
  rules:
    - http:
        paths:
          - path: /test
            pathType: Prefix
            backend:
              service:
                name: whoami-svc
                port:
                  number: 80
EOF
kubectl get namespaces
kubectl get pods --namespace k3s-test -o wide
kubectl get deployments --namespace k3s-test -o wide
kubectl get services --namespace k3s-test -o wide
kubectl get ingress --namespace k3s-test -o wide

try web browser

kubectl delete -f ~/k8s/whoami/whoami.yml

Thanks to

https://loganmarchione.com/2022/03/k3s-single-node-cluster-for-noobs/

https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/

Leave a Reply