Get kubernetes nodes:
k3os-3249 [~]$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3os-22710 Ready <none> 10m v1.14.1-k3s.4
k3os-3249 Ready <none> 17h v1.14.1-k3s.4
Get cluster info:
k3os-3249 [~]$ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
CoreDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Creating a service for an application running in two pods:
k3os-3249 [ ~ ]$ kubectl run --generator=run-pod/v1 hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080
deployment.apps/hello-world created
Display information about the Deployment:
k3os-3249 [/kubernetes]$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/hello-world-68ff65cf7-bxg6j 0/1 ContainerCreating 0 29s
pod/hello-world-68ff65cf7-ptz9p 0/1 ContainerCreating 0 29s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 17h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/hello-world 0/2 2 0 29s
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-world-68ff65cf7 2 2 0 29s
k3os-3249 [/kubernetes]$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/hello-world-68ff65cf7-bxg6j 1/1 Running 0 20m
pod/hello-world-68ff65cf7-ptz9p 1/1 Running 0 20m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 18h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/hello-world 2/2 2 2 20m
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-world-68ff65cf7 2 2 2 20m
Display information about the Deployment:
k3os-3249 [/kubernetes]$ kubectl get deployments hello-world
NAME READY UP-TO-DATE AVAILABLE AGE
hello-world 2/2 2 2 21m
k3os-3249 [/kubernetes]$ kubectl describe deployments hello-world
Name: hello-world
Namespace: default
CreationTimestamp: Mon, 10 Jun 2019 08:57:12 +0000
Labels: run=load-balancer-example
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=load-balancer-example
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=load-balancer-example
Containers:
hello-world:
Image: gcr.io/google-samples/node-hello:1.0
Port: 8080/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: hello-world-68ff65cf7 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 21m deployment-controller Scaled up replica set hello-world-68ff65cf7 to 2
Display information about your ReplicaSet objects:
k3os-3249 [/kubernetes]$ kubectl get replicasets
NAME DESIRED CURRENT READY AGE
hello-world-68ff65cf7 2 2 2 23m
k3os-3249 [~]$ kubectl describe replicasets
Name: hello-world-68ff65cf7
Namespace: default
Selector: pod-template-hash=68ff65cf7,run=load-balancer-example
Labels: pod-template-hash=68ff65cf7
run=load-balancer-example
Annotations: deployment.kubernetes.io/desired-replicas: 2
deployment.kubernetes.io/max-replicas: 3
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/hello-world
Replicas: 2 current / 2 desired
Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: pod-template-hash=68ff65cf7
run=load-balancer-example
Containers:
hello-world:
Image: gcr.io/google-samples/node-hello:1.0
Port: 8080/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 23m replicaset-controller Created pod: hello-world-68ff65cf7-ptz9p
Normal SuccessfulCreate 23m replicaset-controller Created pod: hello-world-68ff65cf7-bxg6j
Create a Service object that exposes the deployment:
k3os-3249 [~]$ kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
service/my-service exposed
Display information about the Service:
k3os-3249 [~]$ kubectl get services my-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service LoadBalancer 10.43.231.148 192.168.17.178,192.168.17.179 8080:30518/TCP 77s
Display detailed information about the Service:
k3os-3249 [~]$ kubectl describe services my-service
Name: my-service
Namespace: default
Labels: run=load-balancer-example
Annotations: <none>
Selector: run=load-balancer-example
Type: LoadBalancer
IP: 10.43.231.148
LoadBalancer Ingress: 192.168.17.178, 192.168.17.179
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 30518/TCP
Endpoints: 10.42.0.10:8080,10.42.1.6:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Display information about the Pods:
k3os-3249 [~]$ kubectl get pods --output=wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hello-world-68ff65cf7-bxg6j 1/1 Running 0 28m 10.42.0.10 k3os-3249 <none> <none>
hello-world-68ff65cf7-ptz9p 1/1 Running 0 28m 10.42.1.6 k3os-22710 <none> <none>
svclb-my-service-flw2l 1/1 Running 0 3m9s 10.42.1.7 k3os-22710 <none> <none>
svclb-my-service-hlqpq 1/1 Running 0 3m9s 10.42.0.11 k3os-3249 <none> <none>
Use the external IP address (LoadBalancer Ingress) to access the Hello World application:
k3os-3249 [~]$ curl http://192.168.17.179:8080
Use the Cluster IP address to access the Hello World application inside machines:
k3os-3249 [~]$ curl http://10.43.231.148:8080
Hello Kubernetes!
Cleaning up
To delete the Service:
k3os-3249 [~]$ kubectl delete services my-service
To delete the Deployment, the ReplicaSet, and the Pods that are running the Hello World application:
k3os-3249 [~]$ kubectl delete deployment hello-world
---------------------------------------------------------------------------------------------------------------
Good Luck
https://www.linkedin.com/in/ahmedms/
Comments
Post a Comment