PHP K8s
Github Repo
master
master
  • ๐ŸšขIntroduction
  • ๐ŸŽ‰Support
  • โซUpgrading to 3.x
  • Getting Started
    • ๐Ÿš€Installation
    • ๐Ÿ™ŒShowcase
    • ๐Ÿ”’Authentication
    • โ™ป๏ธActive Development
      • ๐Ÿ“—Default Versions
      • ๐Ÿง™Supported Kubernetes versions
      • ๐Ÿ—ณ๏ธPackage versioning
  • Cluster Interaction
    • ๐ŸงญGetting Started
    • ๐ŸŽญCRUD Operations
    • ๐Ÿ“ฆImport from YAML
    • ๐Ÿ‘€Watching Resources
  • Resources
    • ๐Ÿ‘“Base Resource
      • Attributes Methods
      • Metadata Methods
      • Custom Callers
    • ๐Ÿง‘Namespace
    • ๐Ÿ–ฅ๏ธNode
    • ๐Ÿ“กEvent
    • ๐Ÿ“ฆWorkloads
      • Pod
      • Deployment
      • StatefulSet
      • DaemonSet
      • Job
      • CronJob
    • ๐ŸงตConfigurations
      • ConfigMap
      • Secret
    • ๐Ÿ“€Storage
      • StorageClass
      • PersistentVolume
      • PersistentVolumeClaim
    • ๐Ÿ“ถNetworking
      • Service
      • Ingress
    • โ†”๏ธScaling & Availability
      • HorizontalPodAutoscaler
      • PodDisruptionBudget
    • ๐Ÿ”‘RBAC
      • ClusterRole
      • ClusterRoleBinding
      • Role
      • RoleBinding
      • ServiceAccount
  • Instances
    • Affinity
    • Container
    • Container Probes
    • Expressions
    • Resource Metrics
    • RBAC Rules
    • Volumes
  • Advanced
    • ๐ŸฐMacros
    • โœจCreate classes for CRDs
      • ๐ŸŽ‡Getting started
      • ๐ŸฐMacros
      • ๐Ÿ‘€Watchable Resources
      • โ†”๏ธScalable Resources
      • ๐Ÿ’ŠPodable Resources
      • ๐Ÿ“„Loggable Resources
      • ๐Ÿš’Helper Traits
  • Frameworks
    • Laravel
    • PHP Helm
Powered by GitBook
On this page
  • Bearer Token
  • HTTP authentication header
  • SSL/TLS Support
  • In-Cluster Authentication
  • Authenticating with a kubeconfig file
  • KUBECONFIG environment variable

Was this helpful?

Edit on GitHub
  1. Getting Started

Authentication

For authentication and cluster interaction, a KubernetesCluster class is provided. In the showcase, you have been shown how to initialize a Kubernetes Cluster instance when the method is kubectl proxy-supported.

use RenokiCo\PhpK8s\KubernetesCluster;

$cluster = KubernetesCluster::fromUrl('http://127.0.0.1:8080');

As an argument, you can pass any Kubernetes endpoint towards your cluster:

use RenokiCo\PhpK8s\KubernetesCluster;

$cluster = KubernetesCluster::fromUrl(
    'https://cluster-id.api.k8s.fr-par.scw.cloud:6443'
);

Further to this page, you will find some ways to authenticate to your cluster.

Bearer Token

The simplest way is to attach a bearer token to the request:

$cluster->withToken($token);

You can also attach a token from a file path:

$cluster->loadTokenFromFile($path);

HTTP authentication header

In case you have a username-password HTTP authentication, the underlying code will make it accessible for you:

$cluster->httpAuthentication($user, $password);

SSL/TLS Support

Besides the authentication, you might want to pass SSL data for the API requests:

$cluster->withCertificate($pathToCert)->withPrivateKey($pathToKey);

If you have a CA certificate, you might also want to pass it:

$cluster->withCaCertificate($pathToCA);

For testing purposes or local checkups, you can disable SSL checks. This will disable peer verification:

$cluster->withoutSslChecks();

In-Cluster Authentication

Please keep in mind that this works only within pods that run in a Kubernetes cluster.

$cluster = KubernetesCluster::inClusterConfiguration();

foreach ($cluster->getAllServices() as $svc) {
    //
}

Authenticating with a kubeconfig file

You may call fromKubeConfigYamlFile method to specify the cluster to be authenticated with the given kubeconfig path and use the passed context:

$cluster = KubernetesCluster::fromKubeConfigYamlFile('/.kube/config', 'context-name');

KUBECONFIG environment variable

$cluster = KubernetesCluster::fromKubeConfigVariable('context-name');
PreviousShowcaseNextActive Development

Last updated 3 years ago

Was this helpful?

Kubernetes allows Pods to access . Each pod that runs in a Cluster has a token and a CA certificate injected at a specific location. The package will recognize the files and will apply the token and the CA accordingly.

Instead of passing a single kubeconfig file with fromKubeConfigYamlFile, you may use the KUBECONFIG variable. This variable as holding multiple paths to different kubeconfig files. From all the paths, PHPK8s will merge all kubeconfig files and will use the specified.

๐Ÿ”’
the internal kubeapi within a container
is defined in the specs