After starting Kubernets (configure kubectl automatically):
doctl kubernetes cluster kubeconfig save my-cluster-name
Fix : invalid object doesn’t have additional properties
After installing kubectl with brew you should run:
rm /usr/local/bin/kubectl
brew link --overwrite kubernetes-cli
minikube dashboard
MacBook:~$ minikube dashboard
🔌 Enabling dashboard …
🤔 Verifying dashboard health …
🚀 Launching proxy …
🤔 Verifying proxy health …
🎉 Opening http://127.0.0.1:51077/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser…
Describe POD
kubectl describe pod nodehelloworld.example.com
minikube service
MacBook:~/kubernetes-course$ cat first-app/helloworld-service.yml apiVersion: v1 kind: Service metadata: name: helloworld-service spec: ports: - port: 80 targetPort: nodejs-port protocol: TCP selector: app: helloworld type: LoadBalancer MacBook:~/kubernetes-course$ cat first-app/helloworld-nodeport-service.yml apiVersion: v1 kind: Service metadata: name: helloworld-service spec: ports: - port: 31001 nodePort: 31001 targetPort: nodejs-port protocol: TCP selector: app: helloworld type: NodePort MacBook:~/kubernetes-course$ kubectl create -f first-app/helloworld-nodeport-service.yml service/helloworld-service created MacBook:~/kubernetes-course$ minikube service helloworld-service --url http: //192.168.99.100:31001 MacBook:~/kubernetes-course$ curl http: //192.168.99.100:31001 Hello World! |
Hello World!MacBook:~/kubernetes-course$ kubectl describe svc helloworld-service Name: helloworld-service Namespace: default Labels: <none> Annotations: <none> Selector: app=helloworld Type: NodePort IP: 10.107 . 169.35 Port: <unset> 31001 /TCP TargetPort: nodejs-port/TCP NodePort: <unset> 31001 /TCP Endpoints: 172.17 . 0.5 : 3000 Session Affinity: None External Traffic Policy: Cluster Events: <none> MacBook:~/kubernetes-course$ kubectl get svc helloworld-service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE helloworld-service NodePort 10.107 . 169.35 <none> 31001 : 31001 /TCP 3m14s |
pod-helloworld.yml
apiVersion: v1 kind: Pod metadata: name: nodehelloworld.kubernetes.intelligence.ws labels: app: helloworld spec: containers: - name: docker-demo image: joelgriffiths/docker-demo ports: - containerPort: 3000 |
kubectl create -f pod-hellowworld.yml |
Useful commands
kubectl get pod
kubectl describe pod
kubectl expose pop <pod> –port=444 –name=frontend
kubectl port-forward <pod-name> 8080
kubectl attach <pod-name> -i
kubectl exec <pod-name> – command # First container
kubectl exec <pod-name> -c <container> – command
kubectl label pods <pod-name> mylabel=awesome
#SHELL
kubectl run -i –tty busybox –image=busybox –restart=Never – sh
POD Commands in hello world example
kubectl get pod
kubectl describe pod nodehelloworld.example.com
kubectl port-forward nodehelloworld.example.com 8081:3000
Getting to the POD directly
kubectl expose pod nodehelloworld.example.com –type=NodePort –name nodehelloworld-service
minikube service nodehelloworld-service –url
OR
MacBook:~/kubernetes-course$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17h
nodehelloworld-service NodePort 10.111.245.197 <none> 3000:32129/TCP 4m
(See logs)
kubectl attach nodehelloworld.example.com
(Execute command)
kubectl exec nodehelloworld.example.com – ls /app
(Describe service)
kubectl get service
kubectl describe service nodehelloworld-service
Endpoints: 172.17.0.4:3000
(Start Busybox POD)
kubectl run -i –tty busybox –image=busybox –restart=Never — sh
#/ telnet 127.17.0.4:3000