apiVersion: v1
kind: Pod
metadata:
name: myjavapod
namespace: default
# or your namespace
labels:
app: nginx-v1
spec:
containers:
- name: myjavapod
image: kubetrain/springboot-demo-jayaram:v0.1
imagePullPolicy: Always
restartPolicy: Never
# kubectl apply -f thisfile.yaml
$kubectl logs -n default myjavapod
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2021-12-03 01:37:00.130 INFO 1 --- [ main] io.kubetrain.tutorial.AppStart : Starting AppStart v1.0 on myjavapod with PID 1 (/opt/app/app.jar started by root in /opt/app)
2021-12-03 01:37:00.134 INFO 1 --- [ main] io.kubetrain.tutorial.AppStart : No active profile set, falling back to default profiles: default
2021-12-03 01:37:01.419 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2021-12-03 01:37:01.457 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-12-03 01:37:01.458 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2021-12-03 01:37:01.562 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-12-03 01:37:01.562 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1362 ms
2021-12-03 01:37:01.837 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-12-03 01:37:02.146 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2021-12-03 01:37:02.149 INFO 1 --- [ main] io.kubetrain.tutorial.AppStart : Started AppStart in 2.608 seconds (JVM running for 3.102)
kubectl exec -it -n default myjavapod -- /bin/sh
/opt/app # pwd
/opt/app
/opt/app # ls
app.jar
/opt/app # top -b -n 1
Mem: 7800132K used, 172676K free, 389020K shrd, 480504K buff, 5454400K cached
CPU: 0% usr 0% sys 0% nic 100% idle 0% io 0% irq 0% sirq
Load average: 0.04 0.09 0.13 2/787 87
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
1 0 root S 3375m 43% 0 0% java -jar app.jar
79 0 root S 1584 0% 1 0% /bin/sh
87 79 root R 1516 0% 0 0% top -b -n 1
apiVersion: v1
kind: Pod
metadata:
name: myjavapod
namespace: default
uid: fc6d466f-b67d-4848-88af-d3d542b1a9d1
resourceVersion: '32768031'
creationTimestamp: '2021-12-03T01:36:56Z'
labels:
app: nginx-v1
status:
phase: Running
conditions:
- type: Initialized
status: 'True'
lastProbeTime: null
lastTransitionTime: '2021-12-03T01:36:56Z'
- type: Ready
status: 'True'
lastProbeTime: null
lastTransitionTime: '2021-12-03T01:37:00Z'
- type: ContainersReady
status: 'True'
lastProbeTime: null
lastTransitionTime: '2021-12-03T01:37:00Z'
- type: PodScheduled
status: 'True'
lastProbeTime: null
lastTransitionTime: '2021-12-03T01:36:56Z'
hostIP: 10.190.227.112
podIP: 172.31.7.29
podIPs:
- ip: 172.31.7.29
startTime: '2021-12-03T01:36:56Z'
containerStatuses:
- name: myjavapod
state:
running:
startedAt: '2021-12-03T01:36:59Z'
lastState: {}
ready: true
restartCount: 0
image: docker.io/kubetrain/springboot-demo-jayaram:v0.1
imageID: >-
docker-pullable://docker.io/kubetrain/springboot-demo-jayaram@sha256:6ce436a7b88dbcd7e2e15c89f97719a4a78b1c42d97107b20e3f476a7aacf155
containerID: >-
docker://419ba98fdf3292086b0ddb08fcd307313b4bec2f4dbd367f5c51b5cbe902f43e
started: true
qosClass: BestEffort
spec:
volumes:
- name: default-token-qfvhl
secret:
secretName: default-token-qfvhl
defaultMode: 420
containers:
- name: myjavapod
image: kubetrain/springboot-demo-jayaram:v0.1
resources: {}
volumeMounts:
- name: default-token-qfvhl
readOnly: true
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Never
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
nodeName: prentxappl15
securityContext: {}
schedulerName: default-scheduler
tolerations:
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 300
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 300
priority: 0
enableServiceLinks: true
preemptionPolicy: PreemptLowerPriority
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-java-deployment
labels:
app: myjava
spec:
replicas: 3
selector:
matchLabels:
app: myjava
template:
metadata:
labels:
app: myjava
spec:
containers:
- name: myjava
image: kubetrain/springboot-demo-jayaram:v0.1
ports:
- containerPort: 8081
$ kubectl.exe get pods
NAME READY STATUS RESTARTS AGE
flask-deployment-7489b9b769-57r9s 1/1 Running 0 23d
flask-deployment-7489b9b769-s5mnj 1/1 Running 0 23d
flask-deployment-7489b9b769-wvb6t 1/1 Running 0 23d
hell2o 1/1 Running 0 27d
hello-world-5c984dfd96-xmff6 1/1 Running 0 29d
my-java-deployment-54564f6d4c-cfps7 1/1 Running 0 2m20s
my-java-deployment-694fc8974b-dpzj8 1/1 Running 0 112s
my-java-deployment-694fc8974b-fznwp 1/1 Running 0 113s
myjavapod 1/1 Running 0 12m
# Edit the replicas value to 2 & save
spec:
replicas: 3
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-java-deployment
namespace: default
uid: e599abd7-bb18-4127-9a20-6db382da5e22
resourceVersion: '32770132'
generation: 2
creationTimestamp: '2021-12-03T01:46:36Z'
labels:
app: myjava
status:
observedGeneration: 2
replicas: 4
updatedReplicas: 2
readyReplicas: 2
availableReplicas: 2
unavailableReplicas: 2
conditions:
- type: Available
status: 'False'
lastUpdateTime: '2021-12-03T01:46:36Z'
lastTransitionTime: '2021-12-03T01:46:36Z'
reason: MinimumReplicasUnavailable
message: Deployment does not have minimum availability.
- type: Progressing
status: 'True'
lastUpdateTime: '2021-12-03T01:47:04Z'
lastTransitionTime: '2021-12-03T01:46:36Z'
reason: ReplicaSetUpdated
message: ReplicaSet "my-java-deployment-694fc8974b" is progressing.
spec:
replicas: 3
selector:
matchLabels:
app: myjava
template:
metadata:
creationTimestamp: null
labels:
app: myjava
spec:
containers:
- name: myjava
image: kubetrain/springboot-demo-jayaram:v0.1
ports:
- containerPort: 8081
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
apiVersion: v1
kind: Service
metadata:
name: myjava-app-service
spec:
selector:
app: myjava
ports:
- protocol: TCP
port: 80
targetPort: 8081
apiVersion: v1
kind: Service
metadata:
name: myjava-app-service
namespace: default
uid: 383eadbf-6b4d-4a8c-8e64-72ecce57be94
resourceVersion: '32771524'
creationTimestamp: '2021-12-03T01:53:39Z'
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"myjava-app-service","namespace":"default"},"spec":{"ports":[{"port":80,"protocol":"TCP","targetPort":8081}],"selector":{"app":"myjava"}}}
status:
loadBalancer: {}
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8081
selector:
app: myjava
clusterIP: 172.30.157.9
clusterIPs:
- 172.30.157.9
type: ClusterIP
sessionAffinity: None
$ kubectl.exe get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
flask ClusterIP 172.30.210.219 <none> 80/TCP 24d
myjava-app-service ClusterIP 172.30.157.9 <none> 80/TCP 79s
$kubectl.exe port-forward service/myjava-app-service 80:80
Forwarding from 127.0.0.1:80 -> 8081
Forwarding from [::1]:80 -> 8081
Handling connection for 80
Handling connection for 80
Open a browser and type 127.0.0.1 or localhost
apiVersion: v1
kind: Service
metadata:
name: my-java-loadbalancer-service
namespace: default
labels:
app: myjava
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8081
selector:
app: myjava
type: LoadBalancer
jayadmin@cloudshell:~ (kubetrain-331123)$ kubectl apply -f java-expose.yaml
service/my-java-loadbalancer-service created
jayadmin@cloudshell:~ (kubetrain-331123)$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-b54m4 ClusterIP 10.56.13.120 <none> 80/TCP 21h
kubernetes ClusterIP 10.56.0.1 <none> 443/TCP 47h
my-java-loadbalancer-service LoadBalancer 10.56.4.188 <pending> 80:31361/TCP 3s
jayadmin@cloudshell:~ (kubetrain-331123)$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-b54m4 ClusterIP 10.56.13.120 <none> 80/TCP 21h
kubernetes ClusterIP 10.56.0.1 <none> 443/TCP 47h
my-java-loadbalancer-service LoadBalancer 10.56.4.188 <pending> 80:31361/TCP 19s
wait for few minutes....
jayadmin@cloudshell:~ (kubetrain-331123)$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-b54m4 ClusterIP 10.56.13.120 <none> 80/TCP 21h
kubernetes ClusterIP 10.56.0.1 <none> 443/TCP 47h
my-java-loadbalancer-service LoadBalancer 10.56.4.188 35.226.106.78 80:31361/TCP 2m6s
jayadmin@cloudshell:~ (kubetrain-331123)$ curl 35.226.106.78
Hello World! Welcome to the World of ...jayadmin@cloudshell:~ (kubetrain-331123)$
Create a Pod:
https://github.com/jayaramcloud/k8sNotes/blob/master/kubetraining/1.pods/just-a-random-pod.yaml
Create the Flask Deployment from the Flask container created earlier:
Create an nginx deployment