Command_K8

  

  • Add new context in k8 config

Config file path: cmd>> vi ~/.kube/config

Add context in config file,
Here namespace you need to keep same name and name you can configure whatever you want.
- context:
        cluster: kubernetes-production
        namespace: test
        user: kubernetes
name: test-production
kubectl config use-context test-production
kubectl get pods -o wide

Config:

Kubectl edit rolebinding admin

kubectl get all
Kubectl get rs
kubectl get events
kubectl get services
kubectl get deploy


kubectl describe pod <pod-name>
Kubectl describe quota
kubectl describe svc <name>

kubectl scale --replicas=10 rollouts/ekl-deeson
kubectl scale --replicas=10 rollouts/ekl-deeson -n ekl-deeson 

kubectl cp a2d2-855f79d545-5gtrl:/var/log/a2d2/* . -c a2d2 [pod to local] 

kubectl cp /Users/Desktop/Calcutta a2d2-7966c7487c-kjwrg:/usr/Asia/Calcutta -c a2d2 [local to pod]

Command:

kubectl config view
kubectl config get-contexts
kubectl config use-context a2d2-production
kubectl get pods -o wide 

kubectl delete pod a2d2-5c8544668b-ghkz4
kubectl delete pod a2d2-5c8544668b-ghkz4 —force
kubectl delete -n a2d2 pod a2d2-765768b96b-wfbq7


kubectl exec -it a2d2-64b6f4799-wcfjp bash
kubectl exec -it a2d2-7b6f99d49c-cr7k2 -c a2d2 -- bash

Logs:

kubectl logs a2d2-64b6f4799-wcfjp a2d2 -f --tail=100 | grep "message"
kubectl logs a2d2-665b5b87f-kv6mc a2d2 -f --tail=1000| grep -v "message"


kubectl logs a2d2-689444564c-mmd9t a2d2 --since=2m
kubectl logs a2d2-64cb586df6-mmd9t -f --since=15m | grep -C 10 ERROR

kubectl logs a2d2-8664d4845d-wghtn -c a2d2 -f 
kubectl logs -f -l app=a2d2 -c a2d2 --max-log-requests 10 --tail=100

tps@a2d2-c55945dc-hrcch:/var/log/a2d2$ zgrep "Code: 5" *


tail -f FILENAME
tail -100f test.log |  grep "/shipments " test.log

grep "/shipments “ test.log

>> Locally hit from postman

Take pod ip: 10.12.113.114
ssh -N -L localhost:4338:10.12.113.114:36050 global.jumphost.in
Postman hit: http://localhost:4338/api 


sample docker file

FROM jfrog.internal.com/fk-base-images/adoptopenjdk/jdk:8u322-debian11.3-slim-20220527
RUN mkdir /etc/fk-a2b2 \
 && mkdir /etc/fk-sc-mq \
 && mkdir -p /var/log/golu/supply-chain/fk-a2b2 \
 && echo "deb [trusted=yes] http://packages/repos/newrelic/19 /" > /etc/apt/sources.list.d/newrelic.list \
 && apt-get update \
 && apt-get install -y curl procps vim-tiny nr-java-apm-agent \
 && apt-get clean \
 && echo "Asia/Kolkata" > /etc/timezone
COPY target/ekl-a2b2-*-SNAPSHOT.jar /usr/share/fk-a2b2/a2b2.jar
ENV MEM_OPTS="-Xmx2048m -Xms1024m"
ENV GC_OPTS="-XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:InitiatingHeapOccupancyPercent=25 -XX:MaxGCPauseMillis=100 -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=75 -XX:ParallelGCThreads=12 -XX:ConcGCThreads=4 -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/var/log/golu/supply-chain/fk-a2b2/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=3 -XX:GCLogFileSize=128K" \
 JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=27754 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
 LOG4J_OPTS="-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -DAsyncLogger.WaitStrategy=\"Yield\"" \
 JFR_OPTS="-XX:+UnlockCommercialFeatures -XX:+FlightRecorder" \
 DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n"
ENV NR_JAVA_OPTS="-javaagent:/opt/newrelic/newrelic-agent.jar"
ENV JVM_OPTS="$JFR_OPTS $LOG4J_OPTS $GC_OPTS $JMX_OPTS $NR_JAVA_OPTS $DEBUG_OPTS"
ARG user=a2b2User
ARG group=a2b2Group
ARG uid=8888
ARG gid=8888
RUN groupadd -g ${gid} ${group} \
 && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user} \
 && chown -R ${user}:${group} /usr/share/fk-a2b2 /etc/fk-a2b2/ /var/log/golu/supply-chain/fk-a2b2 /etc/fk-sc-mq
USER ${user}
WORKDIR /etc/fk-a2b2/
EXPOSE 36050
ENTRYPOINT exec java $JVM_OPTS $MEM_OPTS -jar /usr/share/fk-a2b2/a2b2.jar server "a2b2.yml"

Create new cluster:
my-services

2. create service account:: kubectl create sa my-services-sa -n my-services
3. create rolebinding
kubectl create rolebinding my-services-rolebinding \
--namespace my-services --clusterrole=admin \
--serviceaccount=my-services:my-services-sa
4. desscribe service account:: kubectl describe sa my-services
5. create token for cluster in flow:: kubectl describe secrets my-services-sa-token-wmn5w
6. change token to base64
echo -n "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikw1QmhwcVlyaEhWWE5hS0FDbmlTekdkRE9Md0JBcTJ0TGl0bHdGczBoMm8ifQ.eyJpc3MiOiJrdWJlcm5l" | base64