K8S Field TechNotes
K8S Field TechNotes
1. POD’s
sh-3.2# vi pod-practice-1.yml
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
spec:
containers:
- name: hello-ctr
image: nigelpoulton/pluralsight-docker-ci:latest
ports:
- containerPort: 8080
NOTE - Will not usually work with PODS like this - because it is imperative
NOTE - We will use Replication Controllers/ Services as they are higher level and
DECLARATIVE.
sh-3.2# pwd
/Users/t/gitHub/kubernetes-work/Pods
sh-3.2# ls
pod-practice-1.yml pods-rcs-services-practice-log.log
sh-3.2# cd ../Replication-Controller/
sh-3.2# kubectl delete pod hello-pod
pod "hello-pod" deleted
NOTE: Spacing matters for YAML files - Use 2 Spaces (Not tabs) (Characters) for each new
level.
Updating RC’s
sh-3.2# vi rc.yml
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 20
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/pluralsight-docker-ci:latest
ports:
- containerPort: 8080
SECTION - SERVICES
sh-3.2# kubectl get nodes
NAME STATUS AGE VERSION
minikube Ready 19h v1.7.5
Name: minikube
Role:
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=minikube
Annotations: alpha.kubernetes.io/provided-node-ip=192.168.64.3
node.alpha.kubernetes.io/ttl=0
volumes.kubernetes.io/controller-managed-attach-detach=true
Taints: <none>
CreationTimestamp: Mon, 11 Sep 2017 15:14:13 -0400
Conditions:
Type Status LastHeartbeatTime LastTransitionTime
Reason Message
---- ------ ----------------- ------------------
------ -------
OutOfDisk False Tue, 12 Sep 2017 11:08:40 -0400 Mon, 11 Sep 2017 15:14:13 -0400
KubeletHasSufficientDisk kubelet has sufficient disk space available
MemoryPressure False Tue, 12 Sep 2017 11:08:40 -0400 Mon, 11 Sep 2017 15:14:13 -0400
KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Tue, 12 Sep 2017 11:08:40 -0400 Mon, 11 Sep 2017 15:14:13 -0400
KubeletHasNoDiskPressure kubelet has no disk pressure
Ready True Tue, 12 Sep 2017 11:08:40 -0400 Mon, 11 Sep 2017 15:14:24 -0400
KubeletReady kubelet is posting ready status
Addresses:
InternalIP: 192.168.64.3
Hostname: minikube
Capacity:
cpu: 2
memory: 2048148Ki
pods: 110
Allocatable:
cpu: 2
memory: 1945748Ki
pods: 110
System Info:
Machine ID: b84ddb9d9157491c9c1bcc5a1a37b08e
System UUID: 882741A6-0000-0000-BB88-2847BA1880E6
Boot ID: 9eef9b9e-b4d9-4dbb-8270-ef80b7af470f
Kernel Version: 4.9.13
OS Image: Buildroot 2017.02
Operating System: linux
Architecture: amd64
Container Runtime Version: docker://1.12.6
Kubelet Version: v1.7.5
Kube-Proxy Version: v1.7.5
ExternalID: minikube
Non-terminated Pods: (23 in total)
Namespace Name CPU Requests CPU
Limits Memory Requests Memory Limits
--------- ---- ---------------------- ---------------
-------------
default hello-rc-00mtq 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-0385w 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-054gn 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-1gl91 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-1v3cr 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-20rm3 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-709wb 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-910qv 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-fh0ps 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-gg3sx 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-h0ghv 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-h8t8g 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-jxwsr 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-kbf08 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-q16mk 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-s4bkf 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-vlrc3 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-xs968 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-zlh77 0 (0%) 0 (0%)
0 (0%) 0 (0%)
default hello-rc-zrzc5 0 (0%) 0 (0%)
0 (0%) 0 (0%)
kube-system kube-addon-manager-minikube 5m (0%) 0 (0%)
50Mi (2%) 0 (0%)
kube-system kube-dns-910330662-jtzhx 260m (13%) 0 (0%)
110Mi (5%) 170Mi (8%)
kube-system kubernetes-dashboard-580rd 0 (0%) 0 (0%)
0 (0%) 0 (0%)
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
CPU Requests CPU Limits Memory Requests Memory Limits
------------ ---------- --------------- -------------
265m (13%) 0 (0%) 160Mi (8%) 170Mi (8%)
Events:
FirstSeen LastSeen Count From SubObjectPath Type
Reason Message
--------- -------- ----- ---- ------------- -------- ------
-------
30m 30m 1 kubelet, minikube Normal Starting
Starting kubelet.
30m 30m 1 kubelet, minikube Normal
NodeAllocatableEnforced Updated Node Allocatable limit across pods
30m 30m 1 kubelet, minikube Normal
NodeHasSufficientDisk Node minikube status is now: NodeHasSufficientDisk
30m 30m 1 kubelet, minikube Normal
NodeHasSufficientMemory Node minikube status is now: NodeHasSufficientMemory
30m 30m 1 kubelet, minikube Normal
NodeHasNoDiskPressure Node minikube status is now: NodeHasNoDiskPressure
30m 30m 1 kubelet, minikube Warning
Rebooted Node minikube has been rebooted, boot id:
9eef9b9e-b4d9-4dbb-8270-ef80b7af470f
30m 30m 1 kube-proxy, minikube Normal
Starting Starting kube-proxy.
NOTE: Using IP Address of Master (Its a Single Node cluster (Node and Master) are combined
192.168.64.3:32685. IT works from Chrome
NOTE: Service Ports will by default be between 32,000 and 32,767.
sh-3.2# vi Services/service.yml
apiVersion: v1
kind: Service
metadata:
name: hello-svc
labels:
app: hello-world
spec:
type: NodePort
ports:
- port: 8080
protocol: TCP
selector:
app: hello-world
NOTE::
1. ClusterIP - (Default) Gets a stable IP within the CLUSTER ONLY.
2. NodePort - Exposes app externally by adding a Service Port for the Service. Assigned
random port above 30000 then Service Port for access
3. LocalBalancer - Intergrates NodePort with CloudBased Load Balancers
sh-3.2# vi Services/service-2.yml
apiVersion: v1
kind: Service
metadata:
name: hello-svc
labels:
app: hello-world
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
protocol: TCP
selector:
app: hello-world
NOTE: You can also specify the nodePort (or it can be assigned dynamically).
NOTE: this will be used when deploying the Service for the selector: app: hello-world selector
label to match to.
Name: hello-svc
Namespace: default
Labels: app=hello-world
Annotations: <none>
Selector: app=hello-world
Type: NodePort
IP: 10.0.0.125
Port: <unset> 8080/TCP
NodePort: <unset> 30001/TCP
Endpoints: 172.17.0.10:8080,172.17.0.11:8080,172.17.0.12:8080 + 17 more...
Session Affinity: None
Events: <none>
Name: hello-rc-00mtq
Namespace: default
Node: minikube/192.168.64.3
Start Time: Tue, 12 Sep 2017 11:00:33 -0400
Labels: app=hello-world
Annotations:
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationCon
troller","namespace":"default","name":"hello-rc","uid":"202034a9-97cb-11e7-9456-3a18bf0e81eb...
Status: Running
IP: 172.17.0.5
Created By: ReplicationController/hello-rc
Controlled By: ReplicationController/hello-rc
Containers:
hello-pod:
Container ID: docker://1261b69d38948543f258dddc14ce0b64c7afbe888b3eef5311e74afadcc74b7e
Image: nigelpoulton/pluralsight-docker-ci:latest
Image ID:
docker-pullable://nigelpoulton/pluralsight-docker-ci@sha256:7a6b0125fe7893e70dc63b2c42ad779e5866c6
d2779ceb9b12a28e2c38bd8d3d
Port: 8080/TCP
State: Running
Started: Tue, 12 Sep 2017 11:00:35 -0400
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gdkd3 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-gdkd3:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gdkd3
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events: <none>
Name: hello-rc-0385w
Namespace: default
Node: minikube/192.168.64.3
Start Time: Tue, 12 Sep 2017 11:05:13 -0400
Labels: app=hello-world
Annotations:
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationCon
troller","namespace":"default","name":"hello-rc","uid":"202034a9-97cb-11e7-9456-3a18bf0e81eb...
Status: Running
IP: 172.17.0.16
Created By: ReplicationController/hello-rc
Controlled By: ReplicationController/hello-rc
Containers:
hello-pod:
Container ID: docker://d2031b7637f1d3783cb93f86f9c0f2475b81837f736daf536813ca686474a146
Image: nigelpoulton/pluralsight-docker-ci:latest
Image ID:
docker-pullable://nigelpoulton/pluralsight-docker-ci@sha256:7a6b0125fe7893e70dc63b2c42ad779e5866c6
d2779ceb9b12a28e2c38bd8d3d
Port: 8080/TCP
State: Running
Started: Tue, 12 Sep 2017 11:05:16 -0400
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gdkd3 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-gdkd3:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gdkd3
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events: <none>
Name: hello-rc-054gn
Namespace: default
Node: minikube/192.168.64.3
Start Time: Tue, 12 Sep 2017 11:05:13 -0400
Labels: app=hello-world
Annotations:
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationCon
troller","namespace":"default","name":"hello-rc","uid":"202034a9-97cb-11e7-9456-3a18bf0e81eb...
Status: Running
IP: 172.17.0.14
Created By: ReplicationController/hello-rc
Controlled By: ReplicationController/hello-rc
Containers:
hello-pod:
Container ID: docker://13d256552b516f627d1eba86a38e9d0662bcbb820602db36a851fb0851cc9018
Image: nigelpoulton/pluralsight-docker-ci:latest
Image ID:
docker-pullable://nigelpoulton/pluralsight-docker-ci@sha256:7a6b0125fe7893e70dc63b2c42ad779e5866c6
d2779ceb9b12a28e2c38bd8d3d
Port: 8080/TCP
State: Running
Started: Tue, 12 Sep 2017 11:05:15 -0400
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gdkd3 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-gdkd3:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gdkd3
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events: <none>
Name: hello-rc-1gl91
Namespace: default
Node: minikube/192.168.64.3
Start Time: Tue, 12 Sep 2017 11:00:33 -0400
Labels: app=hello-world
Annotations:
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationCon
troller","namespace":"default","name":"hello-rc","uid":"202034a9-97cb-11e7-9456-3a18bf0e81eb...
Status: Running
IP: 172.17.0.4
Created By: ReplicationController/hello-rc
Controlled By: ReplicationController/hello-rc
Containers:
hello-pod:
Container ID: docker://a7317682c1fcf655c89b71d4e333030adb5103ee4794955ec74b271ddc7d8c2b
Image: nigelpoulton/pluralsight-docker-ci:latest
Image ID:
Name: hello-rc-20rm3
Namespace: default
Node: minikube/192.168.64.3
Start Time: Tue, 12 Sep 2017 11:00:33 -0400
Labels: app=hello-world
Annotations:
kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationCon
troller","namespace":"default","name":"hello-rc","uid":"202034a9-97cb-11e7-9456-3a18bf0e81eb...
Status: Running
IP: 172.17.0.13
Created By: ReplicationController/hello-rc
Controlled By: ReplicationController/hello-rc
Containers:
hello-pod:
Container ID: docker://b17575ea7aaf176691885b4f4ec87416d0b6b493948d690fd36c6b68b2ae1a1c
Image: nigelpoulton/pluralsight-docker-ci:latest
Image ID:
docker-pullable://nigelpoulton/pluralsight-docker-ci@sha256:7a6b0125fe7893e70dc63b2c42ad779e5866c6
d2779ceb9b12a28e2c38bd8d3d
Port: 8080/TCP
State: Running
Started: Tue, 12 Sep 2017 11:00:39 -0400
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gdkd3 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-gdkd3:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gdkd3
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events: <none>
Name: kube-dns
Namespace: kube-system
Labels: addonmanager.kubernetes.io/mode=Reconcile
k8s-app=kube-dns
kubernetes.io/name=KubeDNS
Annotations:
kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"
annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","k8s-app":"kube-dns",
"kubernet...
Selector: k8s-app=kube-dns
Type: ClusterIP
IP: 10.0.0.10
Port: dns 53/UDP
Endpoints: 172.17.0.2:53Name: hello-svc
Namespace: default
Labels: app=hello-world
Annotations: <none>
Selector: app=hello-world
Type: NodePort
IP: 10.0.0.125
Port: <unset> 8080/TCP
NodePort: <unset> 30001/TCP
Endpoints: 172.17.0.10:8080,172.17.0.11:8080,172.17.0.12:8080 + 17 more...
Session Affinity: None
Events: <none>
Name: kubernetes
Namespace: default
Labels: component=apiserver
provider=kubernetes
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP: 10.0.0.1
NOTE: I hit 192;.168.64.3:30001 in browser and it worked great. Took some time
sh: Took: command not found
Deployments
bash-3.2$ pwd
/Users/user/gitHub/kubernetes-work
Name: hello-deploy
Namespace: default
CreationTimestamp: Wed, 13 Sep 2017 11:58:37 -0400
Labels: app=hello-world
Annotations: deployment.kubernetes.io/revision=1
Selector: app=hello-world
Replicas: 11 desired | 11 updated | 11 total | 11 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=hello-world
Containers:
hello-pod:
Image: nigelpoulton/pluralsight-docker-ci:latest
Port: 8080/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: hello-deploy-2512326018 (11/11 replicas created)
Events:
FirstSeen LastSeen Count From SubObjectPath Type
Reason Message
--------- -------- ----- ---- ------------- -------- ------
-------
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2512326018 to 10
18s 18s 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2512326018 to 11
bash-3.2$ pwd
/Users/user/gitHub/kubernetes-work/Deployments
bash-3.2$ ls
deployment.yml
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/pluralsight-docker-ci:edge
ports:
- containerPort: 8080
NOTE: --record=true used for audit history seen with kubectl rollout history
kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"extensions/v1beta1","kind":"Deplo
yment","metadata":{"annotations":{"kubernetes.io/change-cause":"kubectl apply
--filename=deployment-2.y...
kubernetes.io/change-cause=kubectl apply --filename=deployment-2.yml
--record=true
Selector: app=hello-world
Replicas: 10 desired | 10 updated | 10 total | 10 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 10
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=hello-world
Containers:
hello-pod:
Image: nigelpoulton/pluralsight-docker-ci:edge
Port: 8080/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets:<none>
NewReplicaSet:hello-deploy-2108007848 (10/10 replicas created)
Events:
FirstSeen LastSeen Count From SubObjectPath Type
Reason Message
----------------- ----- ---- ------------- -------- ------
-------
25m 25m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2512326018 to 10
23m 23m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2512326018 to 11
3m 3m 1 deployment-controller Normal
ScalingReplicaSet Scaled down replica set hello-deploy-2512326018 to 10
3m 3m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2108007848 to 1
3m 3m 1 deployment-controller Normal
ScalingReplicaSet Scaled down replica set hello-deploy-2512326018 to 9
3m 3m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2108007848 to 2
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled down replica set hello-deploy-2512326018 to 7
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2108007848 to 4
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled down replica set hello-deploy-2512326018 to 5
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled up replica set hello-deploy-2108007848 to 6
2m 2m 1 deployment-controller Normal
ScalingReplicaSet Scaled down replica set hello-deploy-2512326018 to 3
2m 2m 4 deployment-controller Normal
ScalingReplicaSet (combined from similar events): Scaled down replica set
hello-deploy-2512326018 to 0
Waiting for rollout to finish: 2 out of 10 new replicas have been updated...
Waiting for rollout to finish: 2 out of 10 new replicas have been updated...
Waiting for rollout to finish: 2 out of 10 new replicas have been updated...
...
Waiting for rollout to finish: 8 out of 10 new replicas have been updated...
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 1 old replicas are pending termination...
deployment "hello-deploy" successfully rolled out
bash-3.2$ exit