Monday, September 26, 2022

How to check in linux which ports are used?

 Use one of the following commands to check

sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here

Thursday, September 22, 2022

headless in IT context

The word headless often used with many other IT terms such as service, system, device. Sometimes it is a bit confusing, what it really means, if it has been used as faceless, it may have been a lot easier for people to understand. So, basically when word headless is used with many other IT terms, it really means that there is no user interface associated with, for example, if it is headless service, that means, the service is more like a API service, a Rest service, backend service etc. It is running somewhere, you actually do not see unless one uses some user interface such as a client software to request access to it. It is similar used as headless system, such as a linux system running without even a command line user interface. Another example is headless IoT device, usb memory stick, drone, etc. Wireless network connected headless devices is another example.


Friday, August 26, 2022

Istio agent iptable command

When Istio workload starts up, the first thing is to start the proxy-init container which is the InitContainer for a workload. This proxy-init container uses istio/proxy2 which execute iptable command of the istio-agent.


What the iptable command actually does is to do the following which captured in its log. For example, the following is the helloworld workload with istio sidecar injection. Both app port and service port are 5000. The initContainer is named istio-init.


Create new Istio chains

-N ISTIO_INBOUND
-N ISTIO_REDIRECT
-N ISTIO_IN_REDIRECT
-N ISTIO_OUTPUT

Add routing rules.
-A ISTIO_INBOUND -p tcp --dport 15008 -j RETURN
-A ISTIO_REDIRECT -p tcp -j REDIRECT --to-ports 15001
-A ISTIO_IN_REDIRECT -p tcp -j REDIRECT --to-ports 15006
-A PREROUTING -p tcp -j ISTIO_INBOUND
-A ISTIO_INBOUND -p tcp --dport 15090 -j RETURN
-A ISTIO_INBOUND -p tcp --dport 15021 -j RETURN
-A ISTIO_INBOUND -p tcp --dport 15020 -j RETURN
-A ISTIO_INBOUND -p tcp -j ISTIO_IN_REDIRECT
-A OUTPUT -p tcp -j ISTIO_OUTPUT
-A ISTIO_OUTPUT -o lo -s 127.0.0.6/32 -j RETURN
-A ISTIO_OUTPUT -o lo ! -d 127.0.0.1/32 -m owner --uid-owner 1337 -j ISTIO_IN_REDIRECT
-A ISTIO_OUTPUT -o lo -m owner ! --uid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -m owner --uid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -o lo ! -d 127.0.0.1/32 -m owner --gid-owner 1337 -j ISTIO_IN_REDIRECT
-A ISTIO_OUTPUT -o lo -m owner ! --gid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -m owner --gid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -d 127.0.0.1/32 -j RETURN
-A ISTIO_OUTPUT -j ISTIO_REDIRECT

Monday, July 25, 2022

Istio useful commands

Setup multiple primary and multiple cluster network.

1. istioctl proxy-config endpoints

istioctl pc endpoints --context kind-cluster1  helloworld-v1-7b8f6db47c-rw88t.sample


2. istioctl dashboard envoy

 istioctl dashboard envoy helloworld-v2-77f7f4cc45-mrgwv.sample --address=192.168.56.32 --browser=false


3. istioctl dashboard controlz (only against istiod instance)

istioctl dashboard controlz  istiod-7849bf7c66-6prbj.istio-system --address=192.168.56.32 --browser=false


Force ubuntu system to sync date and time for a system

just run the following commands to force the system to sync the date and time. 

sudo timedatectl set-ntp true
sudo timedatectl set-ntp false
sudo timedatectl set-ntp true
Running these 3 commands, then the system will sync your date and time
the correct date and time. 


Ubuntu virtualbox virtual machines can have the system date and time be out sync when the host machine goes on sleep, once the host machine is wake up, the virtual machine's time can be off quite a bit. Run the above command to bring the system date and time to the current.

Friday, July 8, 2022

downstream and upstream in computer networking

In case of Server-Client paradigm, the terms “Upstream” and “Downstream” are used only with respect to the server. So basically "Upstream" means data coming to server (or me), "Downstream" means data leaving server (or me).

In a network, the terms upstream and downstream are used with respect to the position of the devices.

For instance, the flow of packets between three kinds of switches: access, distribution and core switches. The flow of packets from the access switches to the distribution and core switches is upstream. Whereas, from core level switches to access switches, the flow of packets is downstream traffic. With respect to distribution switches, the flow of packets to core switches is upstream traffic while the flow to access switches is downstream traffic.  

So to make this a bit easier, for a giving device (app, or program), if data is coming to the device, then it is upstream. if data is leaving the device, then it is downstream.

 

Thursday, May 19, 2022

How to run Istiod in debug mode outside of k8s

 Debugging a kubernetes controller is a bit hard by keeping adding fmt.Println statement in your code. Using VS code to run the controller main.go in debug mode outside of the kubernetes cluster seems to be a doable solution.

This article will talk about how to do this using istiod as an example.

1. Load your Istio project into VS code.

2. Setup a debug profile (configuration) as follows:

{
"name": "Controller",
"type": "go",
"request": "launch",
"mode": "debug",
"env": {
"REVISION": "default",
"JWT_POLICY": "third-party-jwt",
"PILOT_CERT_PROVIDER": "istiod",
"POD_NAME": "tongli",
"POD_NAMESPACE": "istio-system",
"SERVICE_ACCOUNT": "",
"KUBECONFIG": "/home/ubuntu/.kube/config",
"ENABLE_LEGACY_FSGROUP_INJECTION": "false",
"ROOT_CA_DIR": "/tmp/work",
"PILOT_TRACE_SAMPLING": "1",
"PILOT_ENABLE_PROTOCOL_SNIFFING_FOR_OUTBOUND": "true",
"PILOT_ENABLE_PROTOCOL_SNIFFING_FOR_INBOUND": "true",
"ISTIOD_ADDR": "istiod.istio-system.svc:15012",
"PILOT_ENABLE_ANALYSIS": "false",
"CLUSTER_ID": "tongli"
},
"args": [
"discovery",
"--monitoringAddr=:15014",
"--log_output_level=default:info",
"--domain=cluster.local",
"--keepaliveMaxServerConnectionAge=30m"
],
"program": "${workspaceFolder}/pilot/cmd/pilot-discovery/main.go"
},

3. Now create a kubernetes cluster and make sure that kube config file is in the right place, corresponding to some of the environment variables.

4. For Istiod to work, you will also need to setup variable like ROOT_CA_DIR to a directory which VS Code has access to.

5. Now create a namespace in the kubernetes cluster called istio-system, which Istiod will need to start up.

6. Set up few break points in your code that your controller will run. Then start debug by choose the Controller profile in VScode. If now you send some requests against your controller, then it should break at one of the break point.


There should be ca certs created before hand in multi cluster deployment case so that istiod wont create its own secrets. The best way probably is to create the istio-ca-secret in istio-system namespace (or whatever the namespace it runs in) before start up the debugging process.