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/

Categories
Uncategorized

Install a GUI for Docker Portainer

Since we started covering docker content about a month ago I’ve had several emails from viewers asking about graphical user interfaces rather than having to use a command line. This is the write up for you if you rather use a GUI, web interface then the command line.

Portainer is a web-based user interface that allows you to manage and monitor your Docker containers, images, networks, and volumes. It provides an easy-to-use and intuitive interface for managing your Docker environment, without requiring any knowledge of Docker’s command line interface. Some of the features of Portainer include:

  • Container management: Portainer allows you to start, stop, and remove Docker containers, as well as view logs and access container details.
  • Image management: You can manage Docker images with Portainer, including pulling and pushing images to and from Docker registries.
  • Network management: Portainer allows you to create and manage Docker networks, including inspecting network details and adding and removing containers from networks.
  • Volume management: With Portainer, you can create, manage, and inspect Docker volumes.
  • User management: You can manage user access to Portainer and Docker resources with Portainer’s RBAC (Role-Based Access Control) system.
  • Dashboard: Portainer provides a customizable dashboard that gives you an overview of your Docker environment, including container and resource usage.

Overall, Portainer simplifies the management of Docker containers and makes it easier for users of all skill levels to work with Docker.

This wright up is going to assume that you already have docker and docker compose installed on your system and will be using Ubuntu 22.04

To start the install of Portainer after you have installed Docker and docker-compose you are going to need to make a folder and 2 files one to launch Portainer and the other to start it when your system starts up / reboots.

The first one I am going to do is make the folder I will be calling my folder portainer and I will be storing it at /home/[username]

mkdir portainer

the first file that we will be making and storing in the portainer folder is the docker-compose.yaml file this is what you will use to start portainer on your docker server.

sudo nano docker-compose.yaml
version: "3"

services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: always
    ports:
      - "9000:9000"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "portainer_data:/data"

volumes:
  portainer_data:

in this file we tell docker to use the latest portainer image, open port 9000 to port 9000 into CT, and map two folders to the portainer image from the host OS.

This file by it’s self will be enough to start and use portainer but it will not be much go to you if your server restart and then you go to use it. so lets make portainer start as a service by making a second file.

sudo nano /etc/systemd/system/portainer.service 
[Unit]
Description=Portainer Container
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f [your path]/portainer/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f [your path]/portainer/docker-compose.yml down

[Install]
WantedBy=multi-user.target

This file tells Ubuntu to start and stop portainer just like it would other services on the server as it starts and shuts down.

now it is time to start the image

sudo systemctl enable portainer.service
sudo systemctl start portainer.service
Categories
Uncategorized

Pi Day special React.js Dev Server in Docker on Raspberry pi

Happy Pi Day! In honor of this special occasion, we’re excited to share a tutorial on how to set up a React.js development server in Docker on a Raspberry Pi. With the rise of containerization, Docker has become an increasingly popular tool for managing and deploying web applications, and Raspberry Pi is a versatile and affordable platform that’s perfect for experimenting with new technologies.

In this tutorial, we’ll walk you through the steps of setting up a React.js development environment in Docker on your Raspberry Pi. We’ll cover everything from updating and upgrading your system to installing the necessary dependencies and running a Docker container with your React.js app. Along the way, we’ll provide helpful tips and commands for managing your Docker containers and images.

The first thing that you are going to have to do is use the raspberry pi imageing tool to download and install raspberry pi os on a sd card.

You can now log into your pi or use ssh depending on your setup I will be using ssh today.

the first thing we are going to do is update the system

sudo apt update && sudo apt upgrade -y

now that the system is up to date lets start by installing docker

curl -sSL https://get.docker.com | sh

now that docker is installed lets stop from having to use sudo every time we enter the docker command we do this by adding the user to the docker group with the command

sudo adduser [user name] docker

now we do not have to type sudo every time we run a docker command

lets see if docker is installed

docker -v

the next piece of software that we will need is called docker-compose but to install that we are going to need some other software to so of this might already be installed for you depending on the OS image that you used

sudo apt install libffi-dev libssl-dev
sudo apt install python3-dev
sudo apt install -y python3 python3-pip

now we will use pip to install docker compose

sudo pip3 install docker-compose

lets check to see if docker-compose install crackly with the command

docker-compose -v

with docker and docker-compose installed on your raspberry pi lets get started with the project by making a folder

mkdir Reactjs-Docker

and use cd to move into the folder

cd Reactjs-Docker

now we are going to use nano to make a file called Dockerfile with no explanation here is the contents of the file

sudo nano Dockerfile
# Use an official Node.js runtime as a parent image
FROM node:14-alpine

# Set the working directory to /app
WORKDIR /app

# Install dependencies
RUN npm install

# Build the React app
RUN npx create-react-app my-app

# Set the working directory
WORKDIR /app/my-app

# Set the command to start the server
CMD ["npm", "start"]

in this file we are telling docker that we would like to use the base image of node that has a tag of 14-alpine

then we set the work directory to /app and install npm with npm installed we make a new react app called my-app the next line sets a new working directory to /app/my-app the last line starts the server.

now that docker know how to build the image we can run the command

docker build -t [image name] .

this will make the image that we will use in a bit to setup the dev server.

now lets start the image to test and see of it works

docker run -d -p 3000:3000 [image name]

and run the command docker ps to see more info on the ct like the name.

docker ps

if you dont see a output from docker ps try removing the -d to see and output from the image.

now lets copy so files from the image so that we can start up the image and see a test page.

docker cp [CONTAINER ID]:/app/my-app /home/ve/Reactjs-Docker/my-app

now that we have the files from the image we can stop it with

docker stop [CONTAINER NAME]

now it is time to use docker-compose be we will need a docker-compose.yaml file to do this remember this is a .yaml file so spacing is big!

sudo nano docker-compose.yaml
version: '3'
services:

  [CT-name]:
      image: [image name]
      ports:
        - "3000:3000"
      volumes:
        - ./my-app/my-app:/app/my-app

in this file we tell docker-compose that we are using v3 script and that we are making a service then the name of the container that we would like to make. the next line is a call for the image that we made in the steps before. then we tell it that we would like to map port 3000 of the server to port 3000 of the CT so we will talk to the docker CT at server ip addres:3000 with a web browser. The last line is maybe the most impotent tho the last line maps the folder my-app that we places all the files in to the ct folder my-app this is what will let us easily develop in react.js with this server.

now that all of this is done it is finally time to start the server up on your raspberry pi with the command

docker-compose up -d

then go to your web browser

http://[raspberry pi ip address]:3000