Skip to content

Commit

Permalink
release v1.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Md Imran <[email protected]>
  • Loading branch information
narmidm committed Oct 19, 2024
1 parent ab91caa commit 9f355d2
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 40 deletions.
26 changes: 20 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ RUN apk add --no-cache \
helm \
socat \
ncdu \
bash
bash \
ca-certificates \
conntrack-tools \
ethtool \
iptables \
less \
mtr \
openssh-client \
psmisc \
tcptraceroute \
ngrep \
yq

# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
Expand All @@ -63,15 +74,18 @@ RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/s
RUN curl -L -o /usr/local/bin/stern https://github.com/stern/stern/releases/download/v1.22.0/stern_linux_amd64 && \
chmod +x /usr/local/bin/stern

# Install k9s
RUN curl -L -o /usr/local/bin/k9s https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz && \
tar -xz -C /usr/local/bin/ -f /usr/local/bin/k9s && chmod +x /usr/local/bin/k9s
# Install k9s (Fixed Download and Extraction)
RUN curl -L -o /tmp/k9s_Linux_amd64.tar.gz https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz && \
tar -xz -C /usr/local/bin/ -f /tmp/k9s_Linux_amd64.tar.gz k9s && chmod +x /usr/local/bin/k9s && rm /tmp/k9s_Linux_amd64.tar.gz

# Install mc (MinIO Client)
RUN curl -O https://dl.min.io/client/mc/release/linux-amd64/mc && \
chmod +x mc && \
mv mc /usr/local/bin/

# Set the working directory
WORKDIR /root/

# Copy the Golang executable from the builder stage
COPY --from=builder /app/k8stoolbox /usr/local/bin/k8stoolbox

Expand Down Expand Up @@ -100,5 +114,5 @@ RUN ln -s /usr/local/bin/scripts/aggregate_logs.sh /usr/local/bin/aggregate_logs
# Clean up unnecessary files to keep the image small
RUN rm -rf /var/cache/apk/*

# Set the default command to an interactive shell for general debugging and troubleshooting
CMD ["/bin/sh"]
# Run the Go application
CMD ["tail", "-f", "/dev/null"]
47 changes: 17 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"log"
"os"
"path/filepath"
)

var clientset *kubernetes.Clientset
var config *rest.Config

func main() {
var err error
config, err = rest.InClusterConfig()
if err != nil {
panic(err.Error())
}
// creates the clientset
clientset, err = kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}

// Define flags for CLI commands
healthCheckCmd := flag.NewFlagSet("healthcheck", flag.ExitOnError)
namespace := healthCheckCmd.String("namespace", "default", "Namespace to check pod health")
Expand Down Expand Up @@ -56,21 +69,6 @@ func main() {

// performHealthCheck performs a health check on all pods in the specified namespace
func performHealthCheck(namespace string) {
// Load Kubernetes client configuration
kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config")
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
fmt.Printf("Error loading kubeconfig: %v\n", err)
os.Exit(1)
}

// Create Kubernetes clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
fmt.Printf("Error creating Kubernetes client: %v\n", err)
os.Exit(1)
}

// Get all pods in the specified namespace
pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
Expand All @@ -92,19 +90,8 @@ func performHealthCheck(namespace string) {

// testPodConnectivity tests network connectivity from a pod to a specified target
func testPodConnectivity(namespace, podName, target string) {
// Load Kubernetes client configuration
kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config")
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
fmt.Printf("Error loading kubeconfig: %v\n", err)
os.Exit(1)
}

// Create Kubernetes clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
fmt.Printf("Error creating Kubernetes client: %v\n", err)
os.Exit(1)
if clientset == nil || config == nil {
log.Fatalf("Error: Kubernetes clientset or config is not initialized")
}

// Set up the exec request
Expand Down
43 changes: 41 additions & 2 deletions manifests/debug-daemon.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
# K8sToolbox DaemonSet Manifest
# K8sToolbox DaemonSet Manifest with ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: k8stoolbox-cluster-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: k8stoolbox-cluster-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand All @@ -15,11 +53,12 @@ spec:
labels:
app: k8stoolbox
spec:
serviceAccountName: k8stoolbox-cluster-admin
containers:
- name: k8stoolbox
image: narmidm/k8stoolbox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh"]
command: ["tail", "-f", "/dev/null"]
resources:
requests:
memory: "64Mi"
Expand Down
24 changes: 22 additions & 2 deletions manifests/debug-pod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# K8sToolbox Debug Pod Manifest
# K8sToolbox Debug Pod Manifest with ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: k8stoolbox-cluster-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: k8stoolbox-cluster-admin
namespace: default
---
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -7,11 +26,12 @@ metadata:
labels:
app: k8stoolbox
spec:
serviceAccountName: k8stoolbox-cluster-admin
containers:
- name: k8stoolbox
image: narmidm/k8stoolbox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh"]
command: ["tail", "-f", "/dev/null"]
resources:
requests:
memory: "64Mi"
Expand Down

0 comments on commit 9f355d2

Please sign in to comment.