Goals
- Understand the basics of the deployment and service
- Create our deployment using YAML
- Execute our deployment using YAML
- Verify that the application is working as expected
- Scale the helloworld application
1 Understand the basics of the deployment and service
run kubectl get deploy/hw -o yaml
. This will return the YAML that composes the helloworld service:
localhost:~ xunyang$ kubectl run hw --image=karthequian/helloworld --port=80
deployment.apps "hw" created
localhost:~ xunyang$ kubectl get deployment/hw -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: 2018-04-16T04:41:05Z
generation: 1
labels:
run: hw
name: hw
namespace: default
resourceVersion: "11258"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/hw
uid: 5f8fbd84-4130-11e8-a846-0800272fd392
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
run: hw
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: hw
spec:
containers:
- image: karthequian/helloworld
imagePullPolicy: Always
name: hw
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: 2018-04-16T04:41:05Z
lastUpdateTime: 2018-04-16T04:41:05Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: 2018-04-16T04:41:05Z
lastUpdateTime: 2018-04-16T04:41:10Z
message: ReplicaSet "hw-596b578c58" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
The Kubernetes service also comprises YAML.
run kubectl get service hw -o yaml
localhost:~ xunyang$ kubectl expose deployment hw --type=NodePort
service "hw" exposed
localhost:~ xunyang$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hw NodePort 10.107.135.14 <none> 80:30764/TCP 0s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 19h
localhost:~ xunyang$ kubectl get service hw -o yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2018-04-16T04:44:21Z
labels:
run: hw
name: hw
namespace: default
resourceVersion: "11471"
selfLink: /api/v1/namespaces/default/services/hw
uid: d4c8b9c5-4130-11e8-a846-0800272fd392
spec:
clusterIP: 10.107.135.14
externalTrafficPolicy: Cluster
ports:
- nodePort: 30764
port: 80
protocol: TCP
targetPort: 80
selector:
run: hw
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
2 Create our deployment using YAML
create helloworld-all.yaml
file, content as below
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: helloworld-all-deployment
spec:
selector:
matchLabels:
app: helloworld
replicas: 1 # tells deployment to run 1 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: helloworld
spec:
containers:
- name: helloworld
image: karthequian/helloworld:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: helloworld-all-service
spec:
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: helloworld
3 Execute our deployment using YAML
localhost:~ xunyang$ kubectl create -f helloworld-all.yaml
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-2x756 1/1 Running 0 1s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.98.124.82 <pending> 80:30100/TCP 1s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 1 1 1 1 1s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 1 1 1 1s
localhost:~ xunyang$
4 Verify that the application is working as expected
localhost:~ xunyang$ kubectl create -f helloworld-all.yaml
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-2x756 1/1 Running 0 1s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.98.124.82 <pending> 80:30100/TCP 1s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 1 1 1 1 1s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 1 1 1 1s
localhost:~ xunyang$ minikube service helloworld-all-service
Opening kubernetes service default/helloworld-all-service in default browser...
5 Scale the helloworld application
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-sl9tx 0/1 ContainerCreating 0 0s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.110.116.85 <pending> 80:30265/TCP 0s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 1 1 1 0 0s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 1 1 0 0s
localhost:~ xunyang$ kubectl scale --replicas=3 deploy/helloworld-all-deployment
deployment.extensions "helloworld-all-deployment" scaled
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv 0/1 ContainerCreating 0 0s
helloworld-all-deployment-7c46b4c7dc-sl9tx 1/1 Running 0 15s
helloworld-all-deployment-7c46b4c7dc-vd4h7 0/1 ContainerCreating 0 0s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.110.116.85 <pending> 80:30265/TCP 15s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 3 3 3 1 15s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 3 3 1 15s
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv 0/1 ContainerCreating 0 3s
helloworld-all-deployment-7c46b4c7dc-sl9tx 1/1 Running 0 20s
helloworld-all-deployment-7c46b4c7dc-vd4h7 1/1 Running 0 3s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.110.116.85 <pending> 80:30265/TCP 20s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 3 3 3 2 20s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 3 3 2 20s
localhost:~ xunyang$ kubectl get all
NAME READY STATUS RESTARTS AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv 1/1 Running 0 8s
helloworld-all-deployment-7c46b4c7dc-sl9tx 1/1 Running 0 25s
helloworld-all-deployment-7c46b4c7dc-vd4h7 1/1 Running 0 8s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld-all-service LoadBalancer 10.110.116.85 <pending> 80:30265/TCP 25s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
helloworld-all-deployment 3 3 3 3 25s
NAME DESIRED CURRENT READY AGE
helloworld-all-deployment-7c46b4c7dc 3 3 3 25s
6 clear data
localhost:~ xunyang$ kubectl delete deployment --all
deployment.extensions "helloworld-all-deployment" deleted
localhost:~ xunyang$ kubectl delete services --all
service "helloworld-all-service" deleted
service "kubernetes" deleted
localhost:~ xunyang$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 0s