-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-deployingapplications.sh
145 lines (108 loc) · 5.17 KB
/
6-deployingapplications.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#Imperatively working with your cluster. Run will "generate" a Deployment by default.
#This is pulling a specified image from Google's container registry.
#kubectl run, will convert a pod creation into a "Deployment generation"
#http://kubernetes.io/docs/user-guide/kubectl-conventions/#generators
kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0
#But let's deploy a single pod too...
kubectl run hello-world-pod --image=gcr.io/google-samples/hello-app:1.0 --generator=run-pod/v1
# to deploy our own app run
kubectl run quarkus-greetings --image=docker.io/rakgenius/quarkus-greetings:latest
#Let's follow our pod and deployment status
kubectl get pods
kubectl get deployment
kubectl get pods -o wide
# on master
curl <IP of the pod>:8080/greetings
#Remember, k8s is a container orchestrator and it's starting up containers on Nodes.
#Open a second terminal and ssh into the node that hello-world pod is running on.
ssh root@node<>
sudo docker ps
exit
#Back on the Master, we can pull the logs from the container. Which is going to be anything written to stdout.
#Maybe something went wrong inside our app, and our pod won't start. This is useful for troubleshooting.
kubectl logs hello-world-pod
#Starting a process inside a container inside a pod.
#We can use this to launch any process as long as the executable/binary is in the container.
#Launch a shell into the container. Callout that this is on the *pod* network.
kubectl exec -it hello-world-pod -- /bin/sh
hostname
ip addr
exit
# Expose the service to the outside world using
kubectl port-forward --address 0.0.0.0 deployment/quarkus-greetings 8080:8080
# Create a node port using
kubectl expose deployment quarkus-greetings --port=8080 --type=NodePort
kubectl patch svc quarkus-greetings -p '{"spec":{"externalIPs":["PUBLIC IP"]}}'
#Remember that first kubectl run we executed, it created a Deployment for us.
#Let's look more closely at the deployment
#Deployments are made of ReplicaSets!
kubectl get deployment quarkus-greetings
kubectl get replicaset
kubectl get pods
#Let's take a closer look at our pod.
#Walk through the pods Events...
#Name, Containers, Ports, Conditions, and Events.
#Deployments are made of ReplicaSets!
kubectl describe deployment quarkus-greetings | more
#Let's see what describe can tell us about a deployed Pod.
#Check out the Name, Node, Status, Containers, and events.
kubectl get pods
kubectl describe pods $PASTEPODNAMEHERE | more
#Expose the Deployment as a Serivce.
#This will create a Service for the ReplicaSet behind the Deployment
#We are exposing our serivce on port 80, connecting to an application running on 8080 in our pod.
#Port: Interal Cluster Port, the Service's port. You will point cluster resources here.
#TargetPort: The Pod's Serivce Port, your application. That one we defined when we started the pods.
kubectl expose deployment quarkus-greetings --port=80 --target-port=8080
#Check out the IP: and Port:, that's where we'll access this service.
kubectl get service hello-world
#We can also get that information from using get
kubectl describe service hello-world
#Access the service inside the cluster
curl http://$SERVCIEIP:$PORT
#Access the pod's application directly, useful for troubleshooting.
kubectl get endpoints quarkus-greetings
curl http://$ENDPOINT:$TARGETORT
#Using kubectl to generate yaml or json files of our imperitive configuration.
kubectl get service hello-world -o yaml
kubectl get service hello-world -o json
#Exported resources are stripped of cluster-specific information.
kubectl get service hello-world -o yaml --export > service-hello-world.yaml
kubectl get deployment hello-world -o yaml --export > deployment-hello-world.yaml
ls *.yaml
more service-hello-world.yaml
#We can ask the API for more information about an object
kubectl explain service | more
#And drill down further if needed, includes very good explanation of what's available for that resource
kubectl explain service.spec | more
kubectl explain service.spec.ports
kubectl explain service.spec.ports.targetPort
#Let's remove everything we created imperitively and start over using a declarative model
kubectl delete service hello-world
kubectl delete deployment hello-world
kubectl delete pod hello-world-pod
kubectl get all
#Deploying applications declaratively
#we can use apply to create our resources from yaml.
kubectl apply -f deployment-hello-world.yaml
kubectl apply -f service-hello-world.yaml
#This re-creates everything we created, but in yaml
kubectl get all
#scale up our deployment
vi deployment-hello-world.yaml
Change replicas from 1 to 2
replicas: 2
#update our configuration with apply
kubectl apply -f deployment-hello-world.yaml
#And check the current configuration of our deployment
kubectl get deployment hello-world
#Repeat the curl access to see the load balancing of the HTTP request
kubectl get service hello-world
curl http://$SERVICEIP:PORT
#We can edit the resources "on the fly" with kubectl edit. But this isn't reflected in our yaml. But is
#persisted in the etcd database...cluster store. Change 2 to 3.
kubectl edit deployment hello-world
#Let's clean up our deployment and remove everything
kubectl delete deployment hello-world
kubectl delete service hello-world
kubectl get all